LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Hit Total Coverage
Test: PostgreSQL 18devel Lines: 6770 7480 90.5 %
Date: 2025-04-01 14:15:22 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 opt_virtual_or_stored
     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 VIRTUAL 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      749922 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     919             :                 (void) yynerrs;     /* suppress compiler warning */
     920             :             }
     921             :             | MODE_TYPE_NAME Typename
     922             :             {
     923        9632 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     924             :             }
     925             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     926             :             {
     927       33252 :                 pg_yyget_extra(yyscanner)->parsetree =
     928       33252 :                     list_make1(makeRawStmt($2, @2));
     929             :             }
     930             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     931             :             {
     932        6330 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     933             : 
     934        6330 :                 n->nnames = 1;
     935        6330 :                 pg_yyget_extra(yyscanner)->parsetree =
     936        6330 :                     list_make1(makeRawStmt((Node *) n, @2));
     937             :             }
     938             :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     939             :             {
     940         674 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     941             : 
     942         674 :                 n->nnames = 2;
     943         674 :                 pg_yyget_extra(yyscanner)->parsetree =
     944         674 :                     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      600016 :                     if ($1 != NIL)
     965             :                     {
     966             :                         /* update length of previous stmt */
     967      599920 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     968             :                     }
     969      600016 :                     if ($3 != NULL)
     970       52838 :                         $$ = lappend($1, makeRawStmt($3, @3));
     971             :                     else
     972      547178 :                         $$ = $1;
     973             :                 }
     974             :             | toplevel_stmt
     975             :                 {
     976      749930 :                     if ($1 != NULL)
     977      749168 :                         $$ = list_make1(makeRawStmt($1, @1));
     978             :                     else
     979         762 :                         $$ = 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      547958 :                 { $$ = NULL; }
    1119             :         ;
    1120             : 
    1121             : /*
    1122             :  * Generic supporting productions for DDL
    1123             :  */
    1124             : opt_single_name:
    1125        5368 :             ColId                           { $$ = $1; }
    1126        1510 :             | /* EMPTY */                   { $$ = NULL; }
    1127             :         ;
    1128             : 
    1129             : opt_qualified_name:
    1130        1798 :             any_name                        { $$ = $1; }
    1131       15078 :             | /*EMPTY*/                     { $$ = NIL; }
    1132             :         ;
    1133             : 
    1134             : opt_concurrently:
    1135        1094 :             CONCURRENTLY                    { $$ = true; }
    1136        7504 :             | /*EMPTY*/                     { $$ = false; }
    1137             :         ;
    1138             : 
    1139             : opt_drop_behavior:
    1140        1958 :             CASCADE                         { $$ = DROP_CASCADE; }
    1141         170 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1142       37252 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1143             :         ;
    1144             : 
    1145             : /*****************************************************************************
    1146             :  *
    1147             :  * CALL statement
    1148             :  *
    1149             :  *****************************************************************************/
    1150             : 
    1151             : CallStmt:   CALL func_application
    1152             :                 {
    1153         614 :                     CallStmt   *n = makeNode(CallStmt);
    1154             : 
    1155         614 :                     n->funccall = castNode(FuncCall, $2);
    1156         614 :                     $$ = (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        1334 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1170             : 
    1171        1334 :                     n->stmt_type = ROLESTMT_ROLE;
    1172        1334 :                     n->role = $3;
    1173        1334 :                     n->options = $5;
    1174        1334 :                     $$ = (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        1188 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1191        1814 :             | /* EMPTY */                           { $$ = NIL; }
    1192             :         ;
    1193             : 
    1194             : AlterOptRoleList:
    1195         658 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1196         418 :             | /* EMPTY */                           { $$ = NIL; }
    1197             :         ;
    1198             : 
    1199             : AlterOptRoleElem:
    1200             :             PASSWORD Sconst
    1201             :                 {
    1202         188 :                     $$ = makeDefElem("password",
    1203         188 :                                      (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          96 :                     $$ = 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        1352 :                     if (strcmp($1, "superuser") == 0)
    1252         192 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1253        1160 :                     else if (strcmp($1, "nosuperuser") == 0)
    1254         100 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1255        1060 :                     else if (strcmp($1, "createrole") == 0)
    1256         102 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1257         958 :                     else if (strcmp($1, "nocreaterole") == 0)
    1258          38 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1259         920 :                     else if (strcmp($1, "replication") == 0)
    1260         130 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1261         790 :                     else if (strcmp($1, "noreplication") == 0)
    1262          96 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1263         694 :                     else if (strcmp($1, "createdb") == 0)
    1264          92 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1265         602 :                     else if (strcmp($1, "nocreatedb") == 0)
    1266          46 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1267         556 :                     else if (strcmp($1, "login") == 0)
    1268         284 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1269         272 :                     else if (strcmp($1, "nologin") == 0)
    1270          86 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1271         186 :                     else if (strcmp($1, "bypassrls") == 0)
    1272          82 :                         $$ = 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        1038 :             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          22 :                     $$ = 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         456 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1327             : 
    1328         456 :                     n->stmt_type = ROLESTMT_USER;
    1329         456 :                     n->role = $3;
    1330         456 :                     n->options = $5;
    1331         456 :                     $$ = (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         326 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1346             : 
    1347         326 :                     n->role = $3;
    1348         326 :                     n->action = +1;  /* add, if there are members */
    1349         326 :                     n->options = $5;
    1350         326 :                     $$ = (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        1092 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1421             : 
    1422        1092 :                     n->missing_ok = false;
    1423        1092 :                     n->roles = $3;
    1424        1092 :                     $$ = (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         406 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1437             : 
    1438         406 :                     n->missing_ok = false;
    1439         406 :                     n->roles = $3;
    1440         406 :                     $$ = (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         198 :             | 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         832 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1533             : 
    1534             :                     /* ...but not both */
    1535         832 :                     n->schemaname = $3;
    1536         832 :                     n->authrole = NULL;
    1537         832 :                     n->schemaElts = $4;
    1538         832 :                     n->if_not_exists = false;
    1539         832 :                     $$ = (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        1042 :                 { $$ = 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       20872 :                     VariableSetStmt *n = $2;
    1611             : 
    1612       20872 :                     n->is_local = false;
    1613       20872 :                     $$ = (Node *) n;
    1614             :                 }
    1615             :             | SET LOCAL set_rest
    1616             :                 {
    1617        1214 :                     VariableSetStmt *n = $3;
    1618             : 
    1619        1214 :                     n->is_local = true;
    1620        1214 :                     $$ = (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         566 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1635             : 
    1636         566 :                     n->kind = VAR_SET_MULTI;
    1637         566 :                     n->name = "TRANSACTION";
    1638         566 :                     n->args = $2;
    1639         566 :                     n->jumble_args = true;
    1640         566 :                     n->location = -1;
    1641         566 :                     $$ = 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        4884 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1661             : 
    1662        4884 :                     n->kind = VAR_SET_VALUE;
    1663        4884 :                     n->name = $1;
    1664        4884 :                     n->args = $3;
    1665        4884 :                     n->location = @3;
    1666        4884 :                     $$ = n;
    1667             :                 }
    1668             :             | var_name '=' var_list
    1669             :                 {
    1670       14338 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1671             : 
    1672       14338 :                     n->kind = VAR_SET_VALUE;
    1673       14338 :                     n->name = $1;
    1674       14338 :                     n->args = $3;
    1675       14338 :                     n->location = @3;
    1676       14338 :                     $$ = 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       19252 :             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         942 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1758             : 
    1759         942 :                     n->kind = VAR_SET_VALUE;
    1760         942 :                     n->name = "role";
    1761         942 :                     n->args = list_make1(makeStringConst($2, @2));
    1762         942 :                     n->location = @2;
    1763         942 :                     $$ = n;
    1764             :                 }
    1765             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1766             :                 {
    1767        2550 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1768             : 
    1769        2550 :                     n->kind = VAR_SET_VALUE;
    1770        2550 :                     n->name = "session_authorization";
    1771        2550 :                     n->args = list_make1(makeStringConst($3, @3));
    1772        2550 :                     n->location = @3;
    1773        2550 :                     $$ = 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       23902 : var_name:   ColId                               { $$ = $1; }
    1809             :             | var_name '.' ColId
    1810         466 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1811             :         ;
    1812             : 
    1813       19222 : var_list:   var_value                               { $$ = list_make1($1); }
    1814         170 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1815             :         ;
    1816             : 
    1817             : var_value:  opt_boolean_or_string
    1818       14338 :                 { $$ = makeStringConst($1, @1); }
    1819             :             | NumericOnly
    1820        5054 :                 { $$ = makeAConst($1, @1); }
    1821             :         ;
    1822             : 
    1823           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1824         908 :             | READ COMMITTED                        { $$ = "read committed"; }
    1825        2552 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1826        3196 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1827             :         ;
    1828             : 
    1829             : opt_boolean_or_string:
    1830         650 :             TRUE_P                                  { $$ = "true"; }
    1831        1414 :             | FALSE_P                               { $$ = "false"; }
    1832        2186 :             | 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       29238 :             | 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       50456 :             NonReservedWord                         { $$ = $1; }
    1896        5394 :             | Sconst                                { $$ = $1; }
    1897             :         ;
    1898             : 
    1899             : VariableResetStmt:
    1900        4420 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1901             :         ;
    1902             : 
    1903             : reset_rest:
    1904        3640 :             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        3676 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1938             : 
    1939        3676 :                     n->kind = VAR_RESET;
    1940        3676 :                     n->name = $1;
    1941        3676 :                     n->location = -1;
    1942        3676 :                     $$ = 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        1200 :             SET set_rest                    { $$ = $2; }
    1957          44 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1958             :         ;
    1959             : 
    1960             : /* SetResetClause allows SET or RESET without LOCAL */
    1961             : FunctionSetResetClause:
    1962         134 :             SET set_rest_more               { $$ = $2; }
    1963          12 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1964             :         ;
    1965             : 
    1966             : 
    1967             : VariableShowStmt:
    1968             :             SHOW var_name
    1969             :                 {
    1970         854 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1971             : 
    1972         854 :                     n->name = $2;
    1973         854 :                     $$ = (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         214 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2035             : 
    2036         214 :                     $$ = (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       24430 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2099             : 
    2100       24430 :                     n->relation = $3;
    2101       24430 :                     n->cmds = $4;
    2102       24430 :                     n->objtype = OBJECT_TABLE;
    2103       24430 :                     n->missing_ok = false;
    2104       24430 :                     $$ = (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        2944 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2119             : 
    2120        2944 :                     n->relation = $3;
    2121        2944 :                     n->cmds = list_make1($4);
    2122        2944 :                     n->objtype = OBJECT_TABLE;
    2123        2944 :                     n->missing_ok = false;
    2124        2944 :                     $$ = (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         228 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2163             : 
    2164         228 :                     n->relation = $3;
    2165         228 :                     n->cmds = $4;
    2166         228 :                     n->objtype = OBJECT_INDEX;
    2167         228 :                     n->missing_ok = false;
    2168         228 :                     $$ = (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          94 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2217             : 
    2218          94 :                     n->relation = $3;
    2219          94 :                     n->cmds = $4;
    2220          94 :                     n->objtype = OBJECT_SEQUENCE;
    2221          94 :                     n->missing_ok = false;
    2222          94 :                     $$ = (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         252 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2237             : 
    2238         252 :                     n->relation = $3;
    2239         252 :                     n->cmds = $4;
    2240         252 :                     n->objtype = OBJECT_VIEW;
    2241         252 :                     n->missing_ok = false;
    2242         252 :                     $$ = (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       25588 :             alter_table_cmd                         { $$ = list_make1($1); }
    2322        1008 :             | 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        2342 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2330        2342 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2331             : 
    2332        2342 :                     n->subtype = AT_AttachPartition;
    2333        2342 :                     cmd->name = $3;
    2334        2342 :                     cmd->bound = $4;
    2335        2342 :                     cmd->concurrent = false;
    2336        2342 :                     n->def = (Node *) cmd;
    2337             : 
    2338        2342 :                     $$ = (Node *) n;
    2339             :                 }
    2340             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2341             :             | DETACH PARTITION qualified_name opt_concurrently
    2342             :                 {
    2343         582 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2344         582 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2345             : 
    2346         582 :                     n->subtype = AT_DetachPartition;
    2347         582 :                     cmd->name = $3;
    2348         582 :                     cmd->bound = NULL;
    2349         582 :                     cmd->concurrent = $4;
    2350         582 :                     n->def = (Node *) cmd;
    2351             : 
    2352         582 :                     $$ = (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         192 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2390             : 
    2391         192 :                     n->subtype = AT_AddColumn;
    2392         192 :                     n->def = $2;
    2393         192 :                     n->missing_ok = false;
    2394         192 :                     $$ = (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        1878 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2410             : 
    2411        1878 :                     n->subtype = AT_AddColumn;
    2412        1878 :                     n->def = $3;
    2413        1878 :                     n->missing_ok = false;
    2414        1878 :                     $$ = (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         550 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2430             : 
    2431         550 :                     n->subtype = AT_ColumnDefault;
    2432         550 :                     n->name = $3;
    2433         550 :                     n->def = $4;
    2434         550 :                     $$ = (Node *) n;
    2435             :                 }
    2436             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2437             :             | ALTER opt_column ColId DROP NOT NULL_P
    2438             :                 {
    2439         288 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2440             : 
    2441         288 :                     n->subtype = AT_DropNotNull;
    2442         288 :                     n->name = $3;
    2443         288 :                     $$ = (Node *) n;
    2444             :                 }
    2445             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2446             :             | ALTER opt_column ColId SET NOT NULL_P
    2447             :                 {
    2448         410 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2449             : 
    2450         410 :                     n->subtype = AT_SetNotNull;
    2451         410 :                     n->name = $3;
    2452         410 :                     $$ = (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         132 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2458             : 
    2459         132 :                     n->subtype = AT_SetExpression;
    2460         132 :                     n->name = $3;
    2461         132 :                     n->def = $8;
    2462         132 :                     $$ = (Node *) n;
    2463             :                 }
    2464             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2465             :             | ALTER opt_column ColId DROP EXPRESSION
    2466             :                 {
    2467          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2468             : 
    2469          62 :                     n->subtype = AT_DropExpression;
    2470          62 :                     n->name = $3;
    2471          62 :                     $$ = (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          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2477             : 
    2478          12 :                     n->subtype = AT_DropExpression;
    2479          12 :                     n->name = $3;
    2480          12 :                     n->missing_ok = true;
    2481          12 :                     $$ = (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         218 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2533             : 
    2534         218 :                     n->subtype = AT_SetStorage;
    2535         218 :                     n->name = $3;
    2536         218 :                     n->def = (Node *) makeString($5);
    2537         218 :                     $$ = (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        1574 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2611             : 
    2612        1574 :                     n->subtype = AT_DropColumn;
    2613        1574 :                     n->name = $3;
    2614        1574 :                     n->behavior = $4;
    2615        1574 :                     n->missing_ok = false;
    2616        1574 :                     $$ = (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         982 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2625         982 :                     ColumnDef *def = makeNode(ColumnDef);
    2626             : 
    2627         982 :                     n->subtype = AT_AlterColumnType;
    2628         982 :                     n->name = $3;
    2629         982 :                     n->def = (Node *) def;
    2630             :                     /* We only use these fields of the ColumnDef node */
    2631         982 :                     def->typeName = $6;
    2632         982 :                     def->collClause = (CollateClause *) $7;
    2633         982 :                     def->raw_default = $8;
    2634         982 :                     def->location = @3;
    2635         982 :                     $$ = (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       13182 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2651             : 
    2652       13182 :                     n->subtype = AT_AddConstraint;
    2653       13182 :                     n->def = $2;
    2654       13182 :                     $$ = (Node *) n;
    2655             :                 }
    2656             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2657             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2658             :                 {
    2659         150 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2660         150 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2661             : 
    2662         150 :                     n->subtype = AT_AlterConstraint;
    2663         150 :                     n->def = (Node *) c;
    2664         150 :                     c->conname = $3;
    2665         150 :                     if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
    2666             :                               CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
    2667         108 :                         c->alterDeferrability = true;
    2668         150 :                     if ($4 & CAS_NO_INHERIT)
    2669          24 :                         c->alterInheritability = true;
    2670         150 :                     processCASbits($4, @4, "FOREIGN KEY",
    2671             :                                     &c->deferrable,
    2672             :                                     &c->initdeferred,
    2673             :                                     NULL, NULL, &c->noinherit, yyscanner);
    2674         132 :                     $$ = (Node *) n;
    2675             :                 }
    2676             :             /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
    2677             :             | ALTER CONSTRAINT name INHERIT
    2678             :                 {
    2679          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2680          60 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2681             : 
    2682          60 :                     n->subtype = AT_AlterConstraint;
    2683          60 :                     n->def = (Node *) c;
    2684          60 :                     c->conname = $3;
    2685          60 :                     c->alterInheritability = true;
    2686          60 :                     c->noinherit = false;
    2687             : 
    2688          60 :                     $$ = (Node *) n;
    2689             :                 }
    2690             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2691             :             | VALIDATE CONSTRAINT name
    2692             :                 {
    2693         412 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2694             : 
    2695         412 :                     n->subtype = AT_ValidateConstraint;
    2696         412 :                     n->name = $3;
    2697         412 :                     $$ = (Node *) n;
    2698             :                 }
    2699             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2700             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2701             :                 {
    2702          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2703             : 
    2704          18 :                     n->subtype = AT_DropConstraint;
    2705          18 :                     n->name = $5;
    2706          18 :                     n->behavior = $6;
    2707          18 :                     n->missing_ok = true;
    2708          18 :                     $$ = (Node *) n;
    2709             :                 }
    2710             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2711             :             | DROP CONSTRAINT name opt_drop_behavior
    2712             :                 {
    2713         780 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2714             : 
    2715         780 :                     n->subtype = AT_DropConstraint;
    2716         780 :                     n->name = $3;
    2717         780 :                     n->behavior = $4;
    2718         780 :                     n->missing_ok = false;
    2719         780 :                     $$ = (Node *) n;
    2720             :                 }
    2721             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2722             :             | SET WITHOUT OIDS
    2723             :                 {
    2724           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2725             : 
    2726           6 :                     n->subtype = AT_DropOids;
    2727           6 :                     $$ = (Node *) n;
    2728             :                 }
    2729             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2730             :             | CLUSTER ON name
    2731             :                 {
    2732          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2733             : 
    2734          46 :                     n->subtype = AT_ClusterOn;
    2735          46 :                     n->name = $3;
    2736          46 :                     $$ = (Node *) n;
    2737             :                 }
    2738             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2739             :             | SET WITHOUT CLUSTER
    2740             :                 {
    2741          18 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2742             : 
    2743          18 :                     n->subtype = AT_DropCluster;
    2744          18 :                     n->name = NULL;
    2745          18 :                     $$ = (Node *) n;
    2746             :                 }
    2747             :             /* ALTER TABLE <name> SET LOGGED */
    2748             :             | SET LOGGED
    2749             :                 {
    2750          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2751             : 
    2752          50 :                     n->subtype = AT_SetLogged;
    2753          50 :                     $$ = (Node *) n;
    2754             :                 }
    2755             :             /* ALTER TABLE <name> SET UNLOGGED */
    2756             :             | SET UNLOGGED
    2757             :                 {
    2758          62 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2759             : 
    2760          62 :                     n->subtype = AT_SetUnLogged;
    2761          62 :                     $$ = (Node *) n;
    2762             :                 }
    2763             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2764             :             | ENABLE_P TRIGGER name
    2765             :                 {
    2766         122 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2767             : 
    2768         122 :                     n->subtype = AT_EnableTrig;
    2769         122 :                     n->name = $3;
    2770         122 :                     $$ = (Node *) n;
    2771             :                 }
    2772             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2773             :             | ENABLE_P ALWAYS TRIGGER name
    2774             :                 {
    2775          40 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2776             : 
    2777          40 :                     n->subtype = AT_EnableAlwaysTrig;
    2778          40 :                     n->name = $4;
    2779          40 :                     $$ = (Node *) n;
    2780             :                 }
    2781             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2782             :             | ENABLE_P REPLICA TRIGGER name
    2783             :                 {
    2784          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2785             : 
    2786          16 :                     n->subtype = AT_EnableReplicaTrig;
    2787          16 :                     n->name = $4;
    2788          16 :                     $$ = (Node *) n;
    2789             :                 }
    2790             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2791             :             | ENABLE_P TRIGGER ALL
    2792             :                 {
    2793           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2794             : 
    2795           0 :                     n->subtype = AT_EnableTrigAll;
    2796           0 :                     $$ = (Node *) n;
    2797             :                 }
    2798             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2799             :             | ENABLE_P TRIGGER USER
    2800             :                 {
    2801           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2802             : 
    2803           0 :                     n->subtype = AT_EnableTrigUser;
    2804           0 :                     $$ = (Node *) n;
    2805             :                 }
    2806             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2807             :             | DISABLE_P TRIGGER name
    2808             :                 {
    2809         138 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2810             : 
    2811         138 :                     n->subtype = AT_DisableTrig;
    2812         138 :                     n->name = $3;
    2813         138 :                     $$ = (Node *) n;
    2814             :                 }
    2815             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2816             :             | DISABLE_P TRIGGER ALL
    2817             :                 {
    2818          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2819             : 
    2820          12 :                     n->subtype = AT_DisableTrigAll;
    2821          12 :                     $$ = (Node *) n;
    2822             :                 }
    2823             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2824             :             | DISABLE_P TRIGGER USER
    2825             :                 {
    2826          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2827             : 
    2828          12 :                     n->subtype = AT_DisableTrigUser;
    2829          12 :                     $$ = (Node *) n;
    2830             :                 }
    2831             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2832             :             | ENABLE_P RULE name
    2833             :                 {
    2834           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2835             : 
    2836           8 :                     n->subtype = AT_EnableRule;
    2837           8 :                     n->name = $3;
    2838           8 :                     $$ = (Node *) n;
    2839             :                 }
    2840             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2841             :             | ENABLE_P ALWAYS RULE name
    2842             :                 {
    2843           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2844             : 
    2845           0 :                     n->subtype = AT_EnableAlwaysRule;
    2846           0 :                     n->name = $4;
    2847           0 :                     $$ = (Node *) n;
    2848             :                 }
    2849             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2850             :             | ENABLE_P REPLICA RULE name
    2851             :                 {
    2852           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2853             : 
    2854           6 :                     n->subtype = AT_EnableReplicaRule;
    2855           6 :                     n->name = $4;
    2856           6 :                     $$ = (Node *) n;
    2857             :                 }
    2858             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2859             :             | DISABLE_P RULE name
    2860             :                 {
    2861          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2862             : 
    2863          32 :                     n->subtype = AT_DisableRule;
    2864          32 :                     n->name = $3;
    2865          32 :                     $$ = (Node *) n;
    2866             :                 }
    2867             :             /* ALTER TABLE <name> INHERIT <parent> */
    2868             :             | INHERIT qualified_name
    2869             :                 {
    2870         410 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2871             : 
    2872         410 :                     n->subtype = AT_AddInherit;
    2873         410 :                     n->def = (Node *) $2;
    2874         410 :                     $$ = (Node *) n;
    2875             :                 }
    2876             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2877             :             | NO INHERIT qualified_name
    2878             :                 {
    2879          86 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2880             : 
    2881          86 :                     n->subtype = AT_DropInherit;
    2882          86 :                     n->def = (Node *) $3;
    2883          86 :                     $$ = (Node *) n;
    2884             :                 }
    2885             :             /* ALTER TABLE <name> OF <type_name> */
    2886             :             | OF any_name
    2887             :                 {
    2888          66 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2889          66 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2890             : 
    2891          66 :                     def->location = @2;
    2892          66 :                     n->subtype = AT_AddOf;
    2893          66 :                     n->def = (Node *) def;
    2894          66 :                     $$ = (Node *) n;
    2895             :                 }
    2896             :             /* ALTER TABLE <name> NOT OF */
    2897             :             | NOT OF
    2898             :                 {
    2899           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2900             : 
    2901           6 :                     n->subtype = AT_DropOf;
    2902           6 :                     $$ = (Node *) n;
    2903             :                 }
    2904             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2905             :             | OWNER TO RoleSpec
    2906             :                 {
    2907        1952 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2908             : 
    2909        1952 :                     n->subtype = AT_ChangeOwner;
    2910        1952 :                     n->newowner = $3;
    2911        1952 :                     $$ = (Node *) n;
    2912             :                 }
    2913             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    2914             :             | SET ACCESS METHOD set_access_method_name
    2915             :                 {
    2916         128 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2917             : 
    2918         128 :                     n->subtype = AT_SetAccessMethod;
    2919         128 :                     n->name = $4;
    2920         128 :                     $$ = (Node *) n;
    2921             :                 }
    2922             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2923             :             | SET TABLESPACE name
    2924             :                 {
    2925         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2926             : 
    2927         104 :                     n->subtype = AT_SetTableSpace;
    2928         104 :                     n->name = $3;
    2929         104 :                     $$ = (Node *) n;
    2930             :                 }
    2931             :             /* ALTER TABLE <name> SET (...) */
    2932             :             | SET reloptions
    2933             :                 {
    2934         594 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2935             : 
    2936         594 :                     n->subtype = AT_SetRelOptions;
    2937         594 :                     n->def = (Node *) $2;
    2938         594 :                     $$ = (Node *) n;
    2939             :                 }
    2940             :             /* ALTER TABLE <name> RESET (...) */
    2941             :             | RESET reloptions
    2942             :                 {
    2943         170 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2944             : 
    2945         170 :                     n->subtype = AT_ResetRelOptions;
    2946         170 :                     n->def = (Node *) $2;
    2947         170 :                     $$ = (Node *) n;
    2948             :                 }
    2949             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    2950             :             | REPLICA IDENTITY_P replica_identity
    2951             :                 {
    2952         490 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2953             : 
    2954         490 :                     n->subtype = AT_ReplicaIdentity;
    2955         490 :                     n->def = $3;
    2956         490 :                     $$ = (Node *) n;
    2957             :                 }
    2958             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    2959             :             | ENABLE_P ROW LEVEL SECURITY
    2960             :                 {
    2961         290 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2962             : 
    2963         290 :                     n->subtype = AT_EnableRowSecurity;
    2964         290 :                     $$ = (Node *) n;
    2965             :                 }
    2966             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    2967             :             | DISABLE_P ROW LEVEL SECURITY
    2968             :                 {
    2969          10 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2970             : 
    2971          10 :                     n->subtype = AT_DisableRowSecurity;
    2972          10 :                     $$ = (Node *) n;
    2973             :                 }
    2974             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    2975             :             | FORCE ROW LEVEL SECURITY
    2976             :                 {
    2977          94 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2978             : 
    2979          94 :                     n->subtype = AT_ForceRowSecurity;
    2980          94 :                     $$ = (Node *) n;
    2981             :                 }
    2982             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    2983             :             | NO FORCE ROW LEVEL SECURITY
    2984             :                 {
    2985          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2986             : 
    2987          32 :                     n->subtype = AT_NoForceRowSecurity;
    2988          32 :                     $$ = (Node *) n;
    2989             :                 }
    2990             :             | alter_generic_options
    2991             :                 {
    2992          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2993             : 
    2994          64 :                     n->subtype = AT_GenericOptions;
    2995          64 :                     n->def = (Node *) $1;
    2996          64 :                     $$ = (Node *) n;
    2997             :                 }
    2998             :         ;
    2999             : 
    3000             : alter_column_default:
    3001         378 :             SET DEFAULT a_expr          { $$ = $3; }
    3002         186 :             | DROP DEFAULT              { $$ = NULL; }
    3003             :         ;
    3004             : 
    3005             : opt_collate_clause:
    3006             :             COLLATE any_name
    3007             :                 {
    3008          18 :                     CollateClause *n = makeNode(CollateClause);
    3009             : 
    3010          18 :                     n->arg = NULL;
    3011          18 :                     n->collname = $2;
    3012          18 :                     n->location = @1;
    3013          18 :                     $$ = (Node *) n;
    3014             :                 }
    3015        4678 :             | /* EMPTY */               { $$ = NULL; }
    3016             :         ;
    3017             : 
    3018             : alter_using:
    3019         174 :             USING a_expr                { $$ = $2; }
    3020         808 :             | /* EMPTY */               { $$ = NULL; }
    3021             :         ;
    3022             : 
    3023             : replica_identity:
    3024             :             NOTHING
    3025             :                 {
    3026          48 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3027             : 
    3028          48 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3029          48 :                     n->name = NULL;
    3030          48 :                     $$ = (Node *) n;
    3031             :                 }
    3032             :             | FULL
    3033             :                 {
    3034         166 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3035             : 
    3036         166 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3037         166 :                     n->name = NULL;
    3038         166 :                     $$ = (Node *) n;
    3039             :                 }
    3040             :             | DEFAULT
    3041             :                 {
    3042           6 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3043             : 
    3044           6 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3045           6 :                     n->name = NULL;
    3046           6 :                     $$ = (Node *) n;
    3047             :                 }
    3048             :             | USING INDEX name
    3049             :                 {
    3050         270 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3051             : 
    3052         270 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3053         270 :                     n->name = $3;
    3054         270 :                     $$ = (Node *) n;
    3055             :                 }
    3056             : ;
    3057             : 
    3058             : reloptions:
    3059        2596 :             '(' reloption_list ')'                  { $$ = $2; }
    3060             :         ;
    3061             : 
    3062         934 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3063       21616 :              |      /* EMPTY */                     { $$ = NIL; }
    3064             :         ;
    3065             : 
    3066             : reloption_list:
    3067        2596 :             reloption_elem                          { $$ = list_make1($1); }
    3068         226 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3069             :         ;
    3070             : 
    3071             : /* This should match def_elem and also allow qualified names */
    3072             : reloption_elem:
    3073             :             ColLabel '=' def_arg
    3074             :                 {
    3075        2200 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3076             :                 }
    3077             :             | ColLabel
    3078             :                 {
    3079         554 :                     $$ = makeDefElem($1, NULL, @1);
    3080             :                 }
    3081             :             | ColLabel '.' ColLabel '=' def_arg
    3082             :                 {
    3083          62 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3084          62 :                                              DEFELEM_UNSPEC, @1);
    3085             :                 }
    3086             :             | ColLabel '.' ColLabel
    3087             :                 {
    3088           6 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3089             :                 }
    3090             :         ;
    3091             : 
    3092             : alter_identity_column_option_list:
    3093             :             alter_identity_column_option
    3094          62 :                 { $$ = list_make1($1); }
    3095             :             | alter_identity_column_option_list alter_identity_column_option
    3096          60 :                 { $$ = lappend($1, $2); }
    3097             :         ;
    3098             : 
    3099             : alter_identity_column_option:
    3100             :             RESTART
    3101             :                 {
    3102          24 :                     $$ = makeDefElem("restart", NULL, @1);
    3103             :                 }
    3104             :             | RESTART opt_with NumericOnly
    3105             :                 {
    3106           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3107             :                 }
    3108             :             | SET SeqOptElem
    3109             :                 {
    3110          54 :                     if (strcmp($2->defname, "as") == 0 ||
    3111          54 :                         strcmp($2->defname, "restart") == 0 ||
    3112          54 :                         strcmp($2->defname, "owned_by") == 0)
    3113           0 :                         ereport(ERROR,
    3114             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3115             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3116             :                                  parser_errposition(@2)));
    3117          54 :                     $$ = $2;
    3118             :                 }
    3119             :             | SET GENERATED generated_when
    3120             :                 {
    3121          44 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3122             :                 }
    3123             :         ;
    3124             : 
    3125             : set_statistics_value:
    3126         158 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3127           0 :             | DEFAULT                       { $$ = NULL; }
    3128             :         ;
    3129             : 
    3130             : set_access_method_name:
    3131          92 :             ColId                           { $$ = $1; }
    3132          36 :             | DEFAULT                       { $$ = NULL; }
    3133             :         ;
    3134             : 
    3135             : PartitionBoundSpec:
    3136             :             /* a HASH partition */
    3137             :             FOR VALUES WITH '(' hash_partbound ')'
    3138             :                 {
    3139             :                     ListCell   *lc;
    3140         704 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3141             : 
    3142         704 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3143         704 :                     n->modulus = n->remainder = -1;
    3144             : 
    3145        2112 :                     foreach (lc, $5)
    3146             :                     {
    3147        1408 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3148             : 
    3149        1408 :                         if (strcmp(opt->defname, "modulus") == 0)
    3150             :                         {
    3151         704 :                             if (n->modulus != -1)
    3152           0 :                                 ereport(ERROR,
    3153             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3154             :                                          errmsg("modulus for hash partition provided more than once"),
    3155             :                                          parser_errposition(opt->location)));
    3156         704 :                             n->modulus = defGetInt32(opt);
    3157             :                         }
    3158         704 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3159             :                         {
    3160         704 :                             if (n->remainder != -1)
    3161           0 :                                 ereport(ERROR,
    3162             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3163             :                                          errmsg("remainder for hash partition provided more than once"),
    3164             :                                          parser_errposition(opt->location)));
    3165         704 :                             n->remainder = defGetInt32(opt);
    3166             :                         }
    3167             :                         else
    3168           0 :                             ereport(ERROR,
    3169             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3170             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3171             :                                             opt->defname),
    3172             :                                      parser_errposition(opt->location)));
    3173             :                     }
    3174             : 
    3175         704 :                     if (n->modulus == -1)
    3176           0 :                         ereport(ERROR,
    3177             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3178             :                                  errmsg("modulus for hash partition must be specified"),
    3179             :                                  parser_errposition(@3)));
    3180         704 :                     if (n->remainder == -1)
    3181           0 :                         ereport(ERROR,
    3182             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3183             :                                  errmsg("remainder for hash partition must be specified"),
    3184             :                                  parser_errposition(@3)));
    3185             : 
    3186         704 :                     n->location = @3;
    3187             : 
    3188         704 :                     $$ = n;
    3189             :                 }
    3190             : 
    3191             :             /* a LIST partition */
    3192             :             | FOR VALUES IN_P '(' expr_list ')'
    3193             :                 {
    3194        4856 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3195             : 
    3196        4856 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3197        4856 :                     n->is_default = false;
    3198        4856 :                     n->listdatums = $5;
    3199        4856 :                     n->location = @3;
    3200             : 
    3201        4856 :                     $$ = n;
    3202             :                 }
    3203             : 
    3204             :             /* a RANGE partition */
    3205             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3206             :                 {
    3207        4116 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3208             : 
    3209        4116 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3210        4116 :                     n->is_default = false;
    3211        4116 :                     n->lowerdatums = $5;
    3212        4116 :                     n->upperdatums = $9;
    3213        4116 :                     n->location = @3;
    3214             : 
    3215        4116 :                     $$ = n;
    3216             :                 }
    3217             : 
    3218             :             /* a DEFAULT partition */
    3219             :             | DEFAULT
    3220             :                 {
    3221         598 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3222             : 
    3223         598 :                     n->is_default = true;
    3224         598 :                     n->location = @1;
    3225             : 
    3226         598 :                     $$ = n;
    3227             :                 }
    3228             :         ;
    3229             : 
    3230             : hash_partbound_elem:
    3231             :         NonReservedWord Iconst
    3232             :             {
    3233        1408 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3234             :             }
    3235             :         ;
    3236             : 
    3237             : hash_partbound:
    3238             :         hash_partbound_elem
    3239             :             {
    3240         704 :                 $$ = list_make1($1);
    3241             :             }
    3242             :         | hash_partbound ',' hash_partbound_elem
    3243             :             {
    3244         704 :                 $$ = lappend($1, $3);
    3245             :             }
    3246             :         ;
    3247             : 
    3248             : /*****************************************************************************
    3249             :  *
    3250             :  *  ALTER TYPE
    3251             :  *
    3252             :  * really variants of the ALTER TABLE subcommands with different spellings
    3253             :  *****************************************************************************/
    3254             : 
    3255             : AlterCompositeTypeStmt:
    3256             :             ALTER TYPE_P any_name alter_type_cmds
    3257             :                 {
    3258         208 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3259             : 
    3260             :                     /* can't use qualified_name, sigh */
    3261         208 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3262         208 :                     n->cmds = $4;
    3263         208 :                     n->objtype = OBJECT_TYPE;
    3264         208 :                     $$ = (Node *) n;
    3265             :                 }
    3266             :             ;
    3267             : 
    3268             : alter_type_cmds:
    3269         208 :             alter_type_cmd                          { $$ = list_make1($1); }
    3270          12 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3271             :         ;
    3272             : 
    3273             : alter_type_cmd:
    3274             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3275             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3276             :                 {
    3277          64 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3278             : 
    3279          64 :                     n->subtype = AT_AddColumn;
    3280          64 :                     n->def = $3;
    3281          64 :                     n->behavior = $4;
    3282          64 :                     $$ = (Node *) n;
    3283             :                 }
    3284             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3285             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3286             :                 {
    3287           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3288             : 
    3289           6 :                     n->subtype = AT_DropColumn;
    3290           6 :                     n->name = $5;
    3291           6 :                     n->behavior = $6;
    3292           6 :                     n->missing_ok = true;
    3293           6 :                     $$ = (Node *) n;
    3294             :                 }
    3295             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3296             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3297             :                 {
    3298          76 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3299             : 
    3300          76 :                     n->subtype = AT_DropColumn;
    3301          76 :                     n->name = $3;
    3302          76 :                     n->behavior = $4;
    3303          76 :                     n->missing_ok = false;
    3304          76 :                     $$ = (Node *) n;
    3305             :                 }
    3306             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3307             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3308             :                 {
    3309          74 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3310          74 :                     ColumnDef *def = makeNode(ColumnDef);
    3311             : 
    3312          74 :                     n->subtype = AT_AlterColumnType;
    3313          74 :                     n->name = $3;
    3314          74 :                     n->def = (Node *) def;
    3315          74 :                     n->behavior = $8;
    3316             :                     /* We only use these fields of the ColumnDef node */
    3317          74 :                     def->typeName = $6;
    3318          74 :                     def->collClause = (CollateClause *) $7;
    3319          74 :                     def->raw_default = NULL;
    3320          74 :                     def->location = @3;
    3321          74 :                     $$ = (Node *) n;
    3322             :                 }
    3323             :         ;
    3324             : 
    3325             : 
    3326             : /*****************************************************************************
    3327             :  *
    3328             :  *      QUERY :
    3329             :  *              close <portalname>
    3330             :  *
    3331             :  *****************************************************************************/
    3332             : 
    3333             : ClosePortalStmt:
    3334             :             CLOSE cursor_name
    3335             :                 {
    3336        2188 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3337             : 
    3338        2188 :                     n->portalname = $2;
    3339        2188 :                     $$ = (Node *) n;
    3340             :                 }
    3341             :             | CLOSE ALL
    3342             :                 {
    3343          12 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3344             : 
    3345          12 :                     n->portalname = NULL;
    3346          12 :                     $$ = (Node *) n;
    3347             :                 }
    3348             :         ;
    3349             : 
    3350             : 
    3351             : /*****************************************************************************
    3352             :  *
    3353             :  *      QUERY :
    3354             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3355             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3356             :  *
    3357             :  *              where 'query' can be one of:
    3358             :  *              { SELECT | UPDATE | INSERT | DELETE }
    3359             :  *
    3360             :  *              and 'file' can be one of:
    3361             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3362             :  *
    3363             :  *              In the preferred syntax the options are comma-separated
    3364             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3365             :  *              syntax had a hard-wired, space-separated set of options.
    3366             :  *
    3367             :  *              Really old syntax, from versions 7.2 and prior:
    3368             :  *              COPY [ BINARY ] table FROM/TO file
    3369             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3370             :  *                  [ WITH NULL AS 'null string' ]
    3371             :  *              This option placement is not supported with COPY (query...).
    3372             :  *
    3373             :  *****************************************************************************/
    3374             : 
    3375             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3376             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3377             :             copy_options where_clause
    3378             :                 {
    3379       10220 :                     CopyStmt *n = makeNode(CopyStmt);
    3380             : 
    3381       10220 :                     n->relation = $3;
    3382       10220 :                     n->query = NULL;
    3383       10220 :                     n->attlist = $4;
    3384       10220 :                     n->is_from = $5;
    3385       10220 :                     n->is_program = $6;
    3386       10220 :                     n->filename = $7;
    3387       10220 :                     n->whereClause = $11;
    3388             : 
    3389       10220 :                     if (n->is_program && n->filename == NULL)
    3390           0 :                         ereport(ERROR,
    3391             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3392             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3393             :                                  parser_errposition(@8)));
    3394             : 
    3395       10220 :                     if (!n->is_from && n->whereClause != NULL)
    3396           6 :                         ereport(ERROR,
    3397             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3398             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3399             :                                  parser_errposition(@11)));
    3400             : 
    3401       10214 :                     n->options = NIL;
    3402             :                     /* Concatenate user-supplied flags */
    3403       10214 :                     if ($2)
    3404          12 :                         n->options = lappend(n->options, $2);
    3405       10214 :                     if ($8)
    3406           0 :                         n->options = lappend(n->options, $8);
    3407       10214 :                     if ($10)
    3408         914 :                         n->options = list_concat(n->options, $10);
    3409       10214 :                     $$ = (Node *) n;
    3410             :                 }
    3411             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3412             :                 {
    3413         462 :                     CopyStmt *n = makeNode(CopyStmt);
    3414             : 
    3415         462 :                     updatePreparableStmtEnd($3, @4);
    3416         462 :                     n->relation = NULL;
    3417         462 :                     n->query = $3;
    3418         462 :                     n->attlist = NIL;
    3419         462 :                     n->is_from = false;
    3420         462 :                     n->is_program = $6;
    3421         462 :                     n->filename = $7;
    3422         462 :                     n->options = $9;
    3423             : 
    3424         462 :                     if (n->is_program && n->filename == NULL)
    3425           0 :                         ereport(ERROR,
    3426             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3427             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3428             :                                  parser_errposition(@5)));
    3429             : 
    3430         462 :                     $$ = (Node *) n;
    3431             :                 }
    3432             :         ;
    3433             : 
    3434             : copy_from:
    3435        1732 :             FROM                                    { $$ = true; }
    3436        8488 :             | TO                                    { $$ = false; }
    3437             :         ;
    3438             : 
    3439             : opt_program:
    3440           0 :             PROGRAM                                 { $$ = true; }
    3441       10682 :             | /* EMPTY */                           { $$ = false; }
    3442             :         ;
    3443             : 
    3444             : /*
    3445             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3446             :  * used depends on the direction. (It really doesn't make sense to copy from
    3447             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3448             :  */
    3449             : copy_file_name:
    3450         442 :             Sconst                                  { $$ = $1; }
    3451        1354 :             | STDIN                                 { $$ = NULL; }
    3452        8886 :             | STDOUT                                { $$ = NULL; }
    3453             :         ;
    3454             : 
    3455       10038 : copy_options: copy_opt_list                         { $$ = $1; }
    3456         644 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3457             :         ;
    3458             : 
    3459             : /* old COPY option syntax */
    3460             : copy_opt_list:
    3461         504 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3462       10038 :             | /* EMPTY */                           { $$ = NIL; }
    3463             :         ;
    3464             : 
    3465             : copy_opt_item:
    3466             :             BINARY
    3467             :                 {
    3468           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3469             :                 }
    3470             :             | FREEZE
    3471             :                 {
    3472          50 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3473             :                 }
    3474             :             | DELIMITER opt_as Sconst
    3475             :                 {
    3476         172 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3477             :                 }
    3478             :             | NULL_P opt_as Sconst
    3479             :                 {
    3480          48 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3481             :                 }
    3482             :             | CSV
    3483             :                 {
    3484         150 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3485             :                 }
    3486             :             | HEADER_P
    3487             :                 {
    3488          18 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3489             :                 }
    3490             :             | QUOTE opt_as Sconst
    3491             :                 {
    3492          18 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3493             :                 }
    3494             :             | ESCAPE opt_as Sconst
    3495             :                 {
    3496          18 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3497             :                 }
    3498             :             | FORCE QUOTE columnList
    3499             :                 {
    3500          12 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3501             :                 }
    3502             :             | FORCE QUOTE '*'
    3503             :                 {
    3504           6 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3505             :                 }
    3506             :             | FORCE NOT NULL_P columnList
    3507             :                 {
    3508           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3509             :                 }
    3510             :             | FORCE NOT NULL_P '*'
    3511             :                 {
    3512           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3513             :                 }
    3514             :             | FORCE NULL_P columnList
    3515             :                 {
    3516           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3517             :                 }
    3518             :             | FORCE NULL_P '*'
    3519             :                 {
    3520           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3521             :                 }
    3522             :             | ENCODING Sconst
    3523             :                 {
    3524          12 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3525             :                 }
    3526             :         ;
    3527             : 
    3528             : /* The following exist for backward compatibility with very old versions */
    3529             : 
    3530             : opt_binary:
    3531             :             BINARY
    3532             :                 {
    3533          12 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3534             :                 }
    3535       10208 :             | /*EMPTY*/                             { $$ = NULL; }
    3536             :         ;
    3537             : 
    3538             : copy_delimiter:
    3539             :             opt_using DELIMITERS Sconst
    3540             :                 {
    3541           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3542             :                 }
    3543       10220 :             | /*EMPTY*/                             { $$ = NULL; }
    3544             :         ;
    3545             : 
    3546             : opt_using:
    3547             :             USING
    3548             :             | /*EMPTY*/
    3549             :         ;
    3550             : 
    3551             : /* new COPY option syntax */
    3552             : copy_generic_opt_list:
    3553             :             copy_generic_opt_elem
    3554             :                 {
    3555         644 :                     $$ = list_make1($1);
    3556             :                 }
    3557             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3558             :                 {
    3559         450 :                     $$ = lappend($1, $3);
    3560             :                 }
    3561             :         ;
    3562             : 
    3563             : copy_generic_opt_elem:
    3564             :             ColLabel copy_generic_opt_arg
    3565             :                 {
    3566        1094 :                     $$ = makeDefElem($1, $2, @1);
    3567             :                 }
    3568             :         ;
    3569             : 
    3570             : copy_generic_opt_arg:
    3571         800 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3572          24 :             | NumericOnly                   { $$ = (Node *) $1; }
    3573          90 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3574           6 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3575         150 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3576          24 :             | /* EMPTY */                   { $$ = NULL; }
    3577             :         ;
    3578             : 
    3579             : copy_generic_opt_arg_list:
    3580             :               copy_generic_opt_arg_list_item
    3581             :                 {
    3582         150 :                     $$ = list_make1($1);
    3583             :                 }
    3584             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3585             :                 {
    3586          12 :                     $$ = lappend($1, $3);
    3587             :                 }
    3588             :         ;
    3589             : 
    3590             : /* beware of emitting non-string list elements here; see commands/define.c */
    3591             : copy_generic_opt_arg_list_item:
    3592         162 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3593             :         ;
    3594             : 
    3595             : 
    3596             : /*****************************************************************************
    3597             :  *
    3598             :  *      QUERY :
    3599             :  *              CREATE TABLE relname
    3600             :  *
    3601             :  *****************************************************************************/
    3602             : 
    3603             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3604             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3605             :             OnCommitOption OptTableSpace
    3606             :                 {
    3607       28824 :                     CreateStmt *n = makeNode(CreateStmt);
    3608             : 
    3609       28824 :                     $4->relpersistence = $2;
    3610       28824 :                     n->relation = $4;
    3611       28824 :                     n->tableElts = $6;
    3612       28824 :                     n->inhRelations = $8;
    3613       28824 :                     n->partspec = $9;
    3614       28824 :                     n->ofTypename = NULL;
    3615       28824 :                     n->constraints = NIL;
    3616       28824 :                     n->accessMethod = $10;
    3617       28824 :                     n->options = $11;
    3618       28824 :                     n->oncommit = $12;
    3619       28824 :                     n->tablespacename = $13;
    3620       28824 :                     n->if_not_exists = false;
    3621       28824 :                     $$ = (Node *) n;
    3622             :                 }
    3623             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3624             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3625             :             OptWith OnCommitOption OptTableSpace
    3626             :                 {
    3627          30 :                     CreateStmt *n = makeNode(CreateStmt);
    3628             : 
    3629          30 :                     $7->relpersistence = $2;
    3630          30 :                     n->relation = $7;
    3631          30 :                     n->tableElts = $9;
    3632          30 :                     n->inhRelations = $11;
    3633          30 :                     n->partspec = $12;
    3634          30 :                     n->ofTypename = NULL;
    3635          30 :                     n->constraints = NIL;
    3636          30 :                     n->accessMethod = $13;
    3637          30 :                     n->options = $14;
    3638          30 :                     n->oncommit = $15;
    3639          30 :                     n->tablespacename = $16;
    3640          30 :                     n->if_not_exists = true;
    3641          30 :                     $$ = (Node *) n;
    3642             :                 }
    3643             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3644             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3645             :             OptWith OnCommitOption OptTableSpace
    3646             :                 {
    3647         122 :                     CreateStmt *n = makeNode(CreateStmt);
    3648             : 
    3649         122 :                     $4->relpersistence = $2;
    3650         122 :                     n->relation = $4;
    3651         122 :                     n->tableElts = $7;
    3652         122 :                     n->inhRelations = NIL;
    3653         122 :                     n->partspec = $8;
    3654         122 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3655         122 :                     n->ofTypename->location = @6;
    3656         122 :                     n->constraints = NIL;
    3657         122 :                     n->accessMethod = $9;
    3658         122 :                     n->options = $10;
    3659         122 :                     n->oncommit = $11;
    3660         122 :                     n->tablespacename = $12;
    3661         122 :                     n->if_not_exists = false;
    3662         122 :                     $$ = (Node *) n;
    3663             :                 }
    3664             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3665             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3666             :             OptWith OnCommitOption OptTableSpace
    3667             :                 {
    3668           6 :                     CreateStmt *n = makeNode(CreateStmt);
    3669             : 
    3670           6 :                     $7->relpersistence = $2;
    3671           6 :                     n->relation = $7;
    3672           6 :                     n->tableElts = $10;
    3673           6 :                     n->inhRelations = NIL;
    3674           6 :                     n->partspec = $11;
    3675           6 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3676           6 :                     n->ofTypename->location = @9;
    3677           6 :                     n->constraints = NIL;
    3678           6 :                     n->accessMethod = $12;
    3679           6 :                     n->options = $13;
    3680           6 :                     n->oncommit = $14;
    3681           6 :                     n->tablespacename = $15;
    3682           6 :                     n->if_not_exists = true;
    3683           6 :                     $$ = (Node *) n;
    3684             :                 }
    3685             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3686             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3687             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3688             :                 {
    3689        7842 :                     CreateStmt *n = makeNode(CreateStmt);
    3690             : 
    3691        7842 :                     $4->relpersistence = $2;
    3692        7842 :                     n->relation = $4;
    3693        7842 :                     n->tableElts = $8;
    3694        7842 :                     n->inhRelations = list_make1($7);
    3695        7842 :                     n->partbound = $9;
    3696        7842 :                     n->partspec = $10;
    3697        7842 :                     n->ofTypename = NULL;
    3698        7842 :                     n->constraints = NIL;
    3699        7842 :                     n->accessMethod = $11;
    3700        7842 :                     n->options = $12;
    3701        7842 :                     n->oncommit = $13;
    3702        7842 :                     n->tablespacename = $14;
    3703        7842 :                     n->if_not_exists = false;
    3704        7842 :                     $$ = (Node *) n;
    3705             :                 }
    3706             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3707             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3708             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3709             :                 {
    3710           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3711             : 
    3712           0 :                     $7->relpersistence = $2;
    3713           0 :                     n->relation = $7;
    3714           0 :                     n->tableElts = $11;
    3715           0 :                     n->inhRelations = list_make1($10);
    3716           0 :                     n->partbound = $12;
    3717           0 :                     n->partspec = $13;
    3718           0 :                     n->ofTypename = NULL;
    3719           0 :                     n->constraints = NIL;
    3720           0 :                     n->accessMethod = $14;
    3721           0 :                     n->options = $15;
    3722           0 :                     n->oncommit = $16;
    3723           0 :                     n->tablespacename = $17;
    3724           0 :                     n->if_not_exists = true;
    3725           0 :                     $$ = (Node *) n;
    3726             :                 }
    3727             :         ;
    3728             : 
    3729             : /*
    3730             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3731             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3732             :  *
    3733             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3734             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3735             :  * temp table behavior, so warn about that.  Since we have no modules the
    3736             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3737             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3738             :  * so we'll probably continue to treat LOCAL as a noise word.
    3739             :  */
    3740         312 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3741        2694 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3742           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3743           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3744             :             | GLOBAL TEMPORARY
    3745             :                 {
    3746           0 :                     ereport(WARNING,
    3747             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3748             :                              parser_errposition(@1)));
    3749           0 :                     $$ = RELPERSISTENCE_TEMP;
    3750             :                 }
    3751             :             | GLOBAL TEMP
    3752             :                 {
    3753           0 :                     ereport(WARNING,
    3754             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3755             :                              parser_errposition(@1)));
    3756           0 :                     $$ = RELPERSISTENCE_TEMP;
    3757             :                 }
    3758         152 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3759       51026 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3760             :         ;
    3761             : 
    3762             : OptTableElementList:
    3763       27736 :             TableElementList                    { $$ = $1; }
    3764        1550 :             | /*EMPTY*/                         { $$ = NIL; }
    3765             :         ;
    3766             : 
    3767             : OptTypedTableElementList:
    3768         348 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3769        7718 :             | /*EMPTY*/                         { $$ = NIL; }
    3770             :         ;
    3771             : 
    3772             : TableElementList:
    3773             :             TableElement
    3774             :                 {
    3775       27790 :                     $$ = list_make1($1);
    3776             :                 }
    3777             :             | TableElementList ',' TableElement
    3778             :                 {
    3779       39694 :                     $$ = lappend($1, $3);
    3780             :                 }
    3781             :         ;
    3782             : 
    3783             : TypedTableElementList:
    3784             :             TypedTableElement
    3785             :                 {
    3786         348 :                     $$ = list_make1($1);
    3787             :                 }
    3788             :             | TypedTableElementList ',' TypedTableElement
    3789             :                 {
    3790          68 :                     $$ = lappend($1, $3);
    3791             :                 }
    3792             :         ;
    3793             : 
    3794             : TableElement:
    3795       64076 :             columnDef                           { $$ = $1; }
    3796         768 :             | TableLikeClause                   { $$ = $1; }
    3797        2640 :             | TableConstraint                   { $$ = $1; }
    3798             :         ;
    3799             : 
    3800             : TypedTableElement:
    3801         346 :             columnOptions                       { $$ = $1; }
    3802          70 :             | TableConstraint                   { $$ = $1; }
    3803             :         ;
    3804             : 
    3805             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3806             :                 {
    3807       66206 :                     ColumnDef *n = makeNode(ColumnDef);
    3808             : 
    3809       66206 :                     n->colname = $1;
    3810       66206 :                     n->typeName = $2;
    3811       66206 :                     n->storage_name = $3;
    3812       66206 :                     n->compression = $4;
    3813       66206 :                     n->inhcount = 0;
    3814       66206 :                     n->is_local = true;
    3815       66206 :                     n->is_not_null = false;
    3816       66206 :                     n->is_from_type = false;
    3817       66206 :                     n->storage = 0;
    3818       66206 :                     n->raw_default = NULL;
    3819       66206 :                     n->cooked_default = NULL;
    3820       66206 :                     n->collOid = InvalidOid;
    3821       66206 :                     n->fdwoptions = $5;
    3822       66206 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3823             :                                      yyscanner);
    3824       66206 :                     n->location = @1;
    3825       66206 :                     $$ = (Node *) n;
    3826             :                 }
    3827             :         ;
    3828             : 
    3829             : columnOptions:  ColId ColQualList
    3830             :                 {
    3831         138 :                     ColumnDef *n = makeNode(ColumnDef);
    3832             : 
    3833         138 :                     n->colname = $1;
    3834         138 :                     n->typeName = NULL;
    3835         138 :                     n->inhcount = 0;
    3836         138 :                     n->is_local = true;
    3837         138 :                     n->is_not_null = false;
    3838         138 :                     n->is_from_type = false;
    3839         138 :                     n->storage = 0;
    3840         138 :                     n->raw_default = NULL;
    3841         138 :                     n->cooked_default = NULL;
    3842         138 :                     n->collOid = InvalidOid;
    3843         138 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3844             :                                      yyscanner);
    3845         138 :                     n->location = @1;
    3846         138 :                     $$ = (Node *) n;
    3847             :                 }
    3848             :                 | ColId WITH OPTIONS ColQualList
    3849             :                 {
    3850         208 :                     ColumnDef *n = makeNode(ColumnDef);
    3851             : 
    3852         208 :                     n->colname = $1;
    3853         208 :                     n->typeName = NULL;
    3854         208 :                     n->inhcount = 0;
    3855         208 :                     n->is_local = true;
    3856         208 :                     n->is_not_null = false;
    3857         208 :                     n->is_from_type = false;
    3858         208 :                     n->storage = 0;
    3859         208 :                     n->raw_default = NULL;
    3860         208 :                     n->cooked_default = NULL;
    3861         208 :                     n->collOid = InvalidOid;
    3862         208 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3863             :                                      yyscanner);
    3864         208 :                     n->location = @1;
    3865         208 :                     $$ = (Node *) n;
    3866             :                 }
    3867             :         ;
    3868             : 
    3869             : column_compression:
    3870         144 :             COMPRESSION ColId                       { $$ = $2; }
    3871           6 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3872             :         ;
    3873             : 
    3874             : opt_column_compression:
    3875          82 :             column_compression                      { $$ = $1; }
    3876       66190 :             | /*EMPTY*/                             { $$ = NULL; }
    3877             :         ;
    3878             : 
    3879             : column_storage:
    3880         232 :             STORAGE ColId                           { $$ = $2; }
    3881           6 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3882             :         ;
    3883             : 
    3884             : opt_column_storage:
    3885          20 :             column_storage                          { $$ = $1; }
    3886       66252 :             | /*EMPTY*/                             { $$ = NULL; }
    3887             :         ;
    3888             : 
    3889             : ColQualList:
    3890       19426 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3891       67990 :             | /*EMPTY*/                             { $$ = NIL; }
    3892             :         ;
    3893             : 
    3894             : ColConstraint:
    3895             :             CONSTRAINT name ColConstraintElem
    3896             :                 {
    3897         742 :                     Constraint *n = castNode(Constraint, $3);
    3898             : 
    3899         742 :                     n->conname = $2;
    3900         742 :                     n->location = @1;
    3901         742 :                     $$ = (Node *) n;
    3902             :                 }
    3903       17666 :             | ColConstraintElem                     { $$ = $1; }
    3904         276 :             | ConstraintAttr                        { $$ = $1; }
    3905             :             | COLLATE any_name
    3906             :                 {
    3907             :                     /*
    3908             :                      * Note: the CollateClause is momentarily included in
    3909             :                      * the list built by ColQualList, but we split it out
    3910             :                      * again in SplitColQualList.
    3911             :                      */
    3912         742 :                     CollateClause *n = makeNode(CollateClause);
    3913             : 
    3914         742 :                     n->arg = NULL;
    3915         742 :                     n->collname = $2;
    3916         742 :                     n->location = @1;
    3917         742 :                     $$ = (Node *) n;
    3918             :                 }
    3919             :         ;
    3920             : 
    3921             : /* DEFAULT NULL is already the default for Postgres.
    3922             :  * But define it here and carry it forward into the system
    3923             :  * to make it explicit.
    3924             :  * - thomas 1998-09-13
    3925             :  *
    3926             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3927             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3928             :  * that a column may have that value. WITH NULL leads to
    3929             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3930             :  * - thomas 1999-01-08
    3931             :  *
    3932             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3933             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3934             :  * or be part of a_expr NOT LIKE or similar constructs).
    3935             :  */
    3936             : ColConstraintElem:
    3937             :             NOT NULL_P opt_no_inherit
    3938             :                 {
    3939        6548 :                     Constraint *n = makeNode(Constraint);
    3940             : 
    3941        6548 :                     n->contype = CONSTR_NOTNULL;
    3942        6548 :                     n->location = @1;
    3943        6548 :                     n->is_no_inherit = $3;
    3944        6548 :                     n->is_enforced = true;
    3945        6548 :                     n->skip_validation = false;
    3946        6548 :                     n->initially_valid = true;
    3947        6548 :                     $$ = (Node *) n;
    3948             :                 }
    3949             :             | NULL_P
    3950             :                 {
    3951          30 :                     Constraint *n = makeNode(Constraint);
    3952             : 
    3953          30 :                     n->contype = CONSTR_NULL;
    3954          30 :                     n->location = @1;
    3955          30 :                     $$ = (Node *) n;
    3956             :                 }
    3957             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    3958             :                 {
    3959         442 :                     Constraint *n = makeNode(Constraint);
    3960             : 
    3961         442 :                     n->contype = CONSTR_UNIQUE;
    3962         442 :                     n->location = @1;
    3963         442 :                     n->nulls_not_distinct = !$2;
    3964         442 :                     n->keys = NULL;
    3965         442 :                     n->options = $3;
    3966         442 :                     n->indexname = NULL;
    3967         442 :                     n->indexspace = $4;
    3968         442 :                     $$ = (Node *) n;
    3969             :                 }
    3970             :             | PRIMARY KEY opt_definition OptConsTableSpace
    3971             :                 {
    3972        5744 :                     Constraint *n = makeNode(Constraint);
    3973             : 
    3974        5744 :                     n->contype = CONSTR_PRIMARY;
    3975        5744 :                     n->location = @1;
    3976        5744 :                     n->keys = NULL;
    3977        5744 :                     n->options = $3;
    3978        5744 :                     n->indexname = NULL;
    3979        5744 :                     n->indexspace = $4;
    3980        5744 :                     $$ = (Node *) n;
    3981             :                 }
    3982             :             | CHECK '(' a_expr ')' opt_no_inherit
    3983             :                 {
    3984        1044 :                     Constraint *n = makeNode(Constraint);
    3985             : 
    3986        1044 :                     n->contype = CONSTR_CHECK;
    3987        1044 :                     n->location = @1;
    3988        1044 :                     n->is_no_inherit = $5;
    3989        1044 :                     n->raw_expr = $3;
    3990        1044 :                     n->cooked_expr = NULL;
    3991        1044 :                     n->is_enforced = true;
    3992        1044 :                     n->skip_validation = false;
    3993        1044 :                     n->initially_valid = true;
    3994        1044 :                     $$ = (Node *) n;
    3995             :                 }
    3996             :             | DEFAULT b_expr
    3997             :                 {
    3998        1784 :                     Constraint *n = makeNode(Constraint);
    3999             : 
    4000        1784 :                     n->contype = CONSTR_DEFAULT;
    4001        1784 :                     n->location = @1;
    4002        1784 :                     n->raw_expr = $2;
    4003        1784 :                     n->cooked_expr = NULL;
    4004        1784 :                     $$ = (Node *) n;
    4005             :                 }
    4006             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    4007             :                 {
    4008         332 :                     Constraint *n = makeNode(Constraint);
    4009             : 
    4010         332 :                     n->contype = CONSTR_IDENTITY;
    4011         332 :                     n->generated_when = $2;
    4012         332 :                     n->options = $5;
    4013         332 :                     n->location = @1;
    4014         332 :                     $$ = (Node *) n;
    4015             :                 }
    4016             :             | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
    4017             :                 {
    4018        1674 :                     Constraint *n = makeNode(Constraint);
    4019             : 
    4020        1674 :                     n->contype = CONSTR_GENERATED;
    4021        1674 :                     n->generated_when = $2;
    4022        1674 :                     n->raw_expr = $5;
    4023        1674 :                     n->cooked_expr = NULL;
    4024        1674 :                     n->generated_kind = $7;
    4025        1674 :                     n->location = @1;
    4026             : 
    4027             :                     /*
    4028             :                      * Can't do this in the grammar because of shift/reduce
    4029             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4030             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4031             :                      * can also give a more useful error message and location.
    4032             :                      */
    4033        1674 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4034          12 :                         ereport(ERROR,
    4035             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4036             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4037             :                                  parser_errposition(@2)));
    4038             : 
    4039        1662 :                     $$ = (Node *) n;
    4040             :                 }
    4041             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4042             :                 {
    4043         822 :                     Constraint *n = makeNode(Constraint);
    4044             : 
    4045         822 :                     n->contype = CONSTR_FOREIGN;
    4046         822 :                     n->location = @1;
    4047         822 :                     n->pktable = $2;
    4048         822 :                     n->fk_attrs = NIL;
    4049         822 :                     n->pk_attrs = $3;
    4050         822 :                     n->fk_matchtype = $4;
    4051         822 :                     n->fk_upd_action = ($5)->updateAction->action;
    4052         822 :                     n->fk_del_action = ($5)->deleteAction->action;
    4053         822 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4054         822 :                     n->is_enforced = true;
    4055         822 :                     n->skip_validation = false;
    4056         822 :                     n->initially_valid = true;
    4057         822 :                     $$ = (Node *) n;
    4058             :                 }
    4059             :         ;
    4060             : 
    4061             : opt_unique_null_treatment:
    4062          12 :             NULLS_P DISTINCT        { $$ = true; }
    4063          36 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4064        7652 :             | /*EMPTY*/             { $$ = true; }
    4065             :         ;
    4066             : 
    4067             : generated_when:
    4068        2034 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4069         182 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4070             :         ;
    4071             : 
    4072             : opt_virtual_or_stored:
    4073         960 :             STORED          { $$ = ATTRIBUTE_GENERATED_STORED; }
    4074         610 :             | VIRTUAL       { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4075         104 :             | /*EMPTY*/     { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4076             :         ;
    4077             : 
    4078             : /*
    4079             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4080             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4081             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4082             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4083             :  * attribute information to the preceding "real" constraint node, and for
    4084             :  * complaining if attribute clauses appear in the wrong place or wrong
    4085             :  * combinations.
    4086             :  *
    4087             :  * See also ConstraintAttributeSpec, which can be used in places where
    4088             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4089             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4090             :  * might need to allow them here too, but for the moment it doesn't seem
    4091             :  * useful in the statements that use ConstraintAttr.)
    4092             :  */
    4093             : ConstraintAttr:
    4094             :             DEFERRABLE
    4095             :                 {
    4096         102 :                     Constraint *n = makeNode(Constraint);
    4097             : 
    4098         102 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4099         102 :                     n->location = @1;
    4100         102 :                     $$ = (Node *) n;
    4101             :                 }
    4102             :             | NOT DEFERRABLE
    4103             :                 {
    4104           0 :                     Constraint *n = makeNode(Constraint);
    4105             : 
    4106           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4107           0 :                     n->location = @1;
    4108           0 :                     $$ = (Node *) n;
    4109             :                 }
    4110             :             | INITIALLY DEFERRED
    4111             :                 {
    4112          78 :                     Constraint *n = makeNode(Constraint);
    4113             : 
    4114          78 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4115          78 :                     n->location = @1;
    4116          78 :                     $$ = (Node *) n;
    4117             :                 }
    4118             :             | INITIALLY IMMEDIATE
    4119             :                 {
    4120           6 :                     Constraint *n = makeNode(Constraint);
    4121             : 
    4122           6 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4123           6 :                     n->location = @1;
    4124           6 :                     $$ = (Node *) n;
    4125             :                 }
    4126             :             | ENFORCED
    4127             :                 {
    4128          36 :                     Constraint *n = makeNode(Constraint);
    4129             : 
    4130          36 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4131          36 :                     n->location = @1;
    4132          36 :                     $$ = (Node *) n;
    4133             :                 }
    4134             :             | NOT ENFORCED
    4135             :                 {
    4136          54 :                     Constraint *n = makeNode(Constraint);
    4137             : 
    4138          54 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4139          54 :                     n->location = @1;
    4140          54 :                     $$ = (Node *) n;
    4141             :                 }
    4142             :         ;
    4143             : 
    4144             : 
    4145             : TableLikeClause:
    4146             :             LIKE qualified_name TableLikeOptionList
    4147             :                 {
    4148         768 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4149             : 
    4150         768 :                     n->relation = $2;
    4151         768 :                     n->options = $3;
    4152         768 :                     n->relationOid = InvalidOid;
    4153         768 :                     $$ = (Node *) n;
    4154             :                 }
    4155             :         ;
    4156             : 
    4157             : TableLikeOptionList:
    4158         282 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4159           8 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4160         768 :                 | /* EMPTY */                       { $$ = 0; }
    4161             :         ;
    4162             : 
    4163             : TableLikeOption:
    4164          24 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4165           6 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4166          54 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4167          20 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4168          12 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4169          30 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4170          50 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4171           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4172          26 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4173          68 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4174             :         ;
    4175             : 
    4176             : 
    4177             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4178             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4179             :  * - thomas 1997-12-03
    4180             :  */
    4181             : TableConstraint:
    4182             :             CONSTRAINT name ConstraintElem
    4183             :                 {
    4184        3848 :                     Constraint *n = castNode(Constraint, $3);
    4185             : 
    4186        3848 :                     n->conname = $2;
    4187        3848 :                     n->location = @1;
    4188        3848 :                     $$ = (Node *) n;
    4189             :                 }
    4190       12044 :             | ConstraintElem                        { $$ = $1; }
    4191             :         ;
    4192             : 
    4193             : ConstraintElem:
    4194             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4195             :                 {
    4196        1200 :                     Constraint *n = makeNode(Constraint);
    4197             : 
    4198        1200 :                     n->contype = CONSTR_CHECK;
    4199        1200 :                     n->location = @1;
    4200        1200 :                     n->raw_expr = $3;
    4201        1200 :                     n->cooked_expr = NULL;
    4202        1200 :                     processCASbits($5, @5, "CHECK",
    4203             :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4204             :                                    &n->is_no_inherit, yyscanner);
    4205        1200 :                     n->initially_valid = !n->skip_validation;
    4206        1200 :                     $$ = (Node *) n;
    4207             :                 }
    4208             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4209             :                 {
    4210         404 :                     Constraint *n = makeNode(Constraint);
    4211             : 
    4212         404 :                     n->contype = CONSTR_NOTNULL;
    4213         404 :                     n->location = @1;
    4214         404 :                     n->keys = list_make1(makeString($3));
    4215             :                     /* no NOT VALID support yet */
    4216         404 :                     processCASbits($4, @4, "NOT NULL",
    4217             :                                    NULL, NULL, NULL, NULL,
    4218             :                                    &n->is_no_inherit, yyscanner);
    4219         404 :                     n->initially_valid = true;
    4220         404 :                     $$ = (Node *) n;
    4221             :                 }
    4222             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4223             :                 ConstraintAttributeSpec
    4224             :                 {
    4225         614 :                     Constraint *n = makeNode(Constraint);
    4226             : 
    4227         614 :                     n->contype = CONSTR_UNIQUE;
    4228         614 :                     n->location = @1;
    4229         614 :                     n->nulls_not_distinct = !$2;
    4230         614 :                     n->keys = $4;
    4231         614 :                     n->without_overlaps = $5;
    4232         614 :                     n->including = $7;
    4233         614 :                     n->options = $8;
    4234         614 :                     n->indexname = NULL;
    4235         614 :                     n->indexspace = $9;
    4236         614 :                     processCASbits($10, @10, "UNIQUE",
    4237             :                                    &n->deferrable, &n->initdeferred, NULL,
    4238             :                                    NULL, NULL, yyscanner);
    4239         614 :                     $$ = (Node *) n;
    4240             :                 }
    4241             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4242             :                 {
    4243        4168 :                     Constraint *n = makeNode(Constraint);
    4244             : 
    4245        4168 :                     n->contype = CONSTR_UNIQUE;
    4246        4168 :                     n->location = @1;
    4247        4168 :                     n->keys = NIL;
    4248        4168 :                     n->including = NIL;
    4249        4168 :                     n->options = NIL;
    4250        4168 :                     n->indexname = $2;
    4251        4168 :                     n->indexspace = NULL;
    4252        4168 :                     processCASbits($3, @3, "UNIQUE",
    4253             :                                    &n->deferrable, &n->initdeferred, NULL,
    4254             :                                    NULL, NULL, yyscanner);
    4255        4168 :                     $$ = (Node *) n;
    4256             :                 }
    4257             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4258             :                 ConstraintAttributeSpec
    4259             :                 {
    4260        2096 :                     Constraint *n = makeNode(Constraint);
    4261             : 
    4262        2096 :                     n->contype = CONSTR_PRIMARY;
    4263        2096 :                     n->location = @1;
    4264        2096 :                     n->keys = $4;
    4265        2096 :                     n->without_overlaps = $5;
    4266        2096 :                     n->including = $7;
    4267        2096 :                     n->options = $8;
    4268        2096 :                     n->indexname = NULL;
    4269        2096 :                     n->indexspace = $9;
    4270        2096 :                     processCASbits($10, @10, "PRIMARY KEY",
    4271             :                                    &n->deferrable, &n->initdeferred, NULL,
    4272             :                                    NULL, NULL, yyscanner);
    4273        2096 :                     $$ = (Node *) n;
    4274             :                 }
    4275             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4276             :                 {
    4277        5398 :                     Constraint *n = makeNode(Constraint);
    4278             : 
    4279        5398 :                     n->contype = CONSTR_PRIMARY;
    4280        5398 :                     n->location = @1;
    4281        5398 :                     n->keys = NIL;
    4282        5398 :                     n->including = NIL;
    4283        5398 :                     n->options = NIL;
    4284        5398 :                     n->indexname = $3;
    4285        5398 :                     n->indexspace = NULL;
    4286        5398 :                     processCASbits($4, @4, "PRIMARY KEY",
    4287             :                                    &n->deferrable, &n->initdeferred, NULL,
    4288             :                                    NULL, NULL, yyscanner);
    4289        5398 :                     $$ = (Node *) n;
    4290             :                 }
    4291             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4292             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4293             :                 ConstraintAttributeSpec
    4294             :                 {
    4295         234 :                     Constraint *n = makeNode(Constraint);
    4296             : 
    4297         234 :                     n->contype = CONSTR_EXCLUSION;
    4298         234 :                     n->location = @1;
    4299         234 :                     n->access_method = $2;
    4300         234 :                     n->exclusions = $4;
    4301         234 :                     n->including = $6;
    4302         234 :                     n->options = $7;
    4303         234 :                     n->indexname = NULL;
    4304         234 :                     n->indexspace = $8;
    4305         234 :                     n->where_clause = $9;
    4306         234 :                     processCASbits($10, @10, "EXCLUDE",
    4307             :                                    &n->deferrable, &n->initdeferred, NULL,
    4308             :                                    NULL, NULL, yyscanner);
    4309         234 :                     $$ = (Node *) n;
    4310             :                 }
    4311             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4312             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4313             :                 {
    4314        1778 :                     Constraint *n = makeNode(Constraint);
    4315             : 
    4316        1778 :                     n->contype = CONSTR_FOREIGN;
    4317        1778 :                     n->location = @1;
    4318        1778 :                     n->pktable = $8;
    4319        1778 :                     n->fk_attrs = $4;
    4320        1778 :                     if ($5)
    4321             :                     {
    4322         290 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4323         290 :                         n->fk_with_period = true;
    4324             :                     }
    4325        1778 :                     n->pk_attrs = linitial($9);
    4326        1778 :                     if (lsecond($9))
    4327             :                     {
    4328         170 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4329         170 :                         n->pk_with_period = true;
    4330             :                     }
    4331        1778 :                     n->fk_matchtype = $10;
    4332        1778 :                     n->fk_upd_action = ($11)->updateAction->action;
    4333        1778 :                     n->fk_del_action = ($11)->deleteAction->action;
    4334        1778 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4335        1778 :                     processCASbits($12, @12, "FOREIGN KEY",
    4336             :                                    &n->deferrable, &n->initdeferred,
    4337             :                                    NULL, &n->skip_validation, NULL,
    4338             :                                    yyscanner);
    4339        1778 :                     n->initially_valid = !n->skip_validation;
    4340        1778 :                     $$ = (Node *) n;
    4341             :                 }
    4342             :         ;
    4343             : 
    4344             : /*
    4345             :  * DomainConstraint is separate from TableConstraint because the syntax for
    4346             :  * NOT NULL constraints is different.  For table constraints, we need to
    4347             :  * accept a column name, but for domain constraints, we don't.  (We could
    4348             :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4349             :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4350             :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4351             :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4352             :  * standard; we are just living with the bits of inconsistency that have built
    4353             :  * up over time.
    4354             :  */
    4355             : DomainConstraint:
    4356             :             CONSTRAINT name DomainConstraintElem
    4357             :                 {
    4358         156 :                     Constraint *n = castNode(Constraint, $3);
    4359             : 
    4360         156 :                     n->conname = $2;
    4361         156 :                     n->location = @1;
    4362         156 :                     $$ = (Node *) n;
    4363             :                 }
    4364          18 :             | DomainConstraintElem                  { $$ = $1; }
    4365             :         ;
    4366             : 
    4367             : DomainConstraintElem:
    4368             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4369             :                 {
    4370         156 :                     Constraint *n = makeNode(Constraint);
    4371             : 
    4372         156 :                     n->contype = CONSTR_CHECK;
    4373         156 :                     n->location = @1;
    4374         156 :                     n->raw_expr = $3;
    4375         156 :                     n->cooked_expr = NULL;
    4376         156 :                     processCASbits($5, @5, "CHECK",
    4377             :                                    NULL, NULL, NULL, &n->skip_validation,
    4378             :                                    &n->is_no_inherit, yyscanner);
    4379         144 :                     n->is_enforced = true;
    4380         144 :                     n->initially_valid = !n->skip_validation;
    4381         144 :                     $$ = (Node *) n;
    4382             :                 }
    4383             :             | NOT NULL_P ConstraintAttributeSpec
    4384             :                 {
    4385          30 :                     Constraint *n = makeNode(Constraint);
    4386             : 
    4387          30 :                     n->contype = CONSTR_NOTNULL;
    4388          30 :                     n->location = @1;
    4389          30 :                     n->keys = list_make1(makeString("value"));
    4390             :                     /* no NOT VALID, NO INHERIT support */
    4391          30 :                     processCASbits($3, @3, "NOT NULL",
    4392             :                                    NULL, NULL, NULL,
    4393             :                                    NULL, NULL, yyscanner);
    4394          30 :                     n->initially_valid = true;
    4395          30 :                     $$ = (Node *) n;
    4396             :                 }
    4397             :         ;
    4398             : 
    4399         132 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4400        7460 :             | /* EMPTY */                           {  $$ = false; }
    4401             :         ;
    4402             : 
    4403             : opt_without_overlaps:
    4404         554 :             WITHOUT OVERLAPS                        { $$ = true; }
    4405        2156 :             | /*EMPTY*/                             { $$ = false; }
    4406             :     ;
    4407             : 
    4408             : opt_column_list:
    4409        9720 :             '(' columnList ')'                      { $$ = $2; }
    4410       38812 :             | /*EMPTY*/                             { $$ = NIL; }
    4411             :         ;
    4412             : 
    4413             : columnList:
    4414       15902 :             columnElem                              { $$ = list_make1($1); }
    4415       27646 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4416             :         ;
    4417             : 
    4418             : optionalPeriodName:
    4419         460 :             ',' PERIOD columnElem { $$ = $3; }
    4420        2448 :             | /*EMPTY*/               { $$ = NULL; }
    4421             :     ;
    4422             : 
    4423             : opt_column_and_period_list:
    4424        1124 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4425         660 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4426             :         ;
    4427             : 
    4428             : columnElem: ColId
    4429             :                 {
    4430       44008 :                     $$ = (Node *) makeString($1);
    4431             :                 }
    4432             :         ;
    4433             : 
    4434         168 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4435        2776 :              |      /* EMPTY */                     { $$ = NIL; }
    4436             :         ;
    4437             : 
    4438             : key_match:  MATCH FULL
    4439             :             {
    4440          98 :                 $$ = FKCONSTR_MATCH_FULL;
    4441             :             }
    4442             :         | MATCH PARTIAL
    4443             :             {
    4444           0 :                 ereport(ERROR,
    4445             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4446             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4447             :                          parser_errposition(@1)));
    4448             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4449             :             }
    4450             :         | MATCH SIMPLE
    4451             :             {
    4452           6 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4453             :             }
    4454             :         | /*EMPTY*/
    4455             :             {
    4456        2502 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4457             :             }
    4458             :         ;
    4459             : 
    4460             : ExclusionConstraintList:
    4461         234 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4462             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4463         106 :                                                     { $$ = lappend($1, $3); }
    4464             :         ;
    4465             : 
    4466             : ExclusionConstraintElem: index_elem WITH any_operator
    4467             :             {
    4468         340 :                 $$ = list_make2($1, $3);
    4469             :             }
    4470             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4471             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4472             :             {
    4473           0 :                 $$ = list_make2($1, $5);
    4474             :             }
    4475             :         ;
    4476             : 
    4477             : OptWhereClause:
    4478         440 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4479        1232 :             | /*EMPTY*/                             { $$ = NULL; }
    4480             :         ;
    4481             : 
    4482             : key_actions:
    4483             :             key_update
    4484             :                 {
    4485          74 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4486             : 
    4487          74 :                     n->updateAction = $1;
    4488          74 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4489          74 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4490          74 :                     n->deleteAction->cols = NIL;
    4491          74 :                     $$ = n;
    4492             :                 }
    4493             :             | key_delete
    4494             :                 {
    4495         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4496             : 
    4497         150 :                     n->updateAction = palloc(sizeof(KeyAction));
    4498         150 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4499         150 :                     n->updateAction->cols = NIL;
    4500         150 :                     n->deleteAction = $1;
    4501         150 :                     $$ = n;
    4502             :                 }
    4503             :             | key_update key_delete
    4504             :                 {
    4505         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4506             : 
    4507         150 :                     n->updateAction = $1;
    4508         150 :                     n->deleteAction = $2;
    4509         150 :                     $$ = n;
    4510             :                 }
    4511             :             | key_delete key_update
    4512             :                 {
    4513         150 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4514             : 
    4515         150 :                     n->updateAction = $2;
    4516         150 :                     n->deleteAction = $1;
    4517         150 :                     $$ = n;
    4518             :                 }
    4519             :             | /*EMPTY*/
    4520             :                 {
    4521        2076 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4522             : 
    4523        2076 :                     n->updateAction = palloc(sizeof(KeyAction));
    4524        2076 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4525        2076 :                     n->updateAction->cols = NIL;
    4526        2076 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4527        2076 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4528        2076 :                     n->deleteAction->cols = NIL;
    4529        2076 :                     $$ = n;
    4530             :                 }
    4531             :         ;
    4532             : 
    4533             : key_update: ON UPDATE key_action
    4534             :                 {
    4535         380 :                     if (($3)->cols)
    4536           6 :                         ereport(ERROR,
    4537             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4538             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4539             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4540             :                                  parser_errposition(@1)));
    4541         374 :                     $$ = $3;
    4542             :                 }
    4543             :         ;
    4544             : 
    4545             : key_delete: ON DELETE_P key_action
    4546             :                 {
    4547         450 :                     $$ = $3;
    4548             :                 }
    4549             :         ;
    4550             : 
    4551             : key_action:
    4552             :             NO ACTION
    4553             :                 {
    4554          80 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4555             : 
    4556          80 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4557          80 :                     n->cols = NIL;
    4558          80 :                     $$ = n;
    4559             :                 }
    4560             :             | RESTRICT
    4561             :                 {
    4562          48 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4563             : 
    4564          48 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4565          48 :                     n->cols = NIL;
    4566          48 :                     $$ = n;
    4567             :                 }
    4568             :             | CASCADE
    4569             :                 {
    4570         410 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4571             : 
    4572         410 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4573         410 :                     n->cols = NIL;
    4574         410 :                     $$ = n;
    4575             :                 }
    4576             :             | SET NULL_P opt_column_list
    4577             :                 {
    4578         190 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4579             : 
    4580         190 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4581         190 :                     n->cols = $3;
    4582         190 :                     $$ = n;
    4583             :                 }
    4584             :             | SET DEFAULT opt_column_list
    4585             :                 {
    4586         102 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4587             : 
    4588         102 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4589         102 :                     n->cols = $3;
    4590         102 :                     $$ = n;
    4591             :                 }
    4592             :         ;
    4593             : 
    4594        2018 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4595       27250 :             | /*EMPTY*/                             { $$ = NIL; }
    4596             :         ;
    4597             : 
    4598             : /* Optional partition key specification */
    4599        4922 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4600       31914 :             | /*EMPTY*/         { $$ = NULL; }
    4601             :         ;
    4602             : 
    4603             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4604             :                 {
    4605        4928 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4606             : 
    4607        4928 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4608        4922 :                     n->partParams = $5;
    4609        4922 :                     n->location = @1;
    4610             : 
    4611        4922 :                     $$ = n;
    4612             :                 }
    4613             :         ;
    4614             : 
    4615        4928 : part_params:    part_elem                       { $$ = list_make1($1); }
    4616         456 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4617             :         ;
    4618             : 
    4619             : part_elem: ColId opt_collate opt_qualified_name
    4620             :                 {
    4621        5080 :                     PartitionElem *n = makeNode(PartitionElem);
    4622             : 
    4623        5080 :                     n->name = $1;
    4624        5080 :                     n->expr = NULL;
    4625        5080 :                     n->collation = $2;
    4626        5080 :                     n->opclass = $3;
    4627        5080 :                     n->location = @1;
    4628        5080 :                     $$ = n;
    4629             :                 }
    4630             :             | func_expr_windowless opt_collate opt_qualified_name
    4631             :                 {
    4632         130 :                     PartitionElem *n = makeNode(PartitionElem);
    4633             : 
    4634         130 :                     n->name = NULL;
    4635         130 :                     n->expr = $1;
    4636         130 :                     n->collation = $2;
    4637         130 :                     n->opclass = $3;
    4638         130 :                     n->location = @1;
    4639         130 :                     $$ = n;
    4640             :                 }
    4641             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4642             :                 {
    4643         174 :                     PartitionElem *n = makeNode(PartitionElem);
    4644             : 
    4645         174 :                     n->name = NULL;
    4646         174 :                     n->expr = $2;
    4647         174 :                     n->collation = $4;
    4648         174 :                     n->opclass = $5;
    4649         174 :                     n->location = @1;
    4650         174 :                     $$ = n;
    4651             :                 }
    4652             :         ;
    4653             : 
    4654             : table_access_method_clause:
    4655         122 :             USING name                          { $$ = $2; }
    4656       38616 :             | /*EMPTY*/                         { $$ = NULL; }
    4657             :         ;
    4658             : 
    4659             : /* WITHOUT OIDS is legacy only */
    4660             : OptWith:
    4661         688 :             WITH reloptions             { $$ = $2; }
    4662          24 :             | WITHOUT OIDS              { $$ = NIL; }
    4663       37444 :             | /*EMPTY*/                 { $$ = NIL; }
    4664             :         ;
    4665             : 
    4666          60 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4667          98 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4668          24 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4669       37974 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4670             :         ;
    4671             : 
    4672         206 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4673       45170 :             | /*EMPTY*/                             { $$ = NULL; }
    4674             :         ;
    4675             : 
    4676          66 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4677        9064 :             | /*EMPTY*/                             { $$ = NULL; }
    4678             :         ;
    4679             : 
    4680        9566 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4681             :         ;
    4682             : 
    4683             : /*****************************************************************************
    4684             :  *
    4685             :  *      QUERY :
    4686             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4687             :  *                  ON expression-list FROM from_list
    4688             :  *
    4689             :  * Note: the expectation here is that the clauses after ON are a subset of
    4690             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4691             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4692             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4693             :  * errors as necessary at execution.
    4694             :  *
    4695             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4696             :  *
    4697             :  *****************************************************************************/
    4698             : 
    4699             : CreateStatsStmt:
    4700             :             CREATE STATISTICS opt_qualified_name
    4701             :             opt_name_list ON stats_params FROM from_list
    4702             :                 {
    4703         652 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4704             : 
    4705         652 :                     n->defnames = $3;
    4706         652 :                     n->stat_types = $4;
    4707         652 :                     n->exprs = $6;
    4708         652 :                     n->relations = $8;
    4709         652 :                     n->stxcomment = NULL;
    4710         652 :                     n->if_not_exists = false;
    4711         652 :                     $$ = (Node *) n;
    4712             :                 }
    4713             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4714             :             opt_name_list ON stats_params FROM from_list
    4715             :                 {
    4716          12 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4717             : 
    4718          12 :                     n->defnames = $6;
    4719          12 :                     n->stat_types = $7;
    4720          12 :                     n->exprs = $9;
    4721          12 :                     n->relations = $11;
    4722          12 :                     n->stxcomment = NULL;
    4723          12 :                     n->if_not_exists = true;
    4724          12 :                     $$ = (Node *) n;
    4725             :                 }
    4726             :             ;
    4727             : 
    4728             : /*
    4729             :  * Statistics attributes can be either simple column references, or arbitrary
    4730             :  * expressions in parens.  For compatibility with index attributes permitted
    4731             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4732             :  * written without parens.
    4733             :  */
    4734             : 
    4735         676 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4736         972 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4737             :         ;
    4738             : 
    4739             : stats_param:    ColId
    4740             :                 {
    4741        1174 :                     $$ = makeNode(StatsElem);
    4742        1174 :                     $$->name = $1;
    4743        1174 :                     $$->expr = NULL;
    4744             :                 }
    4745             :             | func_expr_windowless
    4746             :                 {
    4747          32 :                     $$ = makeNode(StatsElem);
    4748          32 :                     $$->name = NULL;
    4749          32 :                     $$->expr = $1;
    4750             :                 }
    4751             :             | '(' a_expr ')'
    4752             :                 {
    4753         442 :                     $$ = makeNode(StatsElem);
    4754         442 :                     $$->name = NULL;
    4755         442 :                     $$->expr = $2;
    4756             :                 }
    4757             :         ;
    4758             : 
    4759             : /*****************************************************************************
    4760             :  *
    4761             :  *      QUERY :
    4762             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4763             :  *                  SET STATISTICS  <SignedIconst>
    4764             :  *
    4765             :  *****************************************************************************/
    4766             : 
    4767             : AlterStatsStmt:
    4768             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4769             :                 {
    4770          20 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4771             : 
    4772          20 :                     n->defnames = $3;
    4773          20 :                     n->missing_ok = false;
    4774          20 :                     n->stxstattarget = $6;
    4775          20 :                     $$ = (Node *) n;
    4776             :                 }
    4777             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4778             :                 {
    4779           6 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4780             : 
    4781           6 :                     n->defnames = $5;
    4782           6 :                     n->missing_ok = true;
    4783           6 :                     n->stxstattarget = $8;
    4784           6 :                     $$ = (Node *) n;
    4785             :                 }
    4786             :             ;
    4787             : 
    4788             : /*****************************************************************************
    4789             :  *
    4790             :  *      QUERY :
    4791             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4792             :  *
    4793             :  *
    4794             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4795             :  *
    4796             :  *****************************************************************************/
    4797             : 
    4798             : CreateAsStmt:
    4799             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4800             :                 {
    4801        1192 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4802             : 
    4803        1192 :                     ctas->query = $6;
    4804        1192 :                     ctas->into = $4;
    4805        1192 :                     ctas->objtype = OBJECT_TABLE;
    4806        1192 :                     ctas->is_select_into = false;
    4807        1192 :                     ctas->if_not_exists = false;
    4808             :                     /* cram additional flags into the IntoClause */
    4809        1192 :                     $4->rel->relpersistence = $2;
    4810        1192 :                     $4->skipData = !($7);
    4811        1192 :                     $$ = (Node *) ctas;
    4812             :                 }
    4813             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4814             :                 {
    4815          52 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4816             : 
    4817          52 :                     ctas->query = $9;
    4818          52 :                     ctas->into = $7;
    4819          52 :                     ctas->objtype = OBJECT_TABLE;
    4820          52 :                     ctas->is_select_into = false;
    4821          52 :                     ctas->if_not_exists = true;
    4822             :                     /* cram additional flags into the IntoClause */
    4823          52 :                     $7->rel->relpersistence = $2;
    4824          52 :                     $7->skipData = !($10);
    4825          52 :                     $$ = (Node *) ctas;
    4826             :                 }
    4827             :         ;
    4828             : 
    4829             : create_as_target:
    4830             :             qualified_name opt_column_list table_access_method_clause
    4831             :             OptWith OnCommitOption OptTableSpace
    4832             :                 {
    4833        1332 :                     $$ = makeNode(IntoClause);
    4834        1332 :                     $$->rel = $1;
    4835        1332 :                     $$->colNames = $2;
    4836        1332 :                     $$->accessMethod = $3;
    4837        1332 :                     $$->options = $4;
    4838        1332 :                     $$->onCommit = $5;
    4839        1332 :                     $$->tableSpaceName = $6;
    4840        1332 :                     $$->viewQuery = NULL;
    4841        1332 :                     $$->skipData = false;        /* might get changed later */
    4842             :                 }
    4843             :         ;
    4844             : 
    4845             : opt_with_data:
    4846          36 :             WITH DATA_P                             { $$ = true; }
    4847         212 :             | WITH NO DATA_P                        { $$ = false; }
    4848        1922 :             | /*EMPTY*/                             { $$ = true; }
    4849             :         ;
    4850             : 
    4851             : 
    4852             : /*****************************************************************************
    4853             :  *
    4854             :  *      QUERY :
    4855             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4856             :  *
    4857             :  *****************************************************************************/
    4858             : 
    4859             : CreateMatViewStmt:
    4860             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4861             :                 {
    4862         528 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4863             : 
    4864         528 :                     ctas->query = $7;
    4865         528 :                     ctas->into = $5;
    4866         528 :                     ctas->objtype = OBJECT_MATVIEW;
    4867         528 :                     ctas->is_select_into = false;
    4868         528 :                     ctas->if_not_exists = false;
    4869             :                     /* cram additional flags into the IntoClause */
    4870         528 :                     $5->rel->relpersistence = $2;
    4871         528 :                     $5->skipData = !($8);
    4872         528 :                     $$ = (Node *) ctas;
    4873             :                 }
    4874             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4875             :                 {
    4876          48 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4877             : 
    4878          48 :                     ctas->query = $10;
    4879          48 :                     ctas->into = $8;
    4880          48 :                     ctas->objtype = OBJECT_MATVIEW;
    4881          48 :                     ctas->is_select_into = false;
    4882          48 :                     ctas->if_not_exists = true;
    4883             :                     /* cram additional flags into the IntoClause */
    4884          48 :                     $8->rel->relpersistence = $2;
    4885          48 :                     $8->skipData = !($11);
    4886          48 :                     $$ = (Node *) ctas;
    4887             :                 }
    4888             :         ;
    4889             : 
    4890             : create_mv_target:
    4891             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4892             :                 {
    4893         576 :                     $$ = makeNode(IntoClause);
    4894         576 :                     $$->rel = $1;
    4895         576 :                     $$->colNames = $2;
    4896         576 :                     $$->accessMethod = $3;
    4897         576 :                     $$->options = $4;
    4898         576 :                     $$->onCommit = ONCOMMIT_NOOP;
    4899         576 :                     $$->tableSpaceName = $5;
    4900         576 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4901         576 :                     $$->skipData = false;        /* might get changed later */
    4902             :                 }
    4903             :         ;
    4904             : 
    4905           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4906         576 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4907             :         ;
    4908             : 
    4909             : 
    4910             : /*****************************************************************************
    4911             :  *
    4912             :  *      QUERY :
    4913             :  *              REFRESH MATERIALIZED VIEW qualified_name
    4914             :  *
    4915             :  *****************************************************************************/
    4916             : 
    4917             : RefreshMatViewStmt:
    4918             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4919             :                 {
    4920         262 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4921             : 
    4922         262 :                     n->concurrent = $4;
    4923         262 :                     n->relation = $5;
    4924         262 :                     n->skipData = !($6);
    4925         262 :                     $$ = (Node *) n;
    4926             :                 }
    4927             :         ;
    4928             : 
    4929             : 
    4930             : /*****************************************************************************
    4931             :  *
    4932             :  *      QUERY :
    4933             :  *              CREATE SEQUENCE seqname
    4934             :  *              ALTER SEQUENCE seqname
    4935             :  *
    4936             :  *****************************************************************************/
    4937             : 
    4938             : CreateSeqStmt:
    4939             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4940             :                 {
    4941         660 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4942             : 
    4943         660 :                     $4->relpersistence = $2;
    4944         660 :                     n->sequence = $4;
    4945         660 :                     n->options = $5;
    4946         660 :                     n->ownerId = InvalidOid;
    4947         660 :                     n->if_not_exists = false;
    4948         660 :                     $$ = (Node *) n;
    4949             :                 }
    4950             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4951             :                 {
    4952          24 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4953             : 
    4954          24 :                     $7->relpersistence = $2;
    4955          24 :                     n->sequence = $7;
    4956          24 :                     n->options = $8;
    4957          24 :                     n->ownerId = InvalidOid;
    4958          24 :                     n->if_not_exists = true;
    4959          24 :                     $$ = (Node *) n;
    4960             :                 }
    4961             :         ;
    4962             : 
    4963             : AlterSeqStmt:
    4964             :             ALTER SEQUENCE qualified_name SeqOptList
    4965             :                 {
    4966         184 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4967             : 
    4968         184 :                     n->sequence = $3;
    4969         184 :                     n->options = $4;
    4970         184 :                     n->missing_ok = false;
    4971         184 :                     $$ = (Node *) n;
    4972             :                 }
    4973             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    4974             :                 {
    4975          12 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4976             : 
    4977          12 :                     n->sequence = $5;
    4978          12 :                     n->options = $6;
    4979          12 :                     n->missing_ok = true;
    4980          12 :                     $$ = (Node *) n;
    4981             :                 }
    4982             : 
    4983             :         ;
    4984             : 
    4985         266 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    4986         418 :             | /*EMPTY*/                             { $$ = NIL; }
    4987             :         ;
    4988             : 
    4989          74 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    4990         424 :             | /*EMPTY*/                             { $$ = NIL; }
    4991             :         ;
    4992             : 
    4993         536 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    4994         810 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    4995             :         ;
    4996             : 
    4997             : SeqOptElem: AS SimpleTypename
    4998             :                 {
    4999         190 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    5000             :                 }
    5001             :             | CACHE NumericOnly
    5002             :                 {
    5003         130 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    5004             :                 }
    5005             :             | CYCLE
    5006             :                 {
    5007          34 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    5008             :                 }
    5009             :             | NO CYCLE
    5010             :                 {
    5011          14 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    5012             :                 }
    5013             :             | INCREMENT opt_by NumericOnly
    5014             :                 {
    5015         250 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    5016             :                 }
    5017             :             | LOGGED
    5018             :                 {
    5019           2 :                     $$ = makeDefElem("logged", NULL, @1);
    5020             :                 }
    5021             :             | MAXVALUE NumericOnly
    5022             :                 {
    5023          68 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5024             :                 }
    5025             :             | MINVALUE NumericOnly
    5026             :                 {
    5027          72 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5028             :                 }
    5029             :             | NO MAXVALUE
    5030             :                 {
    5031         108 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5032             :                 }
    5033             :             | NO MINVALUE
    5034             :                 {
    5035         108 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5036             :                 }
    5037             :             | OWNED BY any_name
    5038             :                 {
    5039          72 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5040             :                 }
    5041             :             | SEQUENCE NAME_P any_name
    5042             :                 {
    5043          44 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5044             :                 }
    5045             :             | START opt_with NumericOnly
    5046             :                 {
    5047         240 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5048             :                 }
    5049             :             | RESTART
    5050             :                 {
    5051           6 :                     $$ = makeDefElem("restart", NULL, @1);
    5052             :                 }
    5053             :             | RESTART opt_with NumericOnly
    5054             :                 {
    5055          60 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5056             :                 }
    5057             :             | UNLOGGED
    5058             :                 {
    5059           2 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5060             :                 }
    5061             :         ;
    5062             : 
    5063             : opt_by:     BY
    5064             :             | /* EMPTY */
    5065             :       ;
    5066             : 
    5067             : NumericOnly:
    5068         318 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5069           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5070             :             | '-' FCONST
    5071             :                 {
    5072          20 :                     Float      *f = makeFloat($2);
    5073             : 
    5074          20 :                     doNegateFloat(f);
    5075          20 :                     $$ = (Node *) f;
    5076             :                 }
    5077       12060 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5078             :         ;
    5079             : 
    5080          80 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5081           6 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5082             :         ;
    5083             : 
    5084             : /*****************************************************************************
    5085             :  *
    5086             :  *      QUERIES :
    5087             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5088             :  *              DROP [PROCEDURAL] LANGUAGE ...
    5089             :  *
    5090             :  *****************************************************************************/
    5091             : 
    5092             : CreatePLangStmt:
    5093             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5094             :             {
    5095             :                 /*
    5096             :                  * We now interpret parameterless CREATE LANGUAGE as
    5097             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5098             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5099             :                  * seems more useful than throwing an error.  We just
    5100             :                  * ignore TRUSTED, as the previous code would have too.
    5101             :                  */
    5102           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5103             : 
    5104           0 :                 n->if_not_exists = $2;
    5105           0 :                 n->extname = $6;
    5106           0 :                 n->options = NIL;
    5107           0 :                 $$ = (Node *) n;
    5108             :             }
    5109             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5110             :               HANDLER handler_name opt_inline_handler opt_validator
    5111             :             {
    5112         132 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5113             : 
    5114         132 :                 n->replace = $2;
    5115         132 :                 n->plname = $6;
    5116         132 :                 n->plhandler = $8;
    5117         132 :                 n->plinline = $9;
    5118         132 :                 n->plvalidator = $10;
    5119         132 :                 n->pltrusted = $3;
    5120         132 :                 $$ = (Node *) n;
    5121             :             }
    5122             :         ;
    5123             : 
    5124             : opt_trusted:
    5125         102 :             TRUSTED                                 { $$ = true; }
    5126          38 :             | /*EMPTY*/                             { $$ = false; }
    5127             :         ;
    5128             : 
    5129             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5130             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5131             :  * Work around by using simple names, instead.
    5132             :  */
    5133             : handler_name:
    5134         524 :             name                        { $$ = list_make1(makeString($1)); }
    5135           2 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5136             :         ;
    5137             : 
    5138             : opt_inline_handler:
    5139         114 :             INLINE_P handler_name                   { $$ = $2; }
    5140          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5141             :         ;
    5142             : 
    5143             : validator_clause:
    5144         114 :             VALIDATOR handler_name                  { $$ = $2; }
    5145           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5146             :         ;
    5147             : 
    5148             : opt_validator:
    5149         114 :             validator_clause                        { $$ = $1; }
    5150          18 :             | /*EMPTY*/                             { $$ = NIL; }
    5151             :         ;
    5152             : 
    5153             : opt_procedural:
    5154             :             PROCEDURAL
    5155             :             | /*EMPTY*/
    5156             :         ;
    5157             : 
    5158             : /*****************************************************************************
    5159             :  *
    5160             :  *      QUERY:
    5161             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5162             :  *
    5163             :  *****************************************************************************/
    5164             : 
    5165             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5166             :                 {
    5167         112 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5168             : 
    5169         112 :                     n->tablespacename = $3;
    5170         112 :                     n->owner = $4;
    5171         112 :                     n->location = $6;
    5172         112 :                     n->options = $7;
    5173         112 :                     $$ = (Node *) n;
    5174             :                 }
    5175             :         ;
    5176             : 
    5177           2 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5178         110 :             | /*EMPTY */                { $$ = NULL; }
    5179             :         ;
    5180             : 
    5181             : /*****************************************************************************
    5182             :  *
    5183             :  *      QUERY :
    5184             :  *              DROP TABLESPACE <tablespace>
    5185             :  *
    5186             :  *      No need for drop behaviour as we cannot implement dependencies for
    5187             :  *      objects in other databases; we can only support RESTRICT.
    5188             :  *
    5189             :  ****************************************************************************/
    5190             : 
    5191             : DropTableSpaceStmt: DROP TABLESPACE name
    5192             :                 {
    5193          64 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5194             : 
    5195          64 :                     n->tablespacename = $3;
    5196          64 :                     n->missing_ok = false;
    5197          64 :                     $$ = (Node *) n;
    5198             :                 }
    5199             :                 |  DROP TABLESPACE IF_P EXISTS name
    5200             :                 {
    5201           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5202             : 
    5203           0 :                     n->tablespacename = $5;
    5204           0 :                     n->missing_ok = true;
    5205           0 :                     $$ = (Node *) n;
    5206             :                 }
    5207             :         ;
    5208             : 
    5209             : /*****************************************************************************
    5210             :  *
    5211             :  *      QUERY:
    5212             :  *             CREATE EXTENSION extension
    5213             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5214             :  *
    5215             :  *****************************************************************************/
    5216             : 
    5217             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5218             :                 {
    5219         480 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5220             : 
    5221         480 :                     n->extname = $3;
    5222         480 :                     n->if_not_exists = false;
    5223         480 :                     n->options = $5;
    5224         480 :                     $$ = (Node *) n;
    5225             :                 }
    5226             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5227             :                 {
    5228          18 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5229             : 
    5230          18 :                     n->extname = $6;
    5231          18 :                     n->if_not_exists = true;
    5232          18 :                     n->options = $8;
    5233          18 :                     $$ = (Node *) n;
    5234             :                 }
    5235             :         ;
    5236             : 
    5237             : create_extension_opt_list:
    5238             :             create_extension_opt_list create_extension_opt_item
    5239          98 :                 { $$ = lappend($1, $2); }
    5240             :             | /* EMPTY */
    5241         498 :                 { $$ = NIL; }
    5242             :         ;
    5243             : 
    5244             : create_extension_opt_item:
    5245             :             SCHEMA name
    5246             :                 {
    5247          46 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5248             :                 }
    5249             :             | VERSION_P NonReservedWord_or_Sconst
    5250             :                 {
    5251          12 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5252             :                 }
    5253             :             | FROM NonReservedWord_or_Sconst
    5254             :                 {
    5255           0 :                     ereport(ERROR,
    5256             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5257             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5258             :                              parser_errposition(@1)));
    5259             :                 }
    5260             :             | CASCADE
    5261             :                 {
    5262          40 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5263             :                 }
    5264             :         ;
    5265             : 
    5266             : /*****************************************************************************
    5267             :  *
    5268             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5269             :  *
    5270             :  *****************************************************************************/
    5271             : 
    5272             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5273             :                 {
    5274          38 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5275             : 
    5276          38 :                     n->extname = $3;
    5277          38 :                     n->options = $5;
    5278          38 :                     $$ = (Node *) n;
    5279             :                 }
    5280             :         ;
    5281             : 
    5282             : alter_extension_opt_list:
    5283             :             alter_extension_opt_list alter_extension_opt_item
    5284          38 :                 { $$ = lappend($1, $2); }
    5285             :             | /* EMPTY */
    5286          38 :                 { $$ = NIL; }
    5287             :         ;
    5288             : 
    5289             : alter_extension_opt_item:
    5290             :             TO NonReservedWord_or_Sconst
    5291             :                 {
    5292          38 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5293             :                 }
    5294             :         ;
    5295             : 
    5296             : /*****************************************************************************
    5297             :  *
    5298             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5299             :  *
    5300             :  *****************************************************************************/
    5301             : 
    5302             : AlterExtensionContentsStmt:
    5303             :             ALTER EXTENSION name add_drop object_type_name name
    5304             :                 {
    5305          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5306             : 
    5307          18 :                     n->extname = $3;
    5308          18 :                     n->action = $4;
    5309          18 :                     n->objtype = $5;
    5310          18 :                     n->object = (Node *) makeString($6);
    5311          18 :                     $$ = (Node *) n;
    5312             :                 }
    5313             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5314             :                 {
    5315          76 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5316             : 
    5317          76 :                     n->extname = $3;
    5318          76 :                     n->action = $4;
    5319          76 :                     n->objtype = $5;
    5320          76 :                     n->object = (Node *) $6;
    5321          76 :                     $$ = (Node *) n;
    5322             :                 }
    5323             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5324             :                 {
    5325           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5326             : 
    5327           8 :                     n->extname = $3;
    5328           8 :                     n->action = $4;
    5329           8 :                     n->objtype = OBJECT_AGGREGATE;
    5330           8 :                     n->object = (Node *) $6;
    5331           8 :                     $$ = (Node *) n;
    5332             :                 }
    5333             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5334             :                 {
    5335           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5336             : 
    5337           4 :                     n->extname = $3;
    5338           4 :                     n->action = $4;
    5339           4 :                     n->objtype = OBJECT_CAST;
    5340           4 :                     n->object = (Node *) list_make2($7, $9);
    5341           4 :                     $$ = (Node *) n;
    5342             :                 }
    5343             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5344             :                 {
    5345           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5346             : 
    5347           0 :                     n->extname = $3;
    5348           0 :                     n->action = $4;
    5349           0 :                     n->objtype = OBJECT_DOMAIN;
    5350           0 :                     n->object = (Node *) $6;
    5351           0 :                     $$ = (Node *) n;
    5352             :                 }
    5353             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5354             :                 {
    5355          98 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5356             : 
    5357          98 :                     n->extname = $3;
    5358          98 :                     n->action = $4;
    5359          98 :                     n->objtype = OBJECT_FUNCTION;
    5360          98 :                     n->object = (Node *) $6;
    5361          98 :                     $$ = (Node *) n;
    5362             :                 }
    5363             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5364             :                 {
    5365          18 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5366             : 
    5367          18 :                     n->extname = $3;
    5368          18 :                     n->action = $4;
    5369          18 :                     n->objtype = OBJECT_OPERATOR;
    5370          18 :                     n->object = (Node *) $6;
    5371          18 :                     $$ = (Node *) n;
    5372             :                 }
    5373             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5374             :                 {
    5375           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5376             : 
    5377           4 :                     n->extname = $3;
    5378           4 :                     n->action = $4;
    5379           4 :                     n->objtype = OBJECT_OPCLASS;
    5380           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5381           4 :                     $$ = (Node *) n;
    5382             :                 }
    5383             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5384             :                 {
    5385           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5386             : 
    5387           4 :                     n->extname = $3;
    5388           4 :                     n->action = $4;
    5389           4 :                     n->objtype = OBJECT_OPFAMILY;
    5390           4 :                     n->object = (Node *) lcons(makeString($9), $7);
    5391           4 :                     $$ = (Node *) n;
    5392             :                 }
    5393             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5394             :                 {
    5395           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5396             : 
    5397           0 :                     n->extname = $3;
    5398           0 :                     n->action = $4;
    5399           0 :                     n->objtype = OBJECT_PROCEDURE;
    5400           0 :                     n->object = (Node *) $6;
    5401           0 :                     $$ = (Node *) n;
    5402             :                 }
    5403             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5404             :                 {
    5405           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5406             : 
    5407           0 :                     n->extname = $3;
    5408           0 :                     n->action = $4;
    5409           0 :                     n->objtype = OBJECT_ROUTINE;
    5410           0 :                     n->object = (Node *) $6;
    5411           0 :                     $$ = (Node *) n;
    5412             :                 }
    5413             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5414             :                 {
    5415           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5416             : 
    5417           4 :                     n->extname = $3;
    5418           4 :                     n->action = $4;
    5419           4 :                     n->objtype = OBJECT_TRANSFORM;
    5420           4 :                     n->object = (Node *) list_make2($7, makeString($9));
    5421           4 :                     $$ = (Node *) n;
    5422             :                 }
    5423             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5424             :                 {
    5425           8 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5426             : 
    5427           8 :                     n->extname = $3;
    5428           8 :                     n->action = $4;
    5429           8 :                     n->objtype = OBJECT_TYPE;
    5430           8 :                     n->object = (Node *) $6;
    5431           8 :                     $$ = (Node *) n;
    5432             :                 }
    5433             :         ;
    5434             : 
    5435             : /*****************************************************************************
    5436             :  *
    5437             :  *      QUERY:
    5438             :  *             CREATE FOREIGN DATA WRAPPER name options
    5439             :  *
    5440             :  *****************************************************************************/
    5441             : 
    5442             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5443             :                 {
    5444         206 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5445             : 
    5446         206 :                     n->fdwname = $5;
    5447         206 :                     n->func_options = $6;
    5448         206 :                     n->options = $7;
    5449         206 :                     $$ = (Node *) n;
    5450             :                 }
    5451             :         ;
    5452             : 
    5453             : fdw_option:
    5454          56 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5455           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5456          48 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5457           6 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5458             :         ;
    5459             : 
    5460             : fdw_options:
    5461          90 :             fdw_option                          { $$ = list_make1($1); }
    5462          20 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5463             :         ;
    5464             : 
    5465             : opt_fdw_options:
    5466          54 :             fdw_options                         { $$ = $1; }
    5467         244 :             | /*EMPTY*/                         { $$ = NIL; }
    5468             :         ;
    5469             : 
    5470             : /*****************************************************************************
    5471             :  *
    5472             :  *      QUERY :
    5473             :  *              ALTER FOREIGN DATA WRAPPER name options
    5474             :  *
    5475             :  ****************************************************************************/
    5476             : 
    5477             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5478             :                 {
    5479          86 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5480             : 
    5481          86 :                     n->fdwname = $5;
    5482          86 :                     n->func_options = $6;
    5483          86 :                     n->options = $7;
    5484          86 :                     $$ = (Node *) n;
    5485             :                 }
    5486             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5487             :                 {
    5488          36 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5489             : 
    5490          36 :                     n->fdwname = $5;
    5491          36 :                     n->func_options = $6;
    5492          36 :                     n->options = NIL;
    5493          36 :                     $$ = (Node *) n;
    5494             :                 }
    5495             :         ;
    5496             : 
    5497             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5498             : create_generic_options:
    5499         734 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5500       66820 :             | /*EMPTY*/                                 { $$ = NIL; }
    5501             :         ;
    5502             : 
    5503             : generic_option_list:
    5504             :             generic_option_elem
    5505             :                 {
    5506         734 :                     $$ = list_make1($1);
    5507             :                 }
    5508             :             | generic_option_list ',' generic_option_elem
    5509             :                 {
    5510         480 :                     $$ = lappend($1, $3);
    5511             :                 }
    5512             :         ;
    5513             : 
    5514             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5515             : alter_generic_options:
    5516         488 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5517             :         ;
    5518             : 
    5519             : alter_generic_option_list:
    5520             :             alter_generic_option_elem
    5521             :                 {
    5522         488 :                     $$ = list_make1($1);
    5523             :                 }
    5524             :             | alter_generic_option_list ',' alter_generic_option_elem
    5525             :                 {
    5526         168 :                     $$ = lappend($1, $3);
    5527             :                 }
    5528             :         ;
    5529             : 
    5530             : alter_generic_option_elem:
    5531             :             generic_option_elem
    5532             :                 {
    5533         200 :                     $$ = $1;
    5534             :                 }
    5535             :             | SET generic_option_elem
    5536             :                 {
    5537         128 :                     $$ = $2;
    5538         128 :                     $$->defaction = DEFELEM_SET;
    5539             :                 }
    5540             :             | ADD_P generic_option_elem
    5541             :                 {
    5542         202 :                     $$ = $2;
    5543         202 :                     $$->defaction = DEFELEM_ADD;
    5544             :                 }
    5545             :             | DROP generic_option_name
    5546             :                 {
    5547         126 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5548             :                 }
    5549             :         ;
    5550             : 
    5551             : generic_option_elem:
    5552             :             generic_option_name generic_option_arg
    5553             :                 {
    5554        1744 :                     $$ = makeDefElem($1, $2, @1);
    5555             :                 }
    5556             :         ;
    5557             : 
    5558             : generic_option_name:
    5559        1870 :                 ColLabel            { $$ = $1; }
    5560             :         ;
    5561             : 
    5562             : /* We could use def_arg here, but the spec only requires string literals */
    5563             : generic_option_arg:
    5564        1744 :                 Sconst              { $$ = (Node *) makeString($1); }
    5565             :         ;
    5566             : 
    5567             : /*****************************************************************************
    5568             :  *
    5569             :  *      QUERY:
    5570             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5571             :  *
    5572             :  *****************************************************************************/
    5573             : 
    5574             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5575             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5576             :                 {
    5577         272 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5578             : 
    5579         272 :                     n->servername = $3;
    5580         272 :                     n->servertype = $4;
    5581         272 :                     n->version = $5;
    5582         272 :                     n->fdwname = $9;
    5583         272 :                     n->options = $10;
    5584         272 :                     n->if_not_exists = false;
    5585         272 :                     $$ = (Node *) n;
    5586             :                 }
    5587             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5588             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5589             :                 {
    5590          24 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5591             : 
    5592          24 :                     n->servername = $6;
    5593          24 :                     n->servertype = $7;
    5594          24 :                     n->version = $8;
    5595          24 :                     n->fdwname = $12;
    5596          24 :                     n->options = $13;
    5597          24 :                     n->if_not_exists = true;
    5598          24 :                     $$ = (Node *) n;
    5599             :                 }
    5600             :         ;
    5601             : 
    5602             : opt_type:
    5603          18 :             TYPE_P Sconst           { $$ = $2; }
    5604         278 :             | /*EMPTY*/             { $$ = NULL; }
    5605             :         ;
    5606             : 
    5607             : 
    5608             : foreign_server_version:
    5609          66 :             VERSION_P Sconst        { $$ = $2; }
    5610           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5611             :         ;
    5612             : 
    5613             : opt_foreign_server_version:
    5614          18 :             foreign_server_version  { $$ = $1; }
    5615         278 :             | /*EMPTY*/             { $$ = NULL; }
    5616             :         ;
    5617             : 
    5618             : /*****************************************************************************
    5619             :  *
    5620             :  *      QUERY :
    5621             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5622             :  *
    5623             :  ****************************************************************************/
    5624             : 
    5625             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5626             :                 {
    5627           6 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5628             : 
    5629           6 :                     n->servername = $3;
    5630           6 :                     n->version = $4;
    5631           6 :                     n->options = $5;
    5632           6 :                     n->has_version = true;
    5633           6 :                     $$ = (Node *) n;
    5634             :                 }
    5635             :             | ALTER SERVER name foreign_server_version
    5636             :                 {
    5637          42 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5638             : 
    5639          42 :                     n->servername = $3;
    5640          42 :                     n->version = $4;
    5641          42 :                     n->has_version = true;
    5642          42 :                     $$ = (Node *) n;
    5643             :                 }
    5644             :             | ALTER SERVER name alter_generic_options
    5645             :                 {
    5646         172 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5647             : 
    5648         172 :                     n->servername = $3;
    5649         172 :                     n->options = $4;
    5650         172 :                     $$ = (Node *) n;
    5651             :                 }
    5652             :         ;
    5653             : 
    5654             : /*****************************************************************************
    5655             :  *
    5656             :  *      QUERY:
    5657             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5658             :  *
    5659             :  *****************************************************************************/
    5660             : 
    5661             : CreateForeignTableStmt:
    5662             :         CREATE FOREIGN TABLE qualified_name
    5663             :             '(' OptTableElementList ')'
    5664             :             OptInherit SERVER name create_generic_options
    5665             :                 {
    5666         390 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5667             : 
    5668         390 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5669         390 :                     n->base.relation = $4;
    5670         390 :                     n->base.tableElts = $6;
    5671         390 :                     n->base.inhRelations = $8;
    5672         390 :                     n->base.ofTypename = NULL;
    5673         390 :                     n->base.constraints = NIL;
    5674         390 :                     n->base.options = NIL;
    5675         390 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5676         390 :                     n->base.tablespacename = NULL;
    5677         390 :                     n->base.if_not_exists = false;
    5678             :                     /* FDW-specific data */
    5679         390 :                     n->servername = $10;
    5680         390 :                     n->options = $11;
    5681         390 :                     $$ = (Node *) n;
    5682             :                 }
    5683             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5684             :             '(' OptTableElementList ')'
    5685             :             OptInherit SERVER name create_generic_options
    5686             :                 {
    5687           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5688             : 
    5689           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5690           0 :                     n->base.relation = $7;
    5691           0 :                     n->base.tableElts = $9;
    5692           0 :                     n->base.inhRelations = $11;
    5693           0 :                     n->base.ofTypename = NULL;
    5694           0 :                     n->base.constraints = NIL;
    5695           0 :                     n->base.options = NIL;
    5696           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5697           0 :                     n->base.tablespacename = NULL;
    5698           0 :                     n->base.if_not_exists = true;
    5699             :                     /* FDW-specific data */
    5700           0 :                     n->servername = $13;
    5701           0 :                     n->options = $14;
    5702           0 :                     $$ = (Node *) n;
    5703             :                 }
    5704             :         | CREATE FOREIGN TABLE qualified_name
    5705             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5706             :             SERVER name create_generic_options
    5707             :                 {
    5708          90 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5709             : 
    5710          90 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5711          90 :                     n->base.relation = $4;
    5712          90 :                     n->base.inhRelations = list_make1($7);
    5713          90 :                     n->base.tableElts = $8;
    5714          90 :                     n->base.partbound = $9;
    5715          90 :                     n->base.ofTypename = NULL;
    5716          90 :                     n->base.constraints = NIL;
    5717          90 :                     n->base.options = NIL;
    5718          90 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5719          90 :                     n->base.tablespacename = NULL;
    5720          90 :                     n->base.if_not_exists = false;
    5721             :                     /* FDW-specific data */
    5722          90 :                     n->servername = $11;
    5723          90 :                     n->options = $12;
    5724          90 :                     $$ = (Node *) n;
    5725             :                 }
    5726             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5727             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5728             :             SERVER name create_generic_options
    5729             :                 {
    5730           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5731             : 
    5732           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5733           0 :                     n->base.relation = $7;
    5734           0 :                     n->base.inhRelations = list_make1($10);
    5735           0 :                     n->base.tableElts = $11;
    5736           0 :                     n->base.partbound = $12;
    5737           0 :                     n->base.ofTypename = NULL;
    5738           0 :                     n->base.constraints = NIL;
    5739           0 :                     n->base.options = NIL;
    5740           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5741           0 :                     n->base.tablespacename = NULL;
    5742           0 :                     n->base.if_not_exists = true;
    5743             :                     /* FDW-specific data */
    5744           0 :                     n->servername = $14;
    5745           0 :                     n->options = $15;
    5746           0 :                     $$ = (Node *) n;
    5747             :                 }
    5748             :         ;
    5749             : 
    5750             : /*****************************************************************************
    5751             :  *
    5752             :  *      QUERY:
    5753             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5754             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5755             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5756             :  *
    5757             :  ****************************************************************************/
    5758             : 
    5759             : ImportForeignSchemaStmt:
    5760             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5761             :           FROM SERVER name INTO name create_generic_options
    5762             :             {
    5763          48 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5764             : 
    5765          48 :                 n->server_name = $8;
    5766          48 :                 n->remote_schema = $4;
    5767          48 :                 n->local_schema = $10;
    5768          48 :                 n->list_type = $5->type;
    5769          48 :                 n->table_list = $5->table_names;
    5770          48 :                 n->options = $11;
    5771          48 :                 $$ = (Node *) n;
    5772             :             }
    5773             :         ;
    5774             : 
    5775             : import_qualification_type:
    5776          14 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5777          14 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5778             :         ;
    5779             : 
    5780             : import_qualification:
    5781             :         import_qualification_type '(' relation_expr_list ')'
    5782             :             {
    5783          28 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5784             : 
    5785          28 :                 n->type = $1;
    5786          28 :                 n->table_names = $3;
    5787          28 :                 $$ = n;
    5788             :             }
    5789             :         | /*EMPTY*/
    5790             :             {
    5791          20 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5792          20 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5793          20 :                 n->table_names = NIL;
    5794          20 :                 $$ = n;
    5795             :             }
    5796             :         ;
    5797             : 
    5798             : /*****************************************************************************
    5799             :  *
    5800             :  *      QUERY:
    5801             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5802             :  *
    5803             :  *****************************************************************************/
    5804             : 
    5805             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5806             :                 {
    5807         246 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5808             : 
    5809         246 :                     n->user = $5;
    5810         246 :                     n->servername = $7;
    5811         246 :                     n->options = $8;
    5812         246 :                     n->if_not_exists = false;
    5813         246 :                     $$ = (Node *) n;
    5814             :                 }
    5815             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5816             :                 {
    5817           6 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5818             : 
    5819           6 :                     n->user = $8;
    5820           6 :                     n->servername = $10;
    5821           6 :                     n->options = $11;
    5822           6 :                     n->if_not_exists = true;
    5823           6 :                     $$ = (Node *) n;
    5824             :                 }
    5825             :         ;
    5826             : 
    5827             : /* User mapping authorization identifier */
    5828         442 : auth_ident: RoleSpec            { $$ = $1; }
    5829          46 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5830             :         ;
    5831             : 
    5832             : /*****************************************************************************
    5833             :  *
    5834             :  *      QUERY :
    5835             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5836             :  *
    5837             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5838             :  * only pro forma; but the SQL standard doesn't show one.
    5839             :  ****************************************************************************/
    5840             : 
    5841             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5842             :                 {
    5843          88 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5844             : 
    5845          88 :                     n->user = $5;
    5846          88 :                     n->servername = $7;
    5847          88 :                     n->missing_ok = false;
    5848          88 :                     $$ = (Node *) n;
    5849             :                 }
    5850             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5851             :                 {
    5852          38 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5853             : 
    5854          38 :                     n->user = $7;
    5855          38 :                     n->servername = $9;
    5856          38 :                     n->missing_ok = true;
    5857          38 :                     $$ = (Node *) n;
    5858             :                 }
    5859             :         ;
    5860             : 
    5861             : /*****************************************************************************
    5862             :  *
    5863             :  *      QUERY :
    5864             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5865             :  *
    5866             :  ****************************************************************************/
    5867             : 
    5868             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5869             :                 {
    5870         110 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5871             : 
    5872         110 :                     n->user = $5;
    5873         110 :                     n->servername = $7;
    5874         110 :                     n->options = $8;
    5875         110 :                     $$ = (Node *) n;
    5876             :                 }
    5877             :         ;
    5878             : 
    5879             : /*****************************************************************************
    5880             :  *
    5881             :  *      QUERIES:
    5882             :  *              CREATE POLICY name ON table
    5883             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5884             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5885             :  *                  [TO role, ...]
    5886             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5887             :  *              ALTER POLICY name ON table [TO role, ...]
    5888             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5889             :  *
    5890             :  *****************************************************************************/
    5891             : 
    5892             : CreatePolicyStmt:
    5893             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5894             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5895             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5896             :                 {
    5897         676 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5898             : 
    5899         676 :                     n->policy_name = $3;
    5900         676 :                     n->table = $5;
    5901         676 :                     n->permissive = $6;
    5902         676 :                     n->cmd_name = $7;
    5903         676 :                     n->roles = $8;
    5904         676 :                     n->qual = $9;
    5905         676 :                     n->with_check = $10;
    5906         676 :                     $$ = (Node *) n;
    5907             :                 }
    5908             :         ;
    5909             : 
    5910             : AlterPolicyStmt:
    5911             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5912             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5913             :                 {
    5914          84 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5915             : 
    5916          84 :                     n->policy_name = $3;
    5917          84 :                     n->table = $5;
    5918          84 :                     n->roles = $6;
    5919          84 :                     n->qual = $7;
    5920          84 :                     n->with_check = $8;
    5921          84 :                     $$ = (Node *) n;
    5922             :                 }
    5923             :         ;
    5924             : 
    5925             : RowSecurityOptionalExpr:
    5926         702 :             USING '(' a_expr ')'    { $$ = $3; }
    5927          58 :             | /* EMPTY */           { $$ = NULL; }
    5928             :         ;
    5929             : 
    5930             : RowSecurityOptionalWithCheck:
    5931         122 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5932         638 :             | /* EMPTY */                   { $$ = NULL; }
    5933             :         ;
    5934             : 
    5935             : RowSecurityDefaultToRole:
    5936         124 :             TO role_list            { $$ = $2; }
    5937         552 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5938             :         ;
    5939             : 
    5940             : RowSecurityOptionalToRole:
    5941          12 :             TO role_list            { $$ = $2; }
    5942          72 :             | /* EMPTY */           { $$ = NULL; }
    5943             :         ;
    5944             : 
    5945             : RowSecurityDefaultPermissive:
    5946             :             AS IDENT
    5947             :                 {
    5948          98 :                     if (strcmp($2, "permissive") == 0)
    5949          24 :                         $$ = true;
    5950          74 :                     else if (strcmp($2, "restrictive") == 0)
    5951          68 :                         $$ = false;
    5952             :                     else
    5953           6 :                         ereport(ERROR,
    5954             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5955             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    5956             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    5957             :                                  parser_errposition(@2)));
    5958             : 
    5959             :                 }
    5960         584 :             | /* EMPTY */           { $$ = true; }
    5961             :         ;
    5962             : 
    5963             : RowSecurityDefaultForCmd:
    5964         314 :             FOR row_security_cmd    { $$ = $2; }
    5965         362 :             | /* EMPTY */           { $$ = "all"; }
    5966             :         ;
    5967             : 
    5968             : row_security_cmd:
    5969          44 :             ALL             { $$ = "all"; }
    5970         106 :         |   SELECT          { $$ = "select"; }
    5971          44 :         |   INSERT          { $$ = "insert"; }
    5972          78 :         |   UPDATE          { $$ = "update"; }
    5973          42 :         |   DELETE_P        { $$ = "delete"; }
    5974             :         ;
    5975             : 
    5976             : /*****************************************************************************
    5977             :  *
    5978             :  *      QUERY:
    5979             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    5980             :  *
    5981             :  *****************************************************************************/
    5982             : 
    5983             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    5984             :                 {
    5985          62 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    5986             : 
    5987          62 :                     n->amname = $4;
    5988          62 :                     n->handler_name = $8;
    5989          62 :                     n->amtype = $6;
    5990          62 :                     $$ = (Node *) n;
    5991             :                 }
    5992             :         ;
    5993             : 
    5994             : am_type:
    5995          34 :             INDEX           { $$ = AMTYPE_INDEX; }
    5996          28 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    5997             :         ;
    5998             : 
    5999             : /*****************************************************************************
    6000             :  *
    6001             :  *      QUERIES :
    6002             :  *              CREATE TRIGGER ...
    6003             :  *
    6004             :  *****************************************************************************/
    6005             : 
    6006             : CreateTrigStmt:
    6007             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    6008             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    6009             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6010             :                 {
    6011        3162 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6012             : 
    6013        3162 :                     n->replace = $2;
    6014        3162 :                     n->isconstraint = false;
    6015        3162 :                     n->trigname = $4;
    6016        3162 :                     n->relation = $8;
    6017        3162 :                     n->funcname = $14;
    6018        3162 :                     n->args = $16;
    6019        3162 :                     n->row = $10;
    6020        3162 :                     n->timing = $5;
    6021        3162 :                     n->events = intVal(linitial($6));
    6022        3162 :                     n->columns = (List *) lsecond($6);
    6023        3162 :                     n->whenClause = $11;
    6024        3162 :                     n->transitionRels = $9;
    6025        3162 :                     n->deferrable = false;
    6026        3162 :                     n->initdeferred = false;
    6027        3162 :                     n->constrrel = NULL;
    6028        3162 :                     $$ = (Node *) n;
    6029             :                 }
    6030             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6031             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6032             :             FOR EACH ROW TriggerWhen
    6033             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6034             :                 {
    6035          62 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6036             : 
    6037          62 :                     n->replace = $2;
    6038          62 :                     if (n->replace) /* not supported, see CreateTrigger */
    6039           0 :                         ereport(ERROR,
    6040             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6041             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
    6042             :                                  parser_errposition(@1)));
    6043          62 :                     n->isconstraint = true;
    6044          62 :                     n->trigname = $5;
    6045          62 :                     n->relation = $9;
    6046          62 :                     n->funcname = $18;
    6047          62 :                     n->args = $20;
    6048          62 :                     n->row = true;
    6049          62 :                     n->timing = TRIGGER_TYPE_AFTER;
    6050          62 :                     n->events = intVal(linitial($7));
    6051          62 :                     n->columns = (List *) lsecond($7);
    6052          62 :                     n->whenClause = $15;
    6053          62 :                     n->transitionRels = NIL;
    6054          62 :                     processCASbits($11, @11, "TRIGGER",
    6055             :                                    &n->deferrable, &n->initdeferred, NULL,
    6056             :                                    NULL, NULL, yyscanner);
    6057          62 :                     n->constrrel = $10;
    6058          62 :                     $$ = (Node *) n;
    6059             :                 }
    6060             :         ;
    6061             : 
    6062             : TriggerActionTime:
    6063        1452 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6064        1578 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6065         144 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6066             :         ;
    6067             : 
    6068             : TriggerEvents:
    6069             :             TriggerOneEvent
    6070        3236 :                 { $$ = $1; }
    6071             :             | TriggerEvents OR TriggerOneEvent
    6072             :                 {
    6073        1160 :                     int         events1 = intVal(linitial($1));
    6074        1160 :                     int         events2 = intVal(linitial($3));
    6075        1160 :                     List       *columns1 = (List *) lsecond($1);
    6076        1160 :                     List       *columns2 = (List *) lsecond($3);
    6077             : 
    6078        1160 :                     if (events1 & events2)
    6079           6 :                         parser_yyerror("duplicate trigger events specified");
    6080             :                     /*
    6081             :                      * concat'ing the columns lists loses information about
    6082             :                      * which columns went with which event, but so long as
    6083             :                      * only UPDATE carries columns and we disallow multiple
    6084             :                      * UPDATE items, it doesn't matter.  Command execution
    6085             :                      * should just ignore the columns for non-UPDATE events.
    6086             :                      */
    6087        1154 :                     $$ = list_make2(makeInteger(events1 | events2),
    6088             :                                     list_concat(columns1, columns2));
    6089             :                 }
    6090             :         ;
    6091             : 
    6092             : TriggerOneEvent:
    6093             :             INSERT
    6094        1644 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6095             :             | DELETE_P
    6096         884 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6097             :             | UPDATE
    6098        1730 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6099             :             | UPDATE OF columnList
    6100         100 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6101             :             | TRUNCATE
    6102          38 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6103             :         ;
    6104             : 
    6105             : TriggerReferencing:
    6106         454 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6107        2708 :             | /*EMPTY*/                             { $$ = NIL; }
    6108             :         ;
    6109             : 
    6110             : TriggerTransitions:
    6111         454 :             TriggerTransition                       { $$ = list_make1($1); }
    6112         138 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6113             :         ;
    6114             : 
    6115             : TriggerTransition:
    6116             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6117             :                 {
    6118         592 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6119             : 
    6120         592 :                     n->name = $4;
    6121         592 :                     n->isNew = $1;
    6122         592 :                     n->isTable = $2;
    6123         592 :                     $$ = (Node *) n;
    6124             :                 }
    6125             :         ;
    6126             : 
    6127             : TransitionOldOrNew:
    6128         324 :             NEW                                     { $$ = true; }
    6129         268 :             | OLD                                   { $$ = false; }
    6130             :         ;
    6131             : 
    6132             : TransitionRowOrTable:
    6133         592 :             TABLE                                   { $$ = true; }
    6134             :             /*
    6135             :              * According to the standard, lack of a keyword here implies ROW.
    6136             :              * Support for that would require prohibiting ROW entirely here,
    6137             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6138             :              * allowing it to be optional, as the standard specifies) as the
    6139             :              * next token.  Requiring ROW seems cleanest and easiest to
    6140             :              * explain.
    6141             :              */
    6142           0 :             | ROW                                   { $$ = false; }
    6143             :         ;
    6144             : 
    6145             : TransitionRelName:
    6146         592 :             ColId                                   { $$ = $1; }
    6147             :         ;
    6148             : 
    6149             : TriggerForSpec:
    6150             :             FOR TriggerForOptEach TriggerForType
    6151             :                 {
    6152        2934 :                     $$ = $3;
    6153             :                 }
    6154             :             | /* EMPTY */
    6155             :                 {
    6156             :                     /*
    6157             :                      * If ROW/STATEMENT not specified, default to
    6158             :                      * STATEMENT, per SQL
    6159             :                      */
    6160         228 :                     $$ = false;
    6161             :                 }
    6162             :         ;
    6163             : 
    6164             : TriggerForOptEach:
    6165             :             EACH
    6166             :             | /*EMPTY*/
    6167             :         ;
    6168             : 
    6169             : TriggerForType:
    6170        2124 :             ROW                                     { $$ = true; }
    6171         810 :             | STATEMENT                             { $$ = false; }
    6172             :         ;
    6173             : 
    6174             : TriggerWhen:
    6175         190 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6176        3034 :             | /*EMPTY*/                             { $$ = NULL; }
    6177             :         ;
    6178             : 
    6179             : FUNCTION_or_PROCEDURE:
    6180             :             FUNCTION
    6181             :         |   PROCEDURE
    6182             :         ;
    6183             : 
    6184             : TriggerFuncArgs:
    6185         576 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6186         264 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6187        2648 :             | /*EMPTY*/                             { $$ = NIL; }
    6188             :         ;
    6189             : 
    6190             : TriggerFuncArg:
    6191             :             Iconst
    6192             :                 {
    6193         102 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6194             :                 }
    6195           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6196         696 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6197          42 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6198             :         ;
    6199             : 
    6200             : OptConstrFromTable:
    6201          12 :             FROM qualified_name                     { $$ = $2; }
    6202          50 :             | /*EMPTY*/                             { $$ = NULL; }
    6203             :         ;
    6204             : 
    6205             : ConstraintAttributeSpec:
    6206             :             /*EMPTY*/
    6207       16296 :                 { $$ = 0; }
    6208             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6209             :                 {
    6210             :                     /*
    6211             :                      * We must complain about conflicting options.
    6212             :                      * We could, but choose not to, complain about redundant
    6213             :                      * options (ie, where $2's bit is already set in $1).
    6214             :                      */
    6215        1300 :                     int     newspec = $1 | $2;
    6216             : 
    6217             :                     /* special message for this case */
    6218        1300 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6219           6 :                         ereport(ERROR,
    6220             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6221             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6222             :                                  parser_errposition(@2)));
    6223             :                     /* generic message for other conflicts */
    6224        1294 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6225        1294 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6226        1294 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6227           0 :                         ereport(ERROR,
    6228             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6229             :                                  errmsg("conflicting constraint properties"),
    6230             :                                  parser_errposition(@2)));
    6231        1294 :                     $$ = newspec;
    6232             :                 }
    6233             :         ;
    6234             : 
    6235             : ConstraintAttributeElem:
    6236          36 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6237         194 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6238          30 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6239         146 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6240         548 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6241         220 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6242          84 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6243          42 :             | ENFORCED                      { $$ = CAS_ENFORCED; }
    6244             :         ;
    6245             : 
    6246             : 
    6247             : /*****************************************************************************
    6248             :  *
    6249             :  *      QUERIES :
    6250             :  *              CREATE EVENT TRIGGER ...
    6251             :  *              ALTER EVENT TRIGGER ...
    6252             :  *
    6253             :  *****************************************************************************/
    6254             : 
    6255             : CreateEventTrigStmt:
    6256             :             CREATE EVENT TRIGGER name ON ColLabel
    6257             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6258             :                 {
    6259          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6260             : 
    6261          98 :                     n->trigname = $4;
    6262          98 :                     n->eventname = $6;
    6263          98 :                     n->whenclause = NULL;
    6264          98 :                     n->funcname = $9;
    6265          98 :                     $$ = (Node *) n;
    6266             :                 }
    6267             :           | CREATE EVENT TRIGGER name ON ColLabel
    6268             :             WHEN event_trigger_when_list
    6269             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6270             :                 {
    6271          98 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6272             : 
    6273          98 :                     n->trigname = $4;
    6274          98 :                     n->eventname = $6;
    6275          98 :                     n->whenclause = $8;
    6276          98 :                     n->funcname = $11;
    6277          98 :                     $$ = (Node *) n;
    6278             :                 }
    6279             :         ;
    6280             : 
    6281             : event_trigger_when_list:
    6282             :           event_trigger_when_item
    6283          98 :             { $$ = list_make1($1); }
    6284             :         | event_trigger_when_list AND event_trigger_when_item
    6285           6 :             { $$ = lappend($1, $3); }
    6286             :         ;
    6287             : 
    6288             : event_trigger_when_item:
    6289             :         ColId IN_P '(' event_trigger_value_list ')'
    6290         104 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6291             :         ;
    6292             : 
    6293             : event_trigger_value_list:
    6294             :           SCONST
    6295         104 :             { $$ = list_make1(makeString($1)); }
    6296             :         | event_trigger_value_list ',' SCONST
    6297          66 :             { $$ = lappend($1, makeString($3)); }
    6298             :         ;
    6299             : 
    6300             : AlterEventTrigStmt:
    6301             :             ALTER EVENT TRIGGER name enable_trigger
    6302             :                 {
    6303          48 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6304             : 
    6305          48 :                     n->trigname = $4;
    6306          48 :                     n->tgenabled = $5;
    6307          48 :                     $$ = (Node *) n;
    6308             :                 }
    6309             :         ;
    6310             : 
    6311             : enable_trigger:
    6312           6 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6313           6 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6314          16 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6315          20 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6316             :         ;
    6317             : 
    6318             : /*****************************************************************************
    6319             :  *
    6320             :  *      QUERY :
    6321             :  *              CREATE ASSERTION ...
    6322             :  *
    6323             :  *****************************************************************************/
    6324             : 
    6325             : CreateAssertionStmt:
    6326             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6327             :                 {
    6328           0 :                     ereport(ERROR,
    6329             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6330             :                              errmsg("CREATE ASSERTION is not yet implemented"),
    6331             :                              parser_errposition(@1)));
    6332             : 
    6333             :                     $$ = NULL;
    6334             :                 }
    6335             :         ;
    6336             : 
    6337             : 
    6338             : /*****************************************************************************
    6339             :  *
    6340             :  *      QUERY :
    6341             :  *              define (aggregate,operator,type)
    6342             :  *
    6343             :  *****************************************************************************/
    6344             : 
    6345             : DefineStmt:
    6346             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6347             :                 {
    6348         544 :                     DefineStmt *n = makeNode(DefineStmt);
    6349             : 
    6350         544 :                     n->kind = OBJECT_AGGREGATE;
    6351         544 :                     n->oldstyle = false;
    6352         544 :                     n->replace = $2;
    6353         544 :                     n->defnames = $4;
    6354         544 :                     n->args = $5;
    6355         544 :                     n->definition = $6;
    6356         544 :                     $$ = (Node *) n;
    6357             :                 }
    6358             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6359             :                 {
    6360             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6361         362 :                     DefineStmt *n = makeNode(DefineStmt);
    6362             : 
    6363         362 :                     n->kind = OBJECT_AGGREGATE;
    6364         362 :                     n->oldstyle = true;
    6365         362 :                     n->replace = $2;
    6366         362 :                     n->defnames = $4;
    6367         362 :                     n->args = NIL;
    6368         362 :                     n->definition = $5;
    6369         362 :                     $$ = (Node *) n;
    6370             :                 }
    6371             :             | CREATE OPERATOR any_operator definition
    6372             :                 {
    6373        1588 :                     DefineStmt *n = makeNode(DefineStmt);
    6374             : 
    6375        1588 :                     n->kind = OBJECT_OPERATOR;
    6376        1588 :                     n->oldstyle = false;
    6377        1588 :                     n->defnames = $3;
    6378        1588 :                     n->args = NIL;
    6379        1588 :                     n->definition = $4;
    6380        1588 :                     $$ = (Node *) n;
    6381             :                 }
    6382             :             | CREATE TYPE_P any_name definition
    6383             :                 {
    6384         216 :                     DefineStmt *n = makeNode(DefineStmt);
    6385             : 
    6386         216 :                     n->kind = OBJECT_TYPE;
    6387         216 :                     n->oldstyle = false;
    6388         216 :                     n->defnames = $3;
    6389         216 :                     n->args = NIL;
    6390         216 :                     n->definition = $4;
    6391         216 :                     $$ = (Node *) n;
    6392             :                 }
    6393             :             | CREATE TYPE_P any_name
    6394             :                 {
    6395             :                     /* Shell type (identified by lack of definition) */
    6396         156 :                     DefineStmt *n = makeNode(DefineStmt);
    6397             : 
    6398         156 :                     n->kind = OBJECT_TYPE;
    6399         156 :                     n->oldstyle = false;
    6400         156 :                     n->defnames = $3;
    6401         156 :                     n->args = NIL;
    6402         156 :                     n->definition = NIL;
    6403         156 :                     $$ = (Node *) n;
    6404             :                 }
    6405             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6406             :                 {
    6407        4500 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6408             : 
    6409             :                     /* can't use qualified_name, sigh */
    6410        4500 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6411        4500 :                     n->coldeflist = $6;
    6412        4500 :                     $$ = (Node *) n;
    6413             :                 }
    6414             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6415             :                 {
    6416         200 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6417             : 
    6418         200 :                     n->typeName = $3;
    6419         200 :                     n->vals = $7;
    6420         200 :                     $$ = (Node *) n;
    6421             :                 }
    6422             :             | CREATE TYPE_P any_name AS RANGE definition
    6423             :                 {
    6424         184 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6425             : 
    6426         184 :                     n->typeName = $3;
    6427         184 :                     n->params = $6;
    6428         184 :                     $$ = (Node *) n;
    6429             :                 }
    6430             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6431             :                 {
    6432          40 :                     DefineStmt *n = makeNode(DefineStmt);
    6433             : 
    6434          40 :                     n->kind = OBJECT_TSPARSER;
    6435          40 :                     n->args = NIL;
    6436          40 :                     n->defnames = $5;
    6437          40 :                     n->definition = $6;
    6438          40 :                     $$ = (Node *) n;
    6439             :                 }
    6440             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6441             :                 {
    6442        2640 :                     DefineStmt *n = makeNode(DefineStmt);
    6443             : 
    6444        2640 :                     n->kind = OBJECT_TSDICTIONARY;
    6445        2640 :                     n->args = NIL;
    6446        2640 :                     n->defnames = $5;
    6447        2640 :                     n->definition = $6;
    6448        2640 :                     $$ = (Node *) n;
    6449             :                 }
    6450             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6451             :                 {
    6452         130 :                     DefineStmt *n = makeNode(DefineStmt);
    6453             : 
    6454         130 :                     n->kind = OBJECT_TSTEMPLATE;
    6455         130 :                     n->args = NIL;
    6456         130 :                     n->defnames = $5;
    6457         130 :                     n->definition = $6;
    6458         130 :                     $$ = (Node *) n;
    6459             :                 }
    6460             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6461             :                 {
    6462        2582 :                     DefineStmt *n = makeNode(DefineStmt);
    6463             : 
    6464        2582 :                     n->kind = OBJECT_TSCONFIGURATION;
    6465        2582 :                     n->args = NIL;
    6466        2582 :                     n->defnames = $5;
    6467        2582 :                     n->definition = $6;
    6468        2582 :                     $$ = (Node *) n;
    6469             :                 }
    6470             :             | CREATE COLLATION any_name definition
    6471             :                 {
    6472         292 :                     DefineStmt *n = makeNode(DefineStmt);
    6473             : 
    6474         292 :                     n->kind = OBJECT_COLLATION;
    6475         292 :                     n->args = NIL;
    6476         292 :                     n->defnames = $3;
    6477         292 :                     n->definition = $4;
    6478         292 :                     $$ = (Node *) n;
    6479             :                 }
    6480             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6481             :                 {
    6482          18 :                     DefineStmt *n = makeNode(DefineStmt);
    6483             : 
    6484          18 :                     n->kind = OBJECT_COLLATION;
    6485          18 :                     n->args = NIL;
    6486          18 :                     n->defnames = $6;
    6487          18 :                     n->definition = $7;
    6488          18 :                     n->if_not_exists = true;
    6489          18 :                     $$ = (Node *) n;
    6490             :                 }
    6491             :             | CREATE COLLATION any_name FROM any_name
    6492             :                 {
    6493          54 :                     DefineStmt *n = makeNode(DefineStmt);
    6494             : 
    6495          54 :                     n->kind = OBJECT_COLLATION;
    6496          54 :                     n->args = NIL;
    6497          54 :                     n->defnames = $3;
    6498          54 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6499          54 :                     $$ = (Node *) n;
    6500             :                 }
    6501             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6502             :                 {
    6503           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6504             : 
    6505           0 :                     n->kind = OBJECT_COLLATION;
    6506           0 :                     n->args = NIL;
    6507           0 :                     n->defnames = $6;
    6508           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6509           0 :                     n->if_not_exists = true;
    6510           0 :                     $$ = (Node *) n;
    6511             :                 }
    6512             :         ;
    6513             : 
    6514        9204 : definition: '(' def_list ')'                        { $$ = $2; }
    6515             :         ;
    6516             : 
    6517        9204 : def_list:   def_elem                                { $$ = list_make1($1); }
    6518       14114 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6519             :         ;
    6520             : 
    6521             : def_elem:   ColLabel '=' def_arg
    6522             :                 {
    6523       22980 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6524             :                 }
    6525             :             | ColLabel
    6526             :                 {
    6527         338 :                     $$ = makeDefElem($1, NULL, @1);
    6528             :                 }
    6529             :         ;
    6530             : 
    6531             : /* Note: any simple identifier will be returned as a type name! */
    6532       18740 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6533        3694 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6534        1176 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6535        1288 :             | NumericOnly                   { $$ = (Node *) $1; }
    6536        1834 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6537         164 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6538             :         ;
    6539             : 
    6540         362 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6541             :         ;
    6542             : 
    6543         362 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6544        1292 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6545             :         ;
    6546             : 
    6547             : /*
    6548             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6549             :  * the item names needed in old aggregate definitions are likely to become
    6550             :  * SQL keywords.
    6551             :  */
    6552             : old_aggr_elem:  IDENT '=' def_arg
    6553             :                 {
    6554        1654 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6555             :                 }
    6556             :         ;
    6557             : 
    6558             : opt_enum_val_list:
    6559         192 :         enum_val_list                           { $$ = $1; }
    6560           8 :         | /*EMPTY*/                             { $$ = NIL; }
    6561             :         ;
    6562             : 
    6563             : enum_val_list:  Sconst
    6564         192 :                 { $$ = list_make1(makeString($1)); }
    6565             :             | enum_val_list ',' Sconst
    6566       10406 :                 { $$ = lappend($1, makeString($3)); }
    6567             :         ;
    6568             : 
    6569             : /*****************************************************************************
    6570             :  *
    6571             :  *  ALTER TYPE enumtype ADD ...
    6572             :  *
    6573             :  *****************************************************************************/
    6574             : 
    6575             : AlterEnumStmt:
    6576             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6577             :             {
    6578         154 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6579             : 
    6580         154 :                 n->typeName = $3;
    6581         154 :                 n->oldVal = NULL;
    6582         154 :                 n->newVal = $7;
    6583         154 :                 n->newValNeighbor = NULL;
    6584         154 :                 n->newValIsAfter = true;
    6585         154 :                 n->skipIfNewValExists = $6;
    6586         154 :                 $$ = (Node *) n;
    6587             :             }
    6588             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6589             :             {
    6590         194 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6591             : 
    6592         194 :                 n->typeName = $3;
    6593         194 :                 n->oldVal = NULL;
    6594         194 :                 n->newVal = $7;
    6595         194 :                 n->newValNeighbor = $9;
    6596         194 :                 n->newValIsAfter = false;
    6597         194 :                 n->skipIfNewValExists = $6;
    6598         194 :                 $$ = (Node *) n;
    6599             :             }
    6600             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6601             :             {
    6602          22 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6603             : 
    6604          22 :                 n->typeName = $3;
    6605          22 :                 n->oldVal = NULL;
    6606          22 :                 n->newVal = $7;
    6607          22 :                 n->newValNeighbor = $9;
    6608          22 :                 n->newValIsAfter = true;
    6609          22 :                 n->skipIfNewValExists = $6;
    6610          22 :                 $$ = (Node *) n;
    6611             :             }
    6612             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6613             :             {
    6614          24 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6615             : 
    6616          24 :                 n->typeName = $3;
    6617          24 :                 n->oldVal = $6;
    6618          24 :                 n->newVal = $8;
    6619          24 :                 n->newValNeighbor = NULL;
    6620          24 :                 n->newValIsAfter = false;
    6621          24 :                 n->skipIfNewValExists = false;
    6622          24 :                 $$ = (Node *) n;
    6623             :             }
    6624             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6625             :             {
    6626             :                 /*
    6627             :                  * The following problems must be solved before this can be
    6628             :                  * implemented:
    6629             :                  *
    6630             :                  * - There must be no instance of the target value in
    6631             :                  *   any table.
    6632             :                  *
    6633             :                  * - The value must not appear in any catalog metadata,
    6634             :                  *   such as stored view expressions or column defaults.
    6635             :                  *
    6636             :                  * - The value must not appear in any non-leaf page of a
    6637             :                  *   btree (and similar issues with other index types).
    6638             :                  *   This is problematic because a value could persist
    6639             :                  *   there long after it's gone from user-visible data.
    6640             :                  *
    6641             :                  * - Concurrent sessions must not be able to insert the
    6642             :                  *   value while the preceding conditions are being checked.
    6643             :                  *
    6644             :                  * - Possibly more...
    6645             :                  */
    6646           0 :                 ereport(ERROR,
    6647             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6648             :                          errmsg("dropping an enum value is not implemented"),
    6649             :                          parser_errposition(@4)));
    6650             :             }
    6651             :          ;
    6652             : 
    6653          12 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6654         358 :         | /* EMPTY */                          { $$ = false; }
    6655             :         ;
    6656             : 
    6657             : 
    6658             : /*****************************************************************************
    6659             :  *
    6660             :  *      QUERIES :
    6661             :  *              CREATE OPERATOR CLASS ...
    6662             :  *              CREATE OPERATOR FAMILY ...
    6663             :  *              ALTER OPERATOR FAMILY ...
    6664             :  *              DROP OPERATOR CLASS ...
    6665             :  *              DROP OPERATOR FAMILY ...
    6666             :  *
    6667             :  *****************************************************************************/
    6668             : 
    6669             : CreateOpClassStmt:
    6670             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6671             :             USING name opt_opfamily AS opclass_item_list
    6672             :                 {
    6673         388 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6674             : 
    6675         388 :                     n->opclassname = $4;
    6676         388 :                     n->isDefault = $5;
    6677         388 :                     n->datatype = $8;
    6678         388 :                     n->amname = $10;
    6679         388 :                     n->opfamilyname = $11;
    6680         388 :                     n->items = $13;
    6681         388 :                     $$ = (Node *) n;
    6682             :                 }
    6683             :         ;
    6684             : 
    6685             : opclass_item_list:
    6686         838 :             opclass_item                            { $$ = list_make1($1); }
    6687        3088 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6688             :         ;
    6689             : 
    6690             : opclass_item:
    6691             :             OPERATOR Iconst any_operator opclass_purpose
    6692             :                 {
    6693        1092 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6694        1092 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6695             : 
    6696        1092 :                     owa->objname = $3;
    6697        1092 :                     owa->objargs = NIL;
    6698        1092 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6699        1092 :                     n->name = owa;
    6700        1092 :                     n->number = $2;
    6701        1092 :                     n->order_family = $4;
    6702        1092 :                     $$ = (Node *) n;
    6703             :                 }
    6704             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6705             :                 {
    6706        1062 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6707             : 
    6708        1062 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6709        1062 :                     n->name = $3;
    6710        1062 :                     n->number = $2;
    6711        1062 :                     n->order_family = $4;
    6712        1062 :                     $$ = (Node *) n;
    6713             :                 }
    6714             :             | FUNCTION Iconst function_with_argtypes
    6715             :                 {
    6716        1386 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6717             : 
    6718        1386 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6719        1386 :                     n->name = $3;
    6720        1386 :                     n->number = $2;
    6721        1386 :                     $$ = (Node *) n;
    6722             :                 }
    6723             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6724             :                 {
    6725         188 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6726             : 
    6727         188 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6728         188 :                     n->name = $6;
    6729         188 :                     n->number = $2;
    6730         188 :                     n->class_args = $4;
    6731         188 :                     $$ = (Node *) n;
    6732             :                 }
    6733             :             | STORAGE Typename
    6734             :                 {
    6735         198 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6736             : 
    6737         198 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6738         198 :                     n->storedtype = $2;
    6739         198 :                     $$ = (Node *) n;
    6740             :                 }
    6741             :         ;
    6742             : 
    6743         290 : opt_default:    DEFAULT                     { $$ = true; }
    6744         162 :             | /*EMPTY*/                     { $$ = false; }
    6745             :         ;
    6746             : 
    6747          44 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6748         344 :             | /*EMPTY*/                     { $$ = NIL; }
    6749             :         ;
    6750             : 
    6751           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6752          72 :             | FOR ORDER BY any_name         { $$ = $4; }
    6753        2082 :             | /*EMPTY*/                     { $$ = NIL; }
    6754             :         ;
    6755             : 
    6756             : 
    6757             : CreateOpFamilyStmt:
    6758             :             CREATE OPERATOR FAMILY any_name USING name
    6759             :                 {
    6760         148 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6761             : 
    6762         148 :                     n->opfamilyname = $4;
    6763         148 :                     n->amname = $6;
    6764         148 :                     $$ = (Node *) n;
    6765             :                 }
    6766             :         ;
    6767             : 
    6768             : AlterOpFamilyStmt:
    6769             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6770             :                 {
    6771         450 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6772             : 
    6773         450 :                     n->opfamilyname = $4;
    6774         450 :                     n->amname = $6;
    6775         450 :                     n->isDrop = false;
    6776         450 :                     n->items = $8;
    6777         450 :                     $$ = (Node *) n;
    6778             :                 }
    6779             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6780             :                 {
    6781          64 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6782             : 
    6783          64 :                     n->opfamilyname = $4;
    6784          64 :                     n->amname = $6;
    6785          64 :                     n->isDrop = true;
    6786          64 :                     n->items = $8;
    6787          64 :                     $$ = (Node *) n;
    6788             :                 }
    6789             :         ;
    6790             : 
    6791             : opclass_drop_list:
    6792          64 :             opclass_drop                            { $$ = list_make1($1); }
    6793          30 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6794             :         ;
    6795             : 
    6796             : opclass_drop:
    6797             :             OPERATOR Iconst '(' type_list ')'
    6798             :                 {
    6799          56 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6800             : 
    6801          56 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6802          56 :                     n->number = $2;
    6803          56 :                     n->class_args = $4;
    6804          56 :                     $$ = (Node *) n;
    6805             :                 }
    6806             :             | FUNCTION Iconst '(' type_list ')'
    6807             :                 {
    6808          38 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6809             : 
    6810          38 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6811          38 :                     n->number = $2;
    6812          38 :                     n->class_args = $4;
    6813          38 :                     $$ = (Node *) n;
    6814             :                 }
    6815             :         ;
    6816             : 
    6817             : 
    6818             : DropOpClassStmt:
    6819             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6820             :                 {
    6821          38 :                     DropStmt *n = makeNode(DropStmt);
    6822             : 
    6823          38 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6824          38 :                     n->removeType = OBJECT_OPCLASS;
    6825          38 :                     n->behavior = $7;
    6826          38 :                     n->missing_ok = false;
    6827          38 :                     n->concurrent = false;
    6828          38 :                     $$ = (Node *) n;
    6829             :                 }
    6830             :             | DROP OPERATOR CLASS 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_OPCLASS;
    6836          18 :                     n->behavior = $9;
    6837          18 :                     n->missing_ok = true;
    6838          18 :                     n->concurrent = false;
    6839          18 :                     $$ = (Node *) n;
    6840             :                 }
    6841             :         ;
    6842             : 
    6843             : DropOpFamilyStmt:
    6844             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6845             :                 {
    6846         110 :                     DropStmt *n = makeNode(DropStmt);
    6847             : 
    6848         110 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6849         110 :                     n->removeType = OBJECT_OPFAMILY;
    6850         110 :                     n->behavior = $7;
    6851         110 :                     n->missing_ok = false;
    6852         110 :                     n->concurrent = false;
    6853         110 :                     $$ = (Node *) n;
    6854             :                 }
    6855             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6856             :                 {
    6857          18 :                     DropStmt *n = makeNode(DropStmt);
    6858             : 
    6859          18 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6860          18 :                     n->removeType = OBJECT_OPFAMILY;
    6861          18 :                     n->behavior = $9;
    6862          18 :                     n->missing_ok = true;
    6863          18 :                     n->concurrent = false;
    6864          18 :                     $$ = (Node *) n;
    6865             :                 }
    6866             :         ;
    6867             : 
    6868             : 
    6869             : /*****************************************************************************
    6870             :  *
    6871             :  *      QUERY:
    6872             :  *
    6873             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6874             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6875             :  *
    6876             :  *****************************************************************************/
    6877             : DropOwnedStmt:
    6878             :             DROP OWNED BY role_list opt_drop_behavior
    6879             :                 {
    6880         154 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6881             : 
    6882         154 :                     n->roles = $4;
    6883         154 :                     n->behavior = $5;
    6884         154 :                     $$ = (Node *) n;
    6885             :                 }
    6886             :         ;
    6887             : 
    6888             : ReassignOwnedStmt:
    6889             :             REASSIGN OWNED BY role_list TO RoleSpec
    6890             :                 {
    6891          52 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6892             : 
    6893          52 :                     n->roles = $4;
    6894          52 :                     n->newrole = $6;
    6895          52 :                     $$ = (Node *) n;
    6896             :                 }
    6897             :         ;
    6898             : 
    6899             : /*****************************************************************************
    6900             :  *
    6901             :  *      QUERY:
    6902             :  *
    6903             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6904             :  *           [ RESTRICT | CASCADE ]
    6905             :  *
    6906             :  *****************************************************************************/
    6907             : 
    6908             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6909             :                 {
    6910        1312 :                     DropStmt *n = makeNode(DropStmt);
    6911             : 
    6912        1312 :                     n->removeType = $2;
    6913        1312 :                     n->missing_ok = true;
    6914        1312 :                     n->objects = $5;
    6915        1312 :                     n->behavior = $6;
    6916        1312 :                     n->concurrent = false;
    6917        1312 :                     $$ = (Node *) n;
    6918             :                 }
    6919             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6920             :                 {
    6921       15840 :                     DropStmt *n = makeNode(DropStmt);
    6922             : 
    6923       15840 :                     n->removeType = $2;
    6924       15840 :                     n->missing_ok = false;
    6925       15840 :                     n->objects = $3;
    6926       15840 :                     n->behavior = $4;
    6927       15840 :                     n->concurrent = false;
    6928       15840 :                     $$ = (Node *) n;
    6929             :                 }
    6930             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6931             :                 {
    6932          78 :                     DropStmt *n = makeNode(DropStmt);
    6933             : 
    6934          78 :                     n->removeType = $2;
    6935          78 :                     n->missing_ok = true;
    6936          78 :                     n->objects = $5;
    6937          78 :                     n->behavior = $6;
    6938          78 :                     n->concurrent = false;
    6939          78 :                     $$ = (Node *) n;
    6940             :                 }
    6941             :             | DROP drop_type_name name_list opt_drop_behavior
    6942             :                 {
    6943        1406 :                     DropStmt *n = makeNode(DropStmt);
    6944             : 
    6945        1406 :                     n->removeType = $2;
    6946        1406 :                     n->missing_ok = false;
    6947        1406 :                     n->objects = $3;
    6948        1406 :                     n->behavior = $4;
    6949        1406 :                     n->concurrent = false;
    6950        1406 :                     $$ = (Node *) n;
    6951             :                 }
    6952             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    6953             :                 {
    6954        1124 :                     DropStmt *n = makeNode(DropStmt);
    6955             : 
    6956        1124 :                     n->removeType = $2;
    6957        1124 :                     n->objects = list_make1(lappend($5, makeString($3)));
    6958        1124 :                     n->behavior = $6;
    6959        1124 :                     n->missing_ok = false;
    6960        1124 :                     n->concurrent = false;
    6961        1124 :                     $$ = (Node *) n;
    6962             :                 }
    6963             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    6964             :                 {
    6965          48 :                     DropStmt *n = makeNode(DropStmt);
    6966             : 
    6967          48 :                     n->removeType = $2;
    6968          48 :                     n->objects = list_make1(lappend($7, makeString($5)));
    6969          48 :                     n->behavior = $8;
    6970          48 :                     n->missing_ok = true;
    6971          48 :                     n->concurrent = false;
    6972          48 :                     $$ = (Node *) n;
    6973             :                 }
    6974             :             | DROP TYPE_P type_name_list opt_drop_behavior
    6975             :                 {
    6976         560 :                     DropStmt *n = makeNode(DropStmt);
    6977             : 
    6978         560 :                     n->removeType = OBJECT_TYPE;
    6979         560 :                     n->missing_ok = false;
    6980         560 :                     n->objects = $3;
    6981         560 :                     n->behavior = $4;
    6982         560 :                     n->concurrent = false;
    6983         560 :                     $$ = (Node *) n;
    6984             :                 }
    6985             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    6986             :                 {
    6987          22 :                     DropStmt *n = makeNode(DropStmt);
    6988             : 
    6989          22 :                     n->removeType = OBJECT_TYPE;
    6990          22 :                     n->missing_ok = true;
    6991          22 :                     n->objects = $5;
    6992          22 :                     n->behavior = $6;
    6993          22 :                     n->concurrent = false;
    6994          22 :                     $$ = (Node *) n;
    6995             :                 }
    6996             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    6997             :                 {
    6998         464 :                     DropStmt *n = makeNode(DropStmt);
    6999             : 
    7000         464 :                     n->removeType = OBJECT_DOMAIN;
    7001         464 :                     n->missing_ok = false;
    7002         464 :                     n->objects = $3;
    7003         464 :                     n->behavior = $4;
    7004         464 :                     n->concurrent = false;
    7005         464 :                     $$ = (Node *) n;
    7006             :                 }
    7007             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    7008             :                 {
    7009          18 :                     DropStmt *n = makeNode(DropStmt);
    7010             : 
    7011          18 :                     n->removeType = OBJECT_DOMAIN;
    7012          18 :                     n->missing_ok = true;
    7013          18 :                     n->objects = $5;
    7014          18 :                     n->behavior = $6;
    7015          18 :                     n->concurrent = false;
    7016          18 :                     $$ = (Node *) n;
    7017             :                 }
    7018             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7019             :                 {
    7020         214 :                     DropStmt *n = makeNode(DropStmt);
    7021             : 
    7022         214 :                     n->removeType = OBJECT_INDEX;
    7023         214 :                     n->missing_ok = false;
    7024         214 :                     n->objects = $4;
    7025         214 :                     n->behavior = $5;
    7026         214 :                     n->concurrent = true;
    7027         214 :                     $$ = (Node *) n;
    7028             :                 }
    7029             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7030             :                 {
    7031          12 :                     DropStmt *n = makeNode(DropStmt);
    7032             : 
    7033          12 :                     n->removeType = OBJECT_INDEX;
    7034          12 :                     n->missing_ok = true;
    7035          12 :                     n->objects = $6;
    7036          12 :                     n->behavior = $7;
    7037          12 :                     n->concurrent = true;
    7038          12 :                     $$ = (Node *) n;
    7039             :                 }
    7040             :         ;
    7041             : 
    7042             : /* object types taking any_name/any_name_list */
    7043             : object_type_any_name:
    7044       14786 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7045         198 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7046        1010 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7047         124 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7048         778 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7049         184 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7050          96 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7051          56 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7052         192 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7053          20 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7054        2524 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7055         106 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7056        2528 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7057             :         ;
    7058             : 
    7059             : /*
    7060             :  * object types taking name/name_list
    7061             :  *
    7062             :  * DROP handles some of them separately
    7063             :  */
    7064             : 
    7065             : object_type_name:
    7066         222 :             drop_type_name                          { $$ = $1; }
    7067         218 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7068          52 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7069          10 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7070           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7071             :         ;
    7072             : 
    7073             : drop_type_name:
    7074          46 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7075         126 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7076         146 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7077         154 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7078         144 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7079         378 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7080         582 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7081         130 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7082             :         ;
    7083             : 
    7084             : /* object types attached to a table */
    7085             : object_type_name_on_any_name:
    7086         164 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7087         268 :             | RULE                                  { $$ = OBJECT_RULE; }
    7088         792 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7089             :         ;
    7090             : 
    7091             : any_name_list:
    7092       25190 :             any_name                                { $$ = list_make1($1); }
    7093        4136 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7094             :         ;
    7095             : 
    7096       63202 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7097        8792 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7098             :         ;
    7099             : 
    7100             : attrs:      '.' attr_name
    7101      115528 :                     { $$ = list_make1(makeString($2)); }
    7102             :             | attrs '.' attr_name
    7103          64 :                     { $$ = lappend($1, makeString($3)); }
    7104             :         ;
    7105             : 
    7106             : type_name_list:
    7107        1064 :             Typename                                { $$ = list_make1($1); }
    7108          96 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7109             :         ;
    7110             : 
    7111             : /*****************************************************************************
    7112             :  *
    7113             :  *      QUERY:
    7114             :  *              truncate table relname1, relname2, ...
    7115             :  *
    7116             :  *****************************************************************************/
    7117             : 
    7118             : TruncateStmt:
    7119             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7120             :                 {
    7121        1672 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7122             : 
    7123        1672 :                     n->relations = $3;
    7124        1672 :                     n->restart_seqs = $4;
    7125        1672 :                     n->behavior = $5;
    7126        1672 :                     $$ = (Node *) n;
    7127             :                 }
    7128             :         ;
    7129             : 
    7130             : opt_restart_seqs:
    7131          24 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7132          24 :             | RESTART IDENTITY_P        { $$ = true; }
    7133        1624 :             | /* EMPTY */               { $$ = false; }
    7134             :         ;
    7135             : 
    7136             : /*****************************************************************************
    7137             :  *
    7138             :  * COMMENT ON <object> IS <text>
    7139             :  *
    7140             :  *****************************************************************************/
    7141             : 
    7142             : CommentStmt:
    7143             :             COMMENT ON object_type_any_name any_name IS comment_text
    7144             :                 {
    7145        5308 :                     CommentStmt *n = makeNode(CommentStmt);
    7146             : 
    7147        5308 :                     n->objtype = $3;
    7148        5308 :                     n->object = (Node *) $4;
    7149        5308 :                     n->comment = $6;
    7150        5308 :                     $$ = (Node *) n;
    7151             :                 }
    7152             :             | COMMENT ON COLUMN any_name IS comment_text
    7153             :                 {
    7154         114 :                     CommentStmt *n = makeNode(CommentStmt);
    7155             : 
    7156         114 :                     n->objtype = OBJECT_COLUMN;
    7157         114 :                     n->object = (Node *) $4;
    7158         114 :                     n->comment = $6;
    7159         114 :                     $$ = (Node *) n;
    7160             :                 }
    7161             :             | COMMENT ON object_type_name name IS comment_text
    7162             :                 {
    7163         440 :                     CommentStmt *n = makeNode(CommentStmt);
    7164             : 
    7165         440 :                     n->objtype = $3;
    7166         440 :                     n->object = (Node *) makeString($4);
    7167         440 :                     n->comment = $6;
    7168         440 :                     $$ = (Node *) n;
    7169             :                 }
    7170             :             | COMMENT ON TYPE_P Typename IS comment_text
    7171             :                 {
    7172          56 :                     CommentStmt *n = makeNode(CommentStmt);
    7173             : 
    7174          56 :                     n->objtype = OBJECT_TYPE;
    7175          56 :                     n->object = (Node *) $4;
    7176          56 :                     n->comment = $6;
    7177          56 :                     $$ = (Node *) n;
    7178             :                 }
    7179             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7180             :                 {
    7181           8 :                     CommentStmt *n = makeNode(CommentStmt);
    7182             : 
    7183           8 :                     n->objtype = OBJECT_DOMAIN;
    7184           8 :                     n->object = (Node *) $4;
    7185           8 :                     n->comment = $6;
    7186           8 :                     $$ = (Node *) n;
    7187             :                 }
    7188             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7189             :                 {
    7190          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7191             : 
    7192          40 :                     n->objtype = OBJECT_AGGREGATE;
    7193          40 :                     n->object = (Node *) $4;
    7194          40 :                     n->comment = $6;
    7195          40 :                     $$ = (Node *) n;
    7196             :                 }
    7197             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7198             :                 {
    7199         170 :                     CommentStmt *n = makeNode(CommentStmt);
    7200             : 
    7201         170 :                     n->objtype = OBJECT_FUNCTION;
    7202         170 :                     n->object = (Node *) $4;
    7203         170 :                     n->comment = $6;
    7204         170 :                     $$ = (Node *) n;
    7205             :                 }
    7206             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7207             :                 {
    7208          18 :                     CommentStmt *n = makeNode(CommentStmt);
    7209             : 
    7210          18 :                     n->objtype = OBJECT_OPERATOR;
    7211          18 :                     n->object = (Node *) $4;
    7212          18 :                     n->comment = $6;
    7213          18 :                     $$ = (Node *) n;
    7214             :                 }
    7215             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7216             :                 {
    7217         110 :                     CommentStmt *n = makeNode(CommentStmt);
    7218             : 
    7219         110 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7220         110 :                     n->object = (Node *) lappend($6, makeString($4));
    7221         110 :                     n->comment = $8;
    7222         110 :                     $$ = (Node *) n;
    7223             :                 }
    7224             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7225             :                 {
    7226          38 :                     CommentStmt *n = makeNode(CommentStmt);
    7227             : 
    7228          38 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7229             :                     /*
    7230             :                      * should use Typename not any_name in the production, but
    7231             :                      * there's a shift/reduce conflict if we do that, so fix it
    7232             :                      * up here.
    7233             :                      */
    7234          38 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7235          38 :                     n->comment = $9;
    7236          38 :                     $$ = (Node *) n;
    7237             :                 }
    7238             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7239             :                 {
    7240          40 :                     CommentStmt *n = makeNode(CommentStmt);
    7241             : 
    7242          40 :                     n->objtype = $3;
    7243          40 :                     n->object = (Node *) lappend($6, makeString($4));
    7244          40 :                     n->comment = $8;
    7245          40 :                     $$ = (Node *) n;
    7246             :                 }
    7247             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7248             :                 {
    7249           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7250             : 
    7251           0 :                     n->objtype = OBJECT_PROCEDURE;
    7252           0 :                     n->object = (Node *) $4;
    7253           0 :                     n->comment = $6;
    7254           0 :                     $$ = (Node *) n;
    7255             :                 }
    7256             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7257             :                 {
    7258           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7259             : 
    7260           0 :                     n->objtype = OBJECT_ROUTINE;
    7261           0 :                     n->object = (Node *) $4;
    7262           0 :                     n->comment = $6;
    7263           0 :                     $$ = (Node *) n;
    7264             :                 }
    7265             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7266             :                 {
    7267          14 :                     CommentStmt *n = makeNode(CommentStmt);
    7268             : 
    7269          14 :                     n->objtype = OBJECT_TRANSFORM;
    7270          14 :                     n->object = (Node *) list_make2($5, makeString($7));
    7271          14 :                     n->comment = $9;
    7272          14 :                     $$ = (Node *) n;
    7273             :                 }
    7274             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7275             :                 {
    7276           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7277             : 
    7278           0 :                     n->objtype = OBJECT_OPCLASS;
    7279           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7280           0 :                     n->comment = $9;
    7281           0 :                     $$ = (Node *) n;
    7282             :                 }
    7283             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7284             :                 {
    7285           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7286             : 
    7287           0 :                     n->objtype = OBJECT_OPFAMILY;
    7288           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7289           0 :                     n->comment = $9;
    7290           0 :                     $$ = (Node *) n;
    7291             :                 }
    7292             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7293             :                 {
    7294          24 :                     CommentStmt *n = makeNode(CommentStmt);
    7295             : 
    7296          24 :                     n->objtype = OBJECT_LARGEOBJECT;
    7297          24 :                     n->object = (Node *) $5;
    7298          24 :                     n->comment = $7;
    7299          24 :                     $$ = (Node *) n;
    7300             :                 }
    7301             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7302             :                 {
    7303           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7304             : 
    7305           0 :                     n->objtype = OBJECT_CAST;
    7306           0 :                     n->object = (Node *) list_make2($5, $7);
    7307           0 :                     n->comment = $10;
    7308           0 :                     $$ = (Node *) n;
    7309             :                 }
    7310             :         ;
    7311             : 
    7312             : comment_text:
    7313        6276 :             Sconst                              { $$ = $1; }
    7314         104 :             | NULL_P                            { $$ = NULL; }
    7315             :         ;
    7316             : 
    7317             : 
    7318             : /*****************************************************************************
    7319             :  *
    7320             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7321             :  *
    7322             :  *  As with COMMENT ON, <object> can refer to various types of database
    7323             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7324             :  *
    7325             :  *****************************************************************************/
    7326             : 
    7327             : SecLabelStmt:
    7328             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7329             :             IS security_label
    7330             :                 {
    7331          48 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7332             : 
    7333          48 :                     n->provider = $3;
    7334          48 :                     n->objtype = $5;
    7335          48 :                     n->object = (Node *) $6;
    7336          48 :                     n->label = $8;
    7337          48 :                     $$ = (Node *) n;
    7338             :                 }
    7339             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7340             :               IS security_label
    7341             :                 {
    7342           4 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7343             : 
    7344           4 :                     n->provider = $3;
    7345           4 :                     n->objtype = OBJECT_COLUMN;
    7346           4 :                     n->object = (Node *) $6;
    7347           4 :                     n->label = $8;
    7348           4 :                     $$ = (Node *) n;
    7349             :                 }
    7350             :             | SECURITY LABEL opt_provider ON object_type_name name
    7351             :               IS security_label
    7352             :                 {
    7353          44 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7354             : 
    7355          44 :                     n->provider = $3;
    7356          44 :                     n->objtype = $5;
    7357          44 :                     n->object = (Node *) makeString($6);
    7358          44 :                     n->label = $8;
    7359          44 :                     $$ = (Node *) n;
    7360             :                 }
    7361             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7362             :               IS security_label
    7363             :                 {
    7364           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7365             : 
    7366           0 :                     n->provider = $3;
    7367           0 :                     n->objtype = OBJECT_TYPE;
    7368           0 :                     n->object = (Node *) $6;
    7369           0 :                     n->label = $8;
    7370           0 :                     $$ = (Node *) n;
    7371             :                 }
    7372             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7373             :               IS security_label
    7374             :                 {
    7375           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7376             : 
    7377           2 :                     n->provider = $3;
    7378           2 :                     n->objtype = OBJECT_DOMAIN;
    7379           2 :                     n->object = (Node *) $6;
    7380           2 :                     n->label = $8;
    7381           2 :                     $$ = (Node *) n;
    7382             :                 }
    7383             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7384             :               IS security_label
    7385             :                 {
    7386           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7387             : 
    7388           0 :                     n->provider = $3;
    7389           0 :                     n->objtype = OBJECT_AGGREGATE;
    7390           0 :                     n->object = (Node *) $6;
    7391           0 :                     n->label = $8;
    7392           0 :                     $$ = (Node *) n;
    7393             :                 }
    7394             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7395             :               IS security_label
    7396             :                 {
    7397           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7398             : 
    7399           2 :                     n->provider = $3;
    7400           2 :                     n->objtype = OBJECT_FUNCTION;
    7401           2 :                     n->object = (Node *) $6;
    7402           2 :                     n->label = $8;
    7403           2 :                     $$ = (Node *) n;
    7404             :                 }
    7405             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7406             :               IS security_label
    7407             :                 {
    7408           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7409             : 
    7410           0 :                     n->provider = $3;
    7411           0 :                     n->objtype = OBJECT_LARGEOBJECT;
    7412           0 :                     n->object = (Node *) $7;
    7413           0 :                     n->label = $9;
    7414           0 :                     $$ = (Node *) n;
    7415             :                 }
    7416             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7417             :               IS security_label
    7418             :                 {
    7419           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7420             : 
    7421           0 :                     n->provider = $3;
    7422           0 :                     n->objtype = OBJECT_PROCEDURE;
    7423           0 :                     n->object = (Node *) $6;
    7424           0 :                     n->label = $8;
    7425           0 :                     $$ = (Node *) n;
    7426             :                 }
    7427             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7428             :               IS security_label
    7429             :                 {
    7430           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7431             : 
    7432           0 :                     n->provider = $3;
    7433           0 :                     n->objtype = OBJECT_ROUTINE;
    7434           0 :                     n->object = (Node *) $6;
    7435           0 :                     n->label = $8;
    7436           0 :                     $$ = (Node *) n;
    7437             :                 }
    7438             :         ;
    7439             : 
    7440          20 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7441          80 :                 | /* EMPTY */                   { $$ = NULL; }
    7442             :         ;
    7443             : 
    7444         100 : security_label: Sconst              { $$ = $1; }
    7445           0 :                 | NULL_P            { $$ = NULL; }
    7446             :         ;
    7447             : 
    7448             : /*****************************************************************************
    7449             :  *
    7450             :  *      QUERY:
    7451             :  *          fetch/move
    7452             :  *
    7453             :  *****************************************************************************/
    7454             : 
    7455             : FetchStmt:  FETCH fetch_args
    7456             :                 {
    7457        7438 :                     FetchStmt *n = (FetchStmt *) $2;
    7458             : 
    7459        7438 :                     n->ismove = false;
    7460        7438 :                     $$ = (Node *) n;
    7461             :                 }
    7462             :             | MOVE fetch_args
    7463             :                 {
    7464          68 :                     FetchStmt *n = (FetchStmt *) $2;
    7465             : 
    7466          68 :                     n->ismove = true;
    7467          68 :                     $$ = (Node *) n;
    7468             :                 }
    7469             :         ;
    7470             : 
    7471             : fetch_args: cursor_name
    7472             :                 {
    7473         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7474             : 
    7475         266 :                     n->portalname = $1;
    7476         266 :                     n->direction = FETCH_FORWARD;
    7477         266 :                     n->howMany = 1;
    7478         266 :                     $$ = (Node *) n;
    7479             :                 }
    7480             :             | from_in cursor_name
    7481             :                 {
    7482         216 :                     FetchStmt *n = makeNode(FetchStmt);
    7483             : 
    7484         216 :                     n->portalname = $2;
    7485         216 :                     n->direction = FETCH_FORWARD;
    7486         216 :                     n->howMany = 1;
    7487         216 :                     $$ = (Node *) n;
    7488             :                 }
    7489             :             | NEXT opt_from_in cursor_name
    7490             :                 {
    7491        2008 :                     FetchStmt *n = makeNode(FetchStmt);
    7492             : 
    7493        2008 :                     n->portalname = $3;
    7494        2008 :                     n->direction = FETCH_FORWARD;
    7495        2008 :                     n->howMany = 1;
    7496        2008 :                     $$ = (Node *) n;
    7497             :                 }
    7498             :             | PRIOR opt_from_in cursor_name
    7499             :                 {
    7500          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7501             : 
    7502          30 :                     n->portalname = $3;
    7503          30 :                     n->direction = FETCH_BACKWARD;
    7504          30 :                     n->howMany = 1;
    7505          30 :                     $$ = (Node *) n;
    7506             :                 }
    7507             :             | FIRST_P opt_from_in cursor_name
    7508             :                 {
    7509          24 :                     FetchStmt *n = makeNode(FetchStmt);
    7510             : 
    7511          24 :                     n->portalname = $3;
    7512          24 :                     n->direction = FETCH_ABSOLUTE;
    7513          24 :                     n->howMany = 1;
    7514          24 :                     $$ = (Node *) n;
    7515             :                 }
    7516             :             | LAST_P opt_from_in cursor_name
    7517             :                 {
    7518          18 :                     FetchStmt *n = makeNode(FetchStmt);
    7519             : 
    7520          18 :                     n->portalname = $3;
    7521          18 :                     n->direction = FETCH_ABSOLUTE;
    7522          18 :                     n->howMany = -1;
    7523          18 :                     $$ = (Node *) n;
    7524             :                 }
    7525             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7526             :                 {
    7527          88 :                     FetchStmt *n = makeNode(FetchStmt);
    7528             : 
    7529          88 :                     n->portalname = $4;
    7530          88 :                     n->direction = FETCH_ABSOLUTE;
    7531          88 :                     n->howMany = $2;
    7532          88 :                     $$ = (Node *) n;
    7533             :                 }
    7534             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7535             :                 {
    7536          30 :                     FetchStmt *n = makeNode(FetchStmt);
    7537             : 
    7538          30 :                     n->portalname = $4;
    7539          30 :                     n->direction = FETCH_RELATIVE;
    7540          30 :                     n->howMany = $2;
    7541          30 :                     $$ = (Node *) n;
    7542             :                 }
    7543             :             | SignedIconst opt_from_in cursor_name
    7544             :                 {
    7545        4124 :                     FetchStmt *n = makeNode(FetchStmt);
    7546             : 
    7547        4124 :                     n->portalname = $3;
    7548        4124 :                     n->direction = FETCH_FORWARD;
    7549        4124 :                     n->howMany = $1;
    7550        4124 :                     $$ = (Node *) n;
    7551             :                 }
    7552             :             | ALL opt_from_in cursor_name
    7553             :                 {
    7554         266 :                     FetchStmt *n = makeNode(FetchStmt);
    7555             : 
    7556         266 :                     n->portalname = $3;
    7557         266 :                     n->direction = FETCH_FORWARD;
    7558         266 :                     n->howMany = FETCH_ALL;
    7559         266 :                     $$ = (Node *) n;
    7560             :                 }
    7561             :             | FORWARD opt_from_in cursor_name
    7562             :                 {
    7563          28 :                     FetchStmt *n = makeNode(FetchStmt);
    7564             : 
    7565          28 :                     n->portalname = $3;
    7566          28 :                     n->direction = FETCH_FORWARD;
    7567          28 :                     n->howMany = 1;
    7568          28 :                     $$ = (Node *) n;
    7569             :                 }
    7570             :             | FORWARD SignedIconst opt_from_in cursor_name
    7571             :                 {
    7572           6 :                     FetchStmt *n = makeNode(FetchStmt);
    7573             : 
    7574           6 :                     n->portalname = $4;
    7575           6 :                     n->direction = FETCH_FORWARD;
    7576           6 :                     n->howMany = $2;
    7577           6 :                     $$ = (Node *) n;
    7578             :                 }
    7579             :             | FORWARD ALL opt_from_in cursor_name
    7580             :                 {
    7581          14 :                     FetchStmt *n = makeNode(FetchStmt);
    7582             : 
    7583          14 :                     n->portalname = $4;
    7584          14 :                     n->direction = FETCH_FORWARD;
    7585          14 :                     n->howMany = FETCH_ALL;
    7586          14 :                     $$ = (Node *) n;
    7587             :                 }
    7588             :             | BACKWARD opt_from_in cursor_name
    7589             :                 {
    7590          78 :                     FetchStmt *n = makeNode(FetchStmt);
    7591             : 
    7592          78 :                     n->portalname = $3;
    7593          78 :                     n->direction = FETCH_BACKWARD;
    7594          78 :                     n->howMany = 1;
    7595          78 :                     $$ = (Node *) n;
    7596             :                 }
    7597             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7598             :                 {
    7599         220 :                     FetchStmt *n = makeNode(FetchStmt);
    7600             : 
    7601         220 :                     n->portalname = $4;
    7602         220 :                     n->direction = FETCH_BACKWARD;
    7603         220 :                     n->howMany = $2;
    7604         220 :                     $$ = (Node *) n;
    7605             :                 }
    7606             :             | BACKWARD ALL opt_from_in cursor_name
    7607             :                 {
    7608          90 :                     FetchStmt *n = makeNode(FetchStmt);
    7609             : 
    7610          90 :                     n->portalname = $4;
    7611          90 :                     n->direction = FETCH_BACKWARD;
    7612          90 :                     n->howMany = FETCH_ALL;
    7613          90 :                     $$ = (Node *) n;
    7614             :                 }
    7615             :         ;
    7616             : 
    7617             : from_in:    FROM
    7618             :             | IN_P
    7619             :         ;
    7620             : 
    7621             : opt_from_in:    from_in
    7622             :             | /* EMPTY */
    7623             :         ;
    7624             : 
    7625             : 
    7626             : /*****************************************************************************
    7627             :  *
    7628             :  * GRANT and REVOKE statements
    7629             :  *
    7630             :  *****************************************************************************/
    7631             : 
    7632             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7633             :             opt_grant_grant_option opt_granted_by
    7634             :                 {
    7635       10344 :                     GrantStmt *n = makeNode(GrantStmt);
    7636             : 
    7637       10344 :                     n->is_grant = true;
    7638       10344 :                     n->privileges = $2;
    7639       10344 :                     n->targtype = ($4)->targtype;
    7640       10344 :                     n->objtype = ($4)->objtype;
    7641       10344 :                     n->objects = ($4)->objs;
    7642       10344 :                     n->grantees = $6;
    7643       10344 :                     n->grant_option = $7;
    7644       10344 :                     n->grantor = $8;
    7645       10344 :                     $$ = (Node *) n;
    7646             :                 }
    7647             :         ;
    7648             : 
    7649             : RevokeStmt:
    7650             :             REVOKE privileges ON privilege_target
    7651             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7652             :                 {
    7653        9040 :                     GrantStmt *n = makeNode(GrantStmt);
    7654             : 
    7655        9040 :                     n->is_grant = false;
    7656        9040 :                     n->grant_option = false;
    7657        9040 :                     n->privileges = $2;
    7658        9040 :                     n->targtype = ($4)->targtype;
    7659        9040 :                     n->objtype = ($4)->objtype;
    7660        9040 :                     n->objects = ($4)->objs;
    7661        9040 :                     n->grantees = $6;
    7662        9040 :                     n->grantor = $7;
    7663        9040 :                     n->behavior = $8;
    7664        9040 :                     $$ = (Node *) n;
    7665             :                 }
    7666             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7667             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7668             :                 {
    7669          16 :                     GrantStmt *n = makeNode(GrantStmt);
    7670             : 
    7671          16 :                     n->is_grant = false;
    7672          16 :                     n->grant_option = true;
    7673          16 :                     n->privileges = $5;
    7674          16 :                     n->targtype = ($7)->targtype;
    7675          16 :                     n->objtype = ($7)->objtype;
    7676          16 :                     n->objects = ($7)->objs;
    7677          16 :                     n->grantees = $9;
    7678          16 :                     n->grantor = $10;
    7679          16 :                     n->behavior = $11;
    7680          16 :                     $$ = (Node *) n;
    7681             :                 }
    7682             :         ;
    7683             : 
    7684             : 
    7685             : /*
    7686             :  * Privilege names are represented as strings; the validity of the privilege
    7687             :  * names gets checked at execution.  This is a bit annoying but we have little
    7688             :  * choice because of the syntactic conflict with lists of role names in
    7689             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7690             :  * production any reserved keywords that need to be usable as privilege names.
    7691             :  */
    7692             : 
    7693             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7694             : privileges: privilege_list
    7695       17212 :                 { $$ = $1; }
    7696             :             | ALL
    7697        2222 :                 { $$ = NIL; }
    7698             :             | ALL PRIVILEGES
    7699         120 :                 { $$ = NIL; }
    7700             :             | ALL '(' columnList ')'
    7701             :                 {
    7702          18 :                     AccessPriv *n = makeNode(AccessPriv);
    7703             : 
    7704          18 :                     n->priv_name = NULL;
    7705          18 :                     n->cols = $3;
    7706          18 :                     $$ = list_make1(n);
    7707             :                 }
    7708             :             | ALL PRIVILEGES '(' columnList ')'
    7709             :                 {
    7710           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7711             : 
    7712           0 :                     n->priv_name = NULL;
    7713           0 :                     n->cols = $4;
    7714           0 :                     $$ = list_make1(n);
    7715             :                 }
    7716             :         ;
    7717             : 
    7718       18152 : privilege_list: privilege                           { $$ = list_make1($1); }
    7719         520 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7720             :         ;
    7721             : 
    7722             : privilege:  SELECT opt_column_list
    7723             :             {
    7724        8560 :                 AccessPriv *n = makeNode(AccessPriv);
    7725             : 
    7726        8560 :                 n->priv_name = pstrdup($1);
    7727        8560 :                 n->cols = $2;
    7728        8560 :                 $$ = n;
    7729             :             }
    7730             :         | REFERENCES opt_column_list
    7731             :             {
    7732          14 :                 AccessPriv *n = makeNode(AccessPriv);
    7733             : 
    7734          14 :                 n->priv_name = pstrdup($1);
    7735          14 :                 n->cols = $2;
    7736          14 :                 $$ = n;
    7737             :             }
    7738             :         | CREATE opt_column_list
    7739             :             {
    7740         270 :                 AccessPriv *n = makeNode(AccessPriv);
    7741             : 
    7742         270 :                 n->priv_name = pstrdup($1);
    7743         270 :                 n->cols = $2;
    7744         270 :                 $$ = n;
    7745             :             }
    7746             :         | ALTER SYSTEM_P
    7747             :             {
    7748          24 :                 AccessPriv *n = makeNode(AccessPriv);
    7749          24 :                 n->priv_name = pstrdup("alter system");
    7750          24 :                 n->cols = NIL;
    7751          24 :                 $$ = n;
    7752             :             }
    7753             :         | ColId opt_column_list
    7754             :             {
    7755        9804 :                 AccessPriv *n = makeNode(AccessPriv);
    7756             : 
    7757        9804 :                 n->priv_name = $1;
    7758        9804 :                 n->cols = $2;
    7759        9804 :                 $$ = n;
    7760             :             }
    7761             :         ;
    7762             : 
    7763             : parameter_name_list:
    7764             :         parameter_name
    7765             :             {
    7766          76 :                 $$ = list_make1(makeString($1));
    7767             :             }
    7768             :         | parameter_name_list ',' parameter_name
    7769             :             {
    7770          50 :                 $$ = lappend($1, makeString($3));
    7771             :             }
    7772             :         ;
    7773             : 
    7774             : parameter_name:
    7775             :         ColId
    7776             :             {
    7777         126 :                 $$ = $1;
    7778             :             }
    7779             :         | parameter_name '.' ColId
    7780             :             {
    7781          32 :                 $$ = psprintf("%s.%s", $1, $3);
    7782             :             }
    7783             :         ;
    7784             : 
    7785             : 
    7786             : /* Don't bother trying to fold the first two rules into one using
    7787             :  * opt_table.  You're going to get conflicts.
    7788             :  */
    7789             : privilege_target:
    7790             :             qualified_name_list
    7791             :                 {
    7792       10196 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7793             : 
    7794       10196 :                     n->targtype = ACL_TARGET_OBJECT;
    7795       10196 :                     n->objtype = OBJECT_TABLE;
    7796       10196 :                     n->objs = $1;
    7797       10196 :                     $$ = n;
    7798             :                 }
    7799             :             | TABLE qualified_name_list
    7800             :                 {
    7801         368 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7802             : 
    7803         368 :                     n->targtype = ACL_TARGET_OBJECT;
    7804         368 :                     n->objtype = OBJECT_TABLE;
    7805         368 :                     n->objs = $2;
    7806         368 :                     $$ = n;
    7807             :                 }
    7808             :             | SEQUENCE qualified_name_list
    7809             :                 {
    7810          22 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7811             : 
    7812          22 :                     n->targtype = ACL_TARGET_OBJECT;
    7813          22 :                     n->objtype = OBJECT_SEQUENCE;
    7814          22 :                     n->objs = $2;
    7815          22 :                     $$ = n;
    7816             :                 }
    7817             :             | FOREIGN DATA_P WRAPPER name_list
    7818             :                 {
    7819          92 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7820             : 
    7821          92 :                     n->targtype = ACL_TARGET_OBJECT;
    7822          92 :                     n->objtype = OBJECT_FDW;
    7823          92 :                     n->objs = $4;
    7824          92 :                     $$ = n;
    7825             :                 }
    7826             :             | FOREIGN SERVER name_list
    7827             :                 {
    7828          88 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7829             : 
    7830          88 :                     n->targtype = ACL_TARGET_OBJECT;
    7831          88 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7832          88 :                     n->objs = $3;
    7833          88 :                     $$ = n;
    7834             :                 }
    7835             :             | FUNCTION function_with_argtypes_list
    7836             :                 {
    7837        7564 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7838             : 
    7839        7564 :                     n->targtype = ACL_TARGET_OBJECT;
    7840        7564 :                     n->objtype = OBJECT_FUNCTION;
    7841        7564 :                     n->objs = $2;
    7842        7564 :                     $$ = n;
    7843             :                 }
    7844             :             | PROCEDURE function_with_argtypes_list
    7845             :                 {
    7846          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7847             : 
    7848          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7849          42 :                     n->objtype = OBJECT_PROCEDURE;
    7850          42 :                     n->objs = $2;
    7851          42 :                     $$ = n;
    7852             :                 }
    7853             :             | ROUTINE function_with_argtypes_list
    7854             :                 {
    7855           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7856             : 
    7857           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7858           0 :                     n->objtype = OBJECT_ROUTINE;
    7859           0 :                     n->objs = $2;
    7860           0 :                     $$ = n;
    7861             :                 }
    7862             :             | DATABASE name_list
    7863             :                 {
    7864         326 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7865             : 
    7866         326 :                     n->targtype = ACL_TARGET_OBJECT;
    7867         326 :                     n->objtype = OBJECT_DATABASE;
    7868         326 :                     n->objs = $2;
    7869         326 :                     $$ = n;
    7870             :                 }
    7871             :             | DOMAIN_P any_name_list
    7872             :                 {
    7873          26 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7874             : 
    7875          26 :                     n->targtype = ACL_TARGET_OBJECT;
    7876          26 :                     n->objtype = OBJECT_DOMAIN;
    7877          26 :                     n->objs = $2;
    7878          26 :                     $$ = n;
    7879             :                 }
    7880             :             | LANGUAGE name_list
    7881             :                 {
    7882          42 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7883             : 
    7884          42 :                     n->targtype = ACL_TARGET_OBJECT;
    7885          42 :                     n->objtype = OBJECT_LANGUAGE;
    7886          42 :                     n->objs = $2;
    7887          42 :                     $$ = n;
    7888             :                 }
    7889             :             | LARGE_P OBJECT_P NumericOnly_list
    7890             :                 {
    7891          80 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7892             : 
    7893          80 :                     n->targtype = ACL_TARGET_OBJECT;
    7894          80 :                     n->objtype = OBJECT_LARGEOBJECT;
    7895          80 :                     n->objs = $3;
    7896          80 :                     $$ = n;
    7897             :                 }
    7898             :             | PARAMETER parameter_name_list
    7899             :                 {
    7900          76 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7901          76 :                     n->targtype = ACL_TARGET_OBJECT;
    7902          76 :                     n->objtype = OBJECT_PARAMETER_ACL;
    7903          76 :                     n->objs = $2;
    7904          76 :                     $$ = n;
    7905             :                 }
    7906             :             | SCHEMA name_list
    7907             :                 {
    7908         342 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7909             : 
    7910         342 :                     n->targtype = ACL_TARGET_OBJECT;
    7911         342 :                     n->objtype = OBJECT_SCHEMA;
    7912         342 :                     n->objs = $2;
    7913         342 :                     $$ = n;
    7914             :                 }
    7915             :             | TABLESPACE name_list
    7916             :                 {
    7917           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7918             : 
    7919           6 :                     n->targtype = ACL_TARGET_OBJECT;
    7920           6 :                     n->objtype = OBJECT_TABLESPACE;
    7921           6 :                     n->objs = $2;
    7922           6 :                     $$ = n;
    7923             :                 }
    7924             :             | TYPE_P any_name_list
    7925             :                 {
    7926         112 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7927             : 
    7928         112 :                     n->targtype = ACL_TARGET_OBJECT;
    7929         112 :                     n->objtype = OBJECT_TYPE;
    7930         112 :                     n->objs = $2;
    7931         112 :                     $$ = n;
    7932             :                 }
    7933             :             | ALL TABLES IN_P SCHEMA name_list
    7934             :                 {
    7935          12 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7936             : 
    7937          12 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7938          12 :                     n->objtype = OBJECT_TABLE;
    7939          12 :                     n->objs = $5;
    7940          12 :                     $$ = n;
    7941             :                 }
    7942             :             | ALL SEQUENCES IN_P SCHEMA name_list
    7943             :                 {
    7944           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7945             : 
    7946           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7947           0 :                     n->objtype = OBJECT_SEQUENCE;
    7948           0 :                     n->objs = $5;
    7949           0 :                     $$ = n;
    7950             :                 }
    7951             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    7952             :                 {
    7953           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7954             : 
    7955           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7956           6 :                     n->objtype = OBJECT_FUNCTION;
    7957           6 :                     n->objs = $5;
    7958           6 :                     $$ = n;
    7959             :                 }
    7960             :             | ALL PROCEDURES IN_P SCHEMA name_list
    7961             :                 {
    7962           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7963             : 
    7964           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7965           6 :                     n->objtype = OBJECT_PROCEDURE;
    7966           6 :                     n->objs = $5;
    7967           6 :                     $$ = n;
    7968             :                 }
    7969             :             | ALL ROUTINES IN_P SCHEMA name_list
    7970             :                 {
    7971           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7972             : 
    7973           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7974           6 :                     n->objtype = OBJECT_ROUTINE;
    7975           6 :                     n->objs = $5;
    7976           6 :                     $$ = n;
    7977             :                 }
    7978             :         ;
    7979             : 
    7980             : 
    7981             : grantee_list:
    7982       19560 :             grantee                                 { $$ = list_make1($1); }
    7983         108 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    7984             :         ;
    7985             : 
    7986             : grantee:
    7987       19644 :             RoleSpec                                { $$ = $1; }
    7988          24 :             | GROUP_P RoleSpec                      { $$ = $2; }
    7989             :         ;
    7990             : 
    7991             : 
    7992             : opt_grant_grant_option:
    7993         102 :             WITH GRANT OPTION { $$ = true; }
    7994       10342 :             | /*EMPTY*/ { $$ = false; }
    7995             :         ;
    7996             : 
    7997             : /*****************************************************************************
    7998             :  *
    7999             :  * GRANT and REVOKE ROLE statements
    8000             :  *
    8001             :  *****************************************************************************/
    8002             : 
    8003             : GrantRoleStmt:
    8004             :             GRANT privilege_list TO role_list opt_granted_by
    8005             :                 {
    8006         606 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8007             : 
    8008         606 :                     n->is_grant = true;
    8009         606 :                     n->granted_roles = $2;
    8010         606 :                     n->grantee_roles = $4;
    8011         606 :                     n->opt = NIL;
    8012         606 :                     n->grantor = $5;
    8013         606 :                     $$ = (Node *) n;
    8014             :                 }
    8015             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    8016             :                 {
    8017         178 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8018             : 
    8019         178 :                     n->is_grant = true;
    8020         178 :                     n->granted_roles = $2;
    8021         178 :                     n->grantee_roles = $4;
    8022         178 :                     n->opt = $6;
    8023         178 :                     n->grantor = $7;
    8024         178 :                     $$ = (Node *) n;
    8025             :                 }
    8026             :         ;
    8027             : 
    8028             : RevokeRoleStmt:
    8029             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8030             :                 {
    8031          90 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8032             : 
    8033          90 :                     n->is_grant = false;
    8034          90 :                     n->opt = NIL;
    8035          90 :                     n->granted_roles = $2;
    8036          90 :                     n->grantee_roles = $4;
    8037          90 :                     n->grantor = $5;
    8038          90 :                     n->behavior = $6;
    8039          90 :                     $$ = (Node *) n;
    8040             :                 }
    8041             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8042             :                 {
    8043          66 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8044             :                     DefElem *opt;
    8045             : 
    8046          66 :                     opt = makeDefElem(pstrdup($2),
    8047          66 :                                       (Node *) makeBoolean(false), @2);
    8048          66 :                     n->is_grant = false;
    8049          66 :                     n->opt = list_make1(opt);
    8050          66 :                     n->granted_roles = $5;
    8051          66 :                     n->grantee_roles = $7;
    8052          66 :                     n->grantor = $8;
    8053          66 :                     n->behavior = $9;
    8054          66 :                     $$ = (Node *) n;
    8055             :                 }
    8056             :         ;
    8057             : 
    8058             : grant_role_opt_list:
    8059         120 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8060         178 :             | grant_role_opt                        { $$ = list_make1($1); }
    8061             :         ;
    8062             : 
    8063             : grant_role_opt:
    8064             :         ColLabel grant_role_opt_value
    8065             :             {
    8066         298 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8067             :             }
    8068             :         ;
    8069             : 
    8070             : grant_role_opt_value:
    8071          72 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8072         112 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8073         114 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8074             :         ;
    8075             : 
    8076         138 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8077       20202 :             | /*EMPTY*/                                 { $$ = NULL; }
    8078             :         ;
    8079             : 
    8080             : /*****************************************************************************
    8081             :  *
    8082             :  * ALTER DEFAULT PRIVILEGES statement
    8083             :  *
    8084             :  *****************************************************************************/
    8085             : 
    8086             : AlterDefaultPrivilegesStmt:
    8087             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8088             :                 {
    8089         160 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8090             : 
    8091         160 :                     n->options = $4;
    8092         160 :                     n->action = (GrantStmt *) $5;
    8093         160 :                     $$ = (Node *) n;
    8094             :                 }
    8095             :         ;
    8096             : 
    8097             : DefACLOptionList:
    8098         122 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8099         160 :             | /* EMPTY */                           { $$ = NIL; }
    8100             :         ;
    8101             : 
    8102             : DefACLOption:
    8103             :             IN_P SCHEMA name_list
    8104             :                 {
    8105          54 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8106             :                 }
    8107             :             | FOR ROLE role_list
    8108             :                 {
    8109          68 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8110             :                 }
    8111             :             | FOR USER role_list
    8112             :                 {
    8113           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8114             :                 }
    8115             :         ;
    8116             : 
    8117             : /*
    8118             :  * This should match GRANT/REVOKE, except that individual target objects
    8119             :  * are not mentioned and we only allow a subset of object types.
    8120             :  */
    8121             : DefACLAction:
    8122             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8123             :             opt_grant_grant_option
    8124             :                 {
    8125         100 :                     GrantStmt *n = makeNode(GrantStmt);
    8126             : 
    8127         100 :                     n->is_grant = true;
    8128         100 :                     n->privileges = $2;
    8129         100 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8130         100 :                     n->objtype = $4;
    8131         100 :                     n->objects = NIL;
    8132         100 :                     n->grantees = $6;
    8133         100 :                     n->grant_option = $7;
    8134         100 :                     $$ = (Node *) n;
    8135             :                 }
    8136             :             | REVOKE privileges ON defacl_privilege_target
    8137             :             FROM grantee_list opt_drop_behavior
    8138             :                 {
    8139          60 :                     GrantStmt *n = makeNode(GrantStmt);
    8140             : 
    8141          60 :                     n->is_grant = false;
    8142          60 :                     n->grant_option = false;
    8143          60 :                     n->privileges = $2;
    8144          60 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8145          60 :                     n->objtype = $4;
    8146          60 :                     n->objects = NIL;
    8147          60 :                     n->grantees = $6;
    8148          60 :                     n->behavior = $7;
    8149          60 :                     $$ = (Node *) n;
    8150             :                 }
    8151             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8152             :             FROM grantee_list opt_drop_behavior
    8153             :                 {
    8154           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8155             : 
    8156           0 :                     n->is_grant = false;
    8157           0 :                     n->grant_option = true;
    8158           0 :                     n->privileges = $5;
    8159           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8160           0 :                     n->objtype = $7;
    8161           0 :                     n->objects = NIL;
    8162           0 :                     n->grantees = $9;
    8163           0 :                     n->behavior = $10;
    8164           0 :                     $$ = (Node *) n;
    8165             :                 }
    8166             :         ;
    8167             : 
    8168             : defacl_privilege_target:
    8169          78 :             TABLES          { $$ = OBJECT_TABLE; }
    8170          16 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8171           6 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8172           6 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8173          18 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8174          36 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8175             :         ;
    8176             : 
    8177             : 
    8178             : /*****************************************************************************
    8179             :  *
    8180             :  *      QUERY: CREATE INDEX
    8181             :  *
    8182             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8183             :  * willing to make TABLESPACE a fully reserved word.
    8184             :  *****************************************************************************/
    8185             : 
    8186             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8187             :             ON relation_expr access_method_clause '(' index_params ')'
    8188             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8189             :                 {
    8190        6626 :                     IndexStmt *n = makeNode(IndexStmt);
    8191             : 
    8192        6626 :                     n->unique = $2;
    8193        6626 :                     n->concurrent = $4;
    8194        6626 :                     n->idxname = $5;
    8195        6626 :                     n->relation = $7;
    8196        6626 :                     n->accessMethod = $8;
    8197        6626 :                     n->indexParams = $10;
    8198        6626 :                     n->indexIncludingParams = $12;
    8199        6626 :                     n->nulls_not_distinct = !$13;
    8200        6626 :                     n->options = $14;
    8201        6626 :                     n->tableSpace = $15;
    8202        6626 :                     n->whereClause = $16;
    8203        6626 :                     n->excludeOpNames = NIL;
    8204        6626 :                     n->idxcomment = NULL;
    8205        6626 :                     n->indexOid = InvalidOid;
    8206        6626 :                     n->oldNumber = InvalidRelFileNumber;
    8207        6626 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8208        6626 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8209        6626 :                     n->primary = false;
    8210        6626 :                     n->isconstraint = false;
    8211        6626 :                     n->deferrable = false;
    8212        6626 :                     n->initdeferred = false;
    8213        6626 :                     n->transformed = false;
    8214        6626 :                     n->if_not_exists = false;
    8215        6626 :                     n->reset_default_tblspc = false;
    8216        6626 :                     $$ = (Node *) n;
    8217             :                 }
    8218             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8219             :             ON relation_expr access_method_clause '(' index_params ')'
    8220             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8221             :                 {
    8222          18 :                     IndexStmt *n = makeNode(IndexStmt);
    8223             : 
    8224          18 :                     n->unique = $2;
    8225          18 :                     n->concurrent = $4;
    8226          18 :                     n->idxname = $8;
    8227          18 :                     n->relation = $10;
    8228          18 :                     n->accessMethod = $11;
    8229          18 :                     n->indexParams = $13;
    8230          18 :                     n->indexIncludingParams = $15;
    8231          18 :                     n->nulls_not_distinct = !$16;
    8232          18 :                     n->options = $17;
    8233          18 :                     n->tableSpace = $18;
    8234          18 :                     n->whereClause = $19;
    8235          18 :                     n->excludeOpNames = NIL;
    8236          18 :                     n->idxcomment = NULL;
    8237          18 :                     n->indexOid = InvalidOid;
    8238          18 :                     n->oldNumber = InvalidRelFileNumber;
    8239          18 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8240          18 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8241          18 :                     n->primary = false;
    8242          18 :                     n->isconstraint = false;
    8243          18 :                     n->deferrable = false;
    8244          18 :                     n->initdeferred = false;
    8245          18 :                     n->transformed = false;
    8246          18 :                     n->if_not_exists = true;
    8247          18 :                     n->reset_default_tblspc = false;
    8248          18 :                     $$ = (Node *) n;
    8249             :                 }
    8250             :         ;
    8251             : 
    8252             : opt_unique:
    8253        1298 :             UNIQUE                                  { $$ = true; }
    8254        5352 :             | /*EMPTY*/                             { $$ = false; }
    8255             :         ;
    8256             : 
    8257             : access_method_clause:
    8258        3014 :             USING name                              { $$ = $2; }
    8259        3864 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8260             :         ;
    8261             : 
    8262        8074 : index_params:   index_elem                          { $$ = list_make1($1); }
    8263        2154 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8264             :         ;
    8265             : 
    8266             : 
    8267             : index_elem_options:
    8268             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8269             :         {
    8270       10810 :             $$ = makeNode(IndexElem);
    8271       10810 :             $$->name = NULL;
    8272       10810 :             $$->expr = NULL;
    8273       10810 :             $$->indexcolname = NULL;
    8274       10810 :             $$->collation = $1;
    8275       10810 :             $$->opclass = $2;
    8276       10810 :             $$->opclassopts = NIL;
    8277       10810 :             $$->ordering = $3;
    8278       10810 :             $$->nulls_ordering = $4;
    8279             :         }
    8280             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8281             :         {
    8282         142 :             $$ = makeNode(IndexElem);
    8283         142 :             $$->name = NULL;
    8284         142 :             $$->expr = NULL;
    8285         142 :             $$->indexcolname = NULL;
    8286         142 :             $$->collation = $1;
    8287         142 :             $$->opclass = $2;
    8288         142 :             $$->opclassopts = $3;
    8289         142 :             $$->ordering = $4;
    8290         142 :             $$->nulls_ordering = $5;
    8291             :         }
    8292             :     ;
    8293             : 
    8294             : /*
    8295             :  * Index attributes can be either simple column references, or arbitrary
    8296             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8297             :  * an expression that's just a function call to be written without parens.
    8298             :  */
    8299             : index_elem: ColId index_elem_options
    8300             :                 {
    8301        9862 :                     $$ = $2;
    8302        9862 :                     $$->name = $1;
    8303             :                 }
    8304             :             | func_expr_windowless index_elem_options
    8305             :                 {
    8306         610 :                     $$ = $2;
    8307         610 :                     $$->expr = $1;
    8308             :                 }
    8309             :             | '(' a_expr ')' index_elem_options
    8310             :                 {
    8311         480 :                     $$ = $4;
    8312         480 :                     $$->expr = $2;
    8313             :                 }
    8314             :         ;
    8315             : 
    8316         218 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8317        6426 :              |      /* EMPTY */                     { $$ = NIL; }
    8318             :         ;
    8319             : 
    8320         218 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8321         166 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8322             :         ;
    8323             : 
    8324         192 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8325       16144 :             | /*EMPTY*/                             { $$ = NIL; }
    8326             :         ;
    8327             : 
    8328             : 
    8329        1810 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8330        2998 :             | DESC                          { $$ = SORTBY_DESC; }
    8331      105868 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8332             :         ;
    8333             : 
    8334         346 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8335        1732 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8336      108818 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8337             :         ;
    8338             : 
    8339             : 
    8340             : /*****************************************************************************
    8341             :  *
    8342             :  *      QUERY:
    8343             :  *              create [or replace] function <fname>
    8344             :  *                      [(<type-1> { , <type-n>})]
    8345             :  *                      returns <type-r>
    8346             :  *                      as <filename or code in language as appropriate>
    8347             :  *                      language <lang> [with parameters]
    8348             :  *
    8349             :  *****************************************************************************/
    8350             : 
    8351             : CreateFunctionStmt:
    8352             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8353             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8354             :                 {
    8355       21882 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8356             : 
    8357       21882 :                     n->is_procedure = false;
    8358       21882 :                     n->replace = $2;
    8359       21882 :                     n->funcname = $4;
    8360       21882 :                     n->parameters = $5;
    8361       21882 :                     n->returnType = $7;
    8362       21882 :                     n->options = $8;
    8363       21882 :                     n->sql_body = $9;
    8364       21882 :                     $$ = (Node *) n;
    8365             :                 }
    8366             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8367             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8368             :                 {
    8369         188 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8370             : 
    8371         188 :                     n->is_procedure = false;
    8372         188 :                     n->replace = $2;
    8373         188 :                     n->funcname = $4;
    8374         188 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8375         188 :                     n->returnType = TableFuncTypeName($9);
    8376         188 :                     n->returnType->location = @7;
    8377         188 :                     n->options = $11;
    8378         188 :                     n->sql_body = $12;
    8379         188 :                     $$ = (Node *) n;
    8380             :                 }
    8381             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8382             :               opt_createfunc_opt_list opt_routine_body
    8383             :                 {
    8384         482 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8385             : 
    8386         482 :                     n->is_procedure = false;
    8387         482 :                     n->replace = $2;
    8388         482 :                     n->funcname = $4;
    8389         482 :                     n->parameters = $5;
    8390         482 :                     n->returnType = NULL;
    8391         482 :                     n->options = $6;
    8392         482 :                     n->sql_body = $7;
    8393         482 :                     $$ = (Node *) n;
    8394             :                 }
    8395             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8396             :               opt_createfunc_opt_list opt_routine_body
    8397             :                 {
    8398         368 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8399             : 
    8400         368 :                     n->is_procedure = true;
    8401         368 :                     n->replace = $2;
    8402         368 :                     n->funcname = $4;
    8403         368 :                     n->parameters = $5;
    8404         368 :                     n->returnType = NULL;
    8405         368 :                     n->options = $6;
    8406         368 :                     n->sql_body = $7;
    8407         368 :                     $$ = (Node *) n;
    8408             :                 }
    8409             :         ;
    8410             : 
    8411             : opt_or_replace:
    8412        9156 :             OR REPLACE                              { $$ = true; }
    8413       19168 :             | /*EMPTY*/                             { $$ = false; }
    8414             :         ;
    8415             : 
    8416        9466 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8417        4964 :             | '(' ')'                               { $$ = NIL; }
    8418             :         ;
    8419             : 
    8420             : func_args_list:
    8421        9466 :             func_arg                                { $$ = list_make1($1); }
    8422        7852 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8423             :         ;
    8424             : 
    8425             : function_with_argtypes_list:
    8426       11282 :             function_with_argtypes                  { $$ = list_make1($1); }
    8427             :             | function_with_argtypes_list ',' function_with_argtypes
    8428          84 :                                                     { $$ = lappend($1, $3); }
    8429             :         ;
    8430             : 
    8431             : function_with_argtypes:
    8432             :             func_name func_args
    8433             :                 {
    8434       14430 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8435             : 
    8436       14430 :                     n->objname = $1;
    8437       14430 :                     n->objargs = extractArgTypes($2);
    8438       14430 :                     n->objfuncargs = $2;
    8439       14430 :                     $$ = n;
    8440             :                 }
    8441             :             /*
    8442             :              * Because of reduce/reduce conflicts, we can't use func_name
    8443             :              * below, but we can write it out the long way, which actually
    8444             :              * allows more cases.
    8445             :              */
    8446             :             | type_func_name_keyword
    8447             :                 {
    8448           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8449             : 
    8450           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8451           0 :                     n->args_unspecified = true;
    8452           0 :                     $$ = n;
    8453             :                 }
    8454             :             | ColId
    8455             :                 {
    8456         346 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8457             : 
    8458         346 :                     n->objname = list_make1(makeString($1));
    8459         346 :                     n->args_unspecified = true;
    8460         346 :                     $$ = n;
    8461             :                 }
    8462             :             | ColId indirection
    8463             :                 {
    8464          28 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8465             : 
    8466          28 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8467             :                                                   yyscanner);
    8468          28 :                     n->args_unspecified = true;
    8469          28 :                     $$ = n;
    8470             :                 }
    8471             :         ;
    8472             : 
    8473             : /*
    8474             :  * func_args_with_defaults is separate because we only want to accept
    8475             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8476             :  */
    8477             : func_args_with_defaults:
    8478       18526 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8479        4394 :         | '(' ')'                                   { $$ = NIL; }
    8480             :         ;
    8481             : 
    8482             : func_args_with_defaults_list:
    8483       18526 :         func_arg_with_default                       { $$ = list_make1($1); }
    8484             :         | func_args_with_defaults_list ',' func_arg_with_default
    8485       31202 :                                                     { $$ = lappend($1, $3); }
    8486             :         ;
    8487             : 
    8488             : /*
    8489             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8490             :  * param_name first; accept both since it's likely people will try both
    8491             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8492             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8493             :  *
    8494             :  * We can catch over-specified arguments here if we want to,
    8495             :  * but for now better to silently swallow typmod, etc.
    8496             :  * - thomas 2000-03-22
    8497             :  */
    8498             : func_arg:
    8499             :             arg_class param_name func_type
    8500             :                 {
    8501       15270 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8502             : 
    8503       15270 :                     n->name = $2;
    8504       15270 :                     n->argType = $3;
    8505       15270 :                     n->mode = $1;
    8506       15270 :                     n->defexpr = NULL;
    8507       15270 :                     n->location = @1;
    8508       15270 :                     $$ = n;
    8509             :                 }
    8510             :             | param_name arg_class func_type
    8511             :                 {
    8512         412 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8513             : 
    8514         412 :                     n->name = $1;
    8515         412 :                     n->argType = $3;
    8516         412 :                     n->mode = $2;
    8517         412 :                     n->defexpr = NULL;
    8518         412 :                     n->location = @1;
    8519         412 :                     $$ = n;
    8520             :                 }
    8521             :             | param_name func_type
    8522             :                 {
    8523       14256 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8524             : 
    8525       14256 :                     n->name = $1;
    8526       14256 :                     n->argType = $2;
    8527       14256 :                     n->mode = FUNC_PARAM_DEFAULT;
    8528       14256 :                     n->defexpr = NULL;
    8529       14256 :                     n->location = @1;
    8530       14256 :                     $$ = n;
    8531             :                 }
    8532             :             | arg_class func_type
    8533             :                 {
    8534         314 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8535             : 
    8536         314 :                     n->name = NULL;
    8537         314 :                     n->argType = $2;
    8538         314 :                     n->mode = $1;
    8539         314 :                     n->defexpr = NULL;
    8540         314 :                     n->location = @1;
    8541         314 :                     $$ = n;
    8542             :                 }
    8543             :             | func_type
    8544             :                 {
    8545       37694 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8546             : 
    8547       37694 :                     n->name = NULL;
    8548       37694 :                     n->argType = $1;
    8549       37694 :                     n->mode = FUNC_PARAM_DEFAULT;
    8550       37694 :                     n->defexpr = NULL;
    8551       37694 :                     n->location = @1;
    8552       37694 :                     $$ = n;
    8553             :                 }
    8554             :         ;
    8555             : 
    8556             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8557        3604 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8558       11668 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8559         198 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8560           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8561         526 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8562             :         ;
    8563             : 
    8564             : /*
    8565             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8566             :  */
    8567             : param_name: type_function_name
    8568             :         ;
    8569             : 
    8570             : func_return:
    8571             :             func_type
    8572             :                 {
    8573             :                     /* We can catch over-specified results here if we want to,
    8574             :                      * but for now better to silently swallow typmod, etc.
    8575             :                      * - thomas 2000-03-22
    8576             :                      */
    8577       21882 :                     $$ = $1;
    8578             :                 }
    8579             :         ;
    8580             : 
    8581             : /*
    8582             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8583             :  * but that causes reduce/reduce conflicts.  type_function_name
    8584             :  * is next best choice.
    8585             :  */
    8586      110018 : func_type:  Typename                                { $$ = $1; }
    8587             :             | type_function_name attrs '%' TYPE_P
    8588             :                 {
    8589          18 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8590          18 :                     $$->pct_type = true;
    8591          18 :                     $$->location = @1;
    8592             :                 }
    8593             :             | SETOF type_function_name attrs '%' TYPE_P
    8594             :                 {
    8595           6 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8596           6 :                     $$->pct_type = true;
    8597           6 :                     $$->setof = true;
    8598           6 :                     $$->location = @2;
    8599             :                 }
    8600             :         ;
    8601             : 
    8602             : func_arg_with_default:
    8603             :         func_arg
    8604             :                 {
    8605       44088 :                     $$ = $1;
    8606             :                 }
    8607             :         | func_arg DEFAULT a_expr
    8608             :                 {
    8609        5444 :                     $$ = $1;
    8610        5444 :                     $$->defexpr = $3;
    8611             :                 }
    8612             :         | func_arg '=' a_expr
    8613             :                 {
    8614         196 :                     $$ = $1;
    8615         196 :                     $$->defexpr = $3;
    8616             :                 }
    8617             :         ;
    8618             : 
    8619             : /* Aggregate args can be most things that function args can be */
    8620             : aggr_arg:   func_arg
    8621             :                 {
    8622         900 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8623          60 :                           $1->mode == FUNC_PARAM_IN ||
    8624          60 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8625           0 :                         ereport(ERROR,
    8626             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8627             :                                  errmsg("aggregates cannot have output arguments"),
    8628             :                                  parser_errposition(@1)));
    8629         900 :                     $$ = $1;
    8630             :                 }
    8631             :         ;
    8632             : 
    8633             : /*
    8634             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8635             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8636             :  *
    8637             :  * (*)                                  - normal agg with no args
    8638             :  * (aggr_arg,...)                       - normal agg with args
    8639             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8640             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8641             :  *
    8642             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8643             :  *
    8644             :  * An additional restriction is that if the direct-args list ends in a
    8645             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8646             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8647             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8648             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8649             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8650             :  * in cases such as DROP AGGREGATE.
    8651             :  *
    8652             :  * The return value of this production is a two-element list, in which the
    8653             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8654             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8655             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8656             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8657             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8658             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8659             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8660             :  * sublist.
    8661             :  */
    8662             : aggr_args:  '(' '*' ')'
    8663             :                 {
    8664         136 :                     $$ = list_make2(NIL, makeInteger(-1));
    8665             :                 }
    8666             :             | '(' aggr_args_list ')'
    8667             :                 {
    8668         732 :                     $$ = list_make2($2, makeInteger(-1));
    8669             :                 }
    8670             :             | '(' ORDER BY aggr_args_list ')'
    8671             :                 {
    8672           6 :                     $$ = list_make2($4, makeInteger(0));
    8673             :                 }
    8674             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8675             :                 {
    8676             :                     /* this is the only case requiring consistency checking */
    8677          32 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8678             :                 }
    8679             :         ;
    8680             : 
    8681             : aggr_args_list:
    8682         802 :             aggr_arg                                { $$ = list_make1($1); }
    8683          98 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8684             :         ;
    8685             : 
    8686             : aggregate_with_argtypes:
    8687             :             func_name aggr_args
    8688             :                 {
    8689         362 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8690             : 
    8691         362 :                     n->objname = $1;
    8692         362 :                     n->objargs = extractAggrArgTypes($2);
    8693         362 :                     n->objfuncargs = (List *) linitial($2);
    8694         362 :                     $$ = n;
    8695             :                 }
    8696             :         ;
    8697             : 
    8698             : aggregate_with_argtypes_list:
    8699         104 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8700             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8701           0 :                                                     { $$ = lappend($1, $3); }
    8702             :         ;
    8703             : 
    8704             : opt_createfunc_opt_list:
    8705             :             createfunc_opt_list
    8706          48 :             | /*EMPTY*/ { $$ = NIL; }
    8707             :     ;
    8708             : 
    8709             : createfunc_opt_list:
    8710             :             /* Must be at least one to prevent conflict */
    8711       22872 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8712       59668 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8713             :     ;
    8714             : 
    8715             : /*
    8716             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8717             :  */
    8718             : common_func_opt_item:
    8719             :             CALLED ON NULL_P INPUT_P
    8720             :                 {
    8721         342 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8722             :                 }
    8723             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8724             :                 {
    8725         792 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8726             :                 }
    8727             :             | STRICT_P
    8728             :                 {
    8729       11782 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8730             :                 }
    8731             :             | IMMUTABLE
    8732             :                 {
    8733        8600 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8734             :                 }
    8735             :             | STABLE
    8736             :                 {
    8737        2294 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8738             :                 }
    8739             :             | VOLATILE
    8740             :                 {
    8741        1518 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8742             :                 }
    8743             :             | EXTERNAL SECURITY DEFINER
    8744             :                 {
    8745           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8746             :                 }
    8747             :             | EXTERNAL SECURITY INVOKER
    8748             :                 {
    8749           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8750             :                 }
    8751             :             | SECURITY DEFINER
    8752             :                 {
    8753          58 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8754             :                 }
    8755             :             | SECURITY INVOKER
    8756             :                 {
    8757          18 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8758             :                 }
    8759             :             | LEAKPROOF
    8760             :                 {
    8761          46 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8762             :                 }
    8763             :             | NOT LEAKPROOF
    8764             :                 {
    8765          12 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8766             :                 }
    8767             :             | COST NumericOnly
    8768             :                 {
    8769        3908 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8770             :                 }
    8771             :             | ROWS NumericOnly
    8772             :                 {
    8773         540 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8774             :                 }
    8775             :             | SUPPORT any_name
    8776             :                 {
    8777         104 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8778             :                 }
    8779             :             | FunctionSetResetClause
    8780             :                 {
    8781             :                     /* we abuse the normal content of a DefElem here */
    8782         146 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8783             :                 }
    8784             :             | PARALLEL ColId
    8785             :                 {
    8786       12254 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8787             :                 }
    8788             :         ;
    8789             : 
    8790             : createfunc_opt_item:
    8791             :             AS func_as
    8792             :                 {
    8793       17812 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8794             :                 }
    8795             :             | LANGUAGE NonReservedWord_or_Sconst
    8796             :                 {
    8797       22852 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8798             :                 }
    8799             :             | TRANSFORM transform_type_list
    8800             :                 {
    8801         118 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8802             :                 }
    8803             :             | WINDOW
    8804             :                 {
    8805          20 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8806             :                 }
    8807             :             | common_func_opt_item
    8808             :                 {
    8809       41738 :                     $$ = $1;
    8810             :                 }
    8811             :         ;
    8812             : 
    8813       14774 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8814             :             | Sconst ',' Sconst
    8815             :                 {
    8816        3038 :                     $$ = list_make2(makeString($1), makeString($3));
    8817             :                 }
    8818             :         ;
    8819             : 
    8820             : ReturnStmt: RETURN a_expr
    8821             :                 {
    8822        4388 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8823             : 
    8824        4388 :                     r->returnval = (Node *) $2;
    8825        4388 :                     $$ = (Node *) r;
    8826             :                 }
    8827             :         ;
    8828             : 
    8829             : opt_routine_body:
    8830             :             ReturnStmt
    8831             :                 {
    8832        4382 :                     $$ = $1;
    8833             :                 }
    8834             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8835             :                 {
    8836             :                     /*
    8837             :                      * A compound statement is stored as a single-item list
    8838             :                      * containing the list of statements as its member.  That
    8839             :                      * way, the parse analysis code can tell apart an empty
    8840             :                      * body from no body at all.
    8841             :                      */
    8842         732 :                     $$ = (Node *) list_make1($3);
    8843             :                 }
    8844             :             | /*EMPTY*/
    8845             :                 {
    8846       17806 :                     $$ = NULL;
    8847             :                 }
    8848             :         ;
    8849             : 
    8850             : routine_body_stmt_list:
    8851             :             routine_body_stmt_list routine_body_stmt ';'
    8852             :                 {
    8853             :                     /* As in stmtmulti, discard empty statements */
    8854         748 :                     if ($2 != NULL)
    8855         730 :                         $$ = lappend($1, $2);
    8856             :                     else
    8857          18 :                         $$ = $1;
    8858             :                 }
    8859             :             | /*EMPTY*/
    8860             :                 {
    8861         732 :                     $$ = NIL;
    8862             :                 }
    8863             :         ;
    8864             : 
    8865             : routine_body_stmt:
    8866             :             stmt
    8867             :             | ReturnStmt
    8868             :         ;
    8869             : 
    8870             : transform_type_list:
    8871         118 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8872           4 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8873             :         ;
    8874             : 
    8875             : opt_definition:
    8876         606 :             WITH definition                         { $$ = $2; }
    8877        9966 :             | /*EMPTY*/                             { $$ = NIL; }
    8878             :         ;
    8879             : 
    8880             : table_func_column:  param_name func_type
    8881             :                 {
    8882         442 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8883             : 
    8884         442 :                     n->name = $1;
    8885         442 :                     n->argType = $2;
    8886         442 :                     n->mode = FUNC_PARAM_TABLE;
    8887         442 :                     n->defexpr = NULL;
    8888         442 :                     n->location = @1;
    8889         442 :                     $$ = n;
    8890             :                 }
    8891             :         ;
    8892             : 
    8893             : table_func_column_list:
    8894             :             table_func_column
    8895             :                 {
    8896         188 :                     $$ = list_make1($1);
    8897             :                 }
    8898             :             | table_func_column_list ',' table_func_column
    8899             :                 {
    8900         254 :                     $$ = lappend($1, $3);
    8901             :                 }
    8902             :         ;
    8903             : 
    8904             : /*****************************************************************************
    8905             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    8906             :  *
    8907             :  * RENAME and OWNER subcommands are already provided by the generic
    8908             :  * ALTER infrastructure, here we just specify alterations that can
    8909             :  * only be applied to functions.
    8910             :  *
    8911             :  *****************************************************************************/
    8912             : AlterFunctionStmt:
    8913             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    8914             :                 {
    8915         654 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8916             : 
    8917         654 :                     n->objtype = OBJECT_FUNCTION;
    8918         654 :                     n->func = $3;
    8919         654 :                     n->actions = $4;
    8920         654 :                     $$ = (Node *) n;
    8921             :                 }
    8922             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    8923             :                 {
    8924          18 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8925             : 
    8926          18 :                     n->objtype = OBJECT_PROCEDURE;
    8927          18 :                     n->func = $3;
    8928          18 :                     n->actions = $4;
    8929          18 :                     $$ = (Node *) n;
    8930             :                 }
    8931             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    8932             :                 {
    8933           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8934             : 
    8935           0 :                     n->objtype = OBJECT_ROUTINE;
    8936           0 :                     n->func = $3;
    8937           0 :                     n->actions = $4;
    8938           0 :                     $$ = (Node *) n;
    8939             :                 }
    8940             :         ;
    8941             : 
    8942             : alterfunc_opt_list:
    8943             :             /* At least one option must be specified */
    8944         672 :             common_func_opt_item                    { $$ = list_make1($1); }
    8945           4 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    8946             :         ;
    8947             : 
    8948             : /* Ignored, merely for SQL compliance */
    8949             : opt_restrict:
    8950             :             RESTRICT
    8951             :             | /* EMPTY */
    8952             :         ;
    8953             : 
    8954             : 
    8955             : /*****************************************************************************
    8956             :  *
    8957             :  *      QUERY:
    8958             :  *
    8959             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8960             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8961             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8962             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    8963             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    8964             :  *
    8965             :  *****************************************************************************/
    8966             : 
    8967             : RemoveFuncStmt:
    8968             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    8969             :                 {
    8970        3254 :                     DropStmt *n = makeNode(DropStmt);
    8971             : 
    8972        3254 :                     n->removeType = OBJECT_FUNCTION;
    8973        3254 :                     n->objects = $3;
    8974        3254 :                     n->behavior = $4;
    8975        3254 :                     n->missing_ok = false;
    8976        3254 :                     n->concurrent = false;
    8977        3254 :                     $$ = (Node *) n;
    8978             :                 }
    8979             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8980             :                 {
    8981         260 :                     DropStmt *n = makeNode(DropStmt);
    8982             : 
    8983         260 :                     n->removeType = OBJECT_FUNCTION;
    8984         260 :                     n->objects = $5;
    8985         260 :                     n->behavior = $6;
    8986         260 :                     n->missing_ok = true;
    8987         260 :                     n->concurrent = false;
    8988         260 :                     $$ = (Node *) n;
    8989             :                 }
    8990             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    8991             :                 {
    8992         138 :                     DropStmt *n = makeNode(DropStmt);
    8993             : 
    8994         138 :                     n->removeType = OBJECT_PROCEDURE;
    8995         138 :                     n->objects = $3;
    8996         138 :                     n->behavior = $4;
    8997         138 :                     n->missing_ok = false;
    8998         138 :                     n->concurrent = false;
    8999         138 :                     $$ = (Node *) n;
    9000             :                 }
    9001             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9002             :                 {
    9003           6 :                     DropStmt *n = makeNode(DropStmt);
    9004             : 
    9005           6 :                     n->removeType = OBJECT_PROCEDURE;
    9006           6 :                     n->objects = $5;
    9007           6 :                     n->behavior = $6;
    9008           6 :                     n->missing_ok = true;
    9009           6 :                     n->concurrent = false;
    9010           6 :                     $$ = (Node *) n;
    9011             :                 }
    9012             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    9013             :                 {
    9014          12 :                     DropStmt *n = makeNode(DropStmt);
    9015             : 
    9016          12 :                     n->removeType = OBJECT_ROUTINE;
    9017          12 :                     n->objects = $3;
    9018          12 :                     n->behavior = $4;
    9019          12 :                     n->missing_ok = false;
    9020          12 :                     n->concurrent = false;
    9021          12 :                     $$ = (Node *) n;
    9022             :                 }
    9023             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9024             :                 {
    9025           6 :                     DropStmt *n = makeNode(DropStmt);
    9026             : 
    9027           6 :                     n->removeType = OBJECT_ROUTINE;
    9028           6 :                     n->objects = $5;
    9029           6 :                     n->behavior = $6;
    9030           6 :                     n->missing_ok = true;
    9031           6 :                     n->concurrent = false;
    9032           6 :                     $$ = (Node *) n;
    9033             :                 }
    9034             :         ;
    9035             : 
    9036             : RemoveAggrStmt:
    9037             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9038             :                 {
    9039          74 :                     DropStmt *n = makeNode(DropStmt);
    9040             : 
    9041          74 :                     n->removeType = OBJECT_AGGREGATE;
    9042          74 :                     n->objects = $3;
    9043          74 :                     n->behavior = $4;
    9044          74 :                     n->missing_ok = false;
    9045          74 :                     n->concurrent = false;
    9046          74 :                     $$ = (Node *) n;
    9047             :                 }
    9048             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9049             :                 {
    9050          30 :                     DropStmt *n = makeNode(DropStmt);
    9051             : 
    9052          30 :                     n->removeType = OBJECT_AGGREGATE;
    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             : RemoveOperStmt:
    9062             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9063             :                 {
    9064         194 :                     DropStmt *n = makeNode(DropStmt);
    9065             : 
    9066         194 :                     n->removeType = OBJECT_OPERATOR;
    9067         194 :                     n->objects = $3;
    9068         194 :                     n->behavior = $4;
    9069         194 :                     n->missing_ok = false;
    9070         194 :                     n->concurrent = false;
    9071         194 :                     $$ = (Node *) n;
    9072             :                 }
    9073             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9074             :                 {
    9075          30 :                     DropStmt *n = makeNode(DropStmt);
    9076             : 
    9077          30 :                     n->removeType = OBJECT_OPERATOR;
    9078          30 :                     n->objects = $5;
    9079          30 :                     n->behavior = $6;
    9080          30 :                     n->missing_ok = true;
    9081          30 :                     n->concurrent = false;
    9082          30 :                     $$ = (Node *) n;
    9083             :                 }
    9084             :         ;
    9085             : 
    9086             : oper_argtypes:
    9087             :             '(' Typename ')'
    9088             :                 {
    9089          12 :                    ereport(ERROR,
    9090             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9091             :                             errmsg("missing argument"),
    9092             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9093             :                             parser_errposition(@3)));
    9094             :                 }
    9095             :             | '(' Typename ',' Typename ')'
    9096        1950 :                     { $$ = list_make2($2, $4); }
    9097             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9098          32 :                     { $$ = list_make2(NULL, $4); }
    9099             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9100          12 :                     { $$ = list_make2($2, NULL); }
    9101             :         ;
    9102             : 
    9103             : any_operator:
    9104             :             all_Op
    9105       20626 :                     { $$ = list_make1(makeString($1)); }
    9106             :             | ColId '.' any_operator
    9107       15718 :                     { $$ = lcons(makeString($1), $3); }
    9108             :         ;
    9109             : 
    9110             : operator_with_argtypes_list:
    9111         224 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9112             :             | operator_with_argtypes_list ',' operator_with_argtypes
    9113           0 :                                                     { $$ = lappend($1, $3); }
    9114             :         ;
    9115             : 
    9116             : operator_with_argtypes:
    9117             :             any_operator oper_argtypes
    9118             :                 {
    9119        1994 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9120             : 
    9121        1994 :                     n->objname = $1;
    9122        1994 :                     n->objargs = $2;
    9123        1994 :                     $$ = n;
    9124             :                 }
    9125             :         ;
    9126             : 
    9127             : /*****************************************************************************
    9128             :  *
    9129             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9130             :  *
    9131             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9132             :  * in the clause order.
    9133             :  *
    9134             :  *****************************************************************************/
    9135             : 
    9136             : DoStmt: DO dostmt_opt_list
    9137             :                 {
    9138        1132 :                     DoStmt *n = makeNode(DoStmt);
    9139             : 
    9140        1132 :                     n->args = $2;
    9141        1132 :                     $$ = (Node *) n;
    9142             :                 }
    9143             :         ;
    9144             : 
    9145             : dostmt_opt_list:
    9146        1132 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9147         198 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9148             :         ;
    9149             : 
    9150             : dostmt_opt_item:
    9151             :             Sconst
    9152             :                 {
    9153        1132 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9154             :                 }
    9155             :             | LANGUAGE NonReservedWord_or_Sconst
    9156             :                 {
    9157         198 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9158             :                 }
    9159             :         ;
    9160             : 
    9161             : /*****************************************************************************
    9162             :  *
    9163             :  *      CREATE CAST / DROP CAST
    9164             :  *
    9165             :  *****************************************************************************/
    9166             : 
    9167             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9168             :                     WITH FUNCTION function_with_argtypes cast_context
    9169             :                 {
    9170         108 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9171             : 
    9172         108 :                     n->sourcetype = $4;
    9173         108 :                     n->targettype = $6;
    9174         108 :                     n->func = $10;
    9175         108 :                     n->context = (CoercionContext) $11;
    9176         108 :                     n->inout = false;
    9177         108 :                     $$ = (Node *) n;
    9178             :                 }
    9179             :             | CREATE CAST '(' Typename AS Typename ')'
    9180             :                     WITHOUT FUNCTION cast_context
    9181             :                 {
    9182         162 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9183             : 
    9184         162 :                     n->sourcetype = $4;
    9185         162 :                     n->targettype = $6;
    9186         162 :                     n->func = NULL;
    9187         162 :                     n->context = (CoercionContext) $10;
    9188         162 :                     n->inout = false;
    9189         162 :                     $$ = (Node *) n;
    9190             :                 }
    9191             :             | CREATE CAST '(' Typename AS Typename ')'
    9192             :                     WITH INOUT cast_context
    9193             :                 {
    9194           8 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9195             : 
    9196           8 :                     n->sourcetype = $4;
    9197           8 :                     n->targettype = $6;
    9198           8 :                     n->func = NULL;
    9199           8 :                     n->context = (CoercionContext) $10;
    9200           8 :                     n->inout = true;
    9201           8 :                     $$ = (Node *) n;
    9202             :                 }
    9203             :         ;
    9204             : 
    9205          36 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9206          58 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9207         184 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9208             :         ;
    9209             : 
    9210             : 
    9211             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9212             :                 {
    9213          60 :                     DropStmt *n = makeNode(DropStmt);
    9214             : 
    9215          60 :                     n->removeType = OBJECT_CAST;
    9216          60 :                     n->objects = list_make1(list_make2($5, $7));
    9217          60 :                     n->behavior = $9;
    9218          60 :                     n->missing_ok = $3;
    9219          60 :                     n->concurrent = false;
    9220          60 :                     $$ = (Node *) n;
    9221             :                 }
    9222             :         ;
    9223             : 
    9224          36 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9225          38 :         | /*EMPTY*/                             { $$ = false; }
    9226             :         ;
    9227             : 
    9228             : 
    9229             : /*****************************************************************************
    9230             :  *
    9231             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9232             :  *
    9233             :  *****************************************************************************/
    9234             : 
    9235             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9236             :                 {
    9237          50 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9238             : 
    9239          50 :                     n->replace = $2;
    9240          50 :                     n->type_name = $5;
    9241          50 :                     n->lang = $7;
    9242          50 :                     n->fromsql = linitial($9);
    9243          50 :                     n->tosql = lsecond($9);
    9244          50 :                     $$ = (Node *) n;
    9245             :                 }
    9246             :         ;
    9247             : 
    9248             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9249             :                 {
    9250          44 :                     $$ = list_make2($5, $11);
    9251             :                 }
    9252             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9253             :                 {
    9254           0 :                     $$ = list_make2($11, $5);
    9255             :                 }
    9256             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9257             :                 {
    9258           4 :                     $$ = list_make2($5, NULL);
    9259             :                 }
    9260             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9261             :                 {
    9262           2 :                     $$ = list_make2(NULL, $5);
    9263             :                 }
    9264             :         ;
    9265             : 
    9266             : 
    9267             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9268             :                 {
    9269          14 :                     DropStmt *n = makeNode(DropStmt);
    9270             : 
    9271          14 :                     n->removeType = OBJECT_TRANSFORM;
    9272          14 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9273          14 :                     n->behavior = $8;
    9274          14 :                     n->missing_ok = $3;
    9275          14 :                     $$ = (Node *) n;
    9276             :                 }
    9277             :         ;
    9278             : 
    9279             : 
    9280             : /*****************************************************************************
    9281             :  *
    9282             :  *      QUERY:
    9283             :  *
    9284             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9285             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9286             :  *****************************************************************************/
    9287             : 
    9288             : ReindexStmt:
    9289             :             REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
    9290             :                 {
    9291         922 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9292             : 
    9293         922 :                     n->kind = $3;
    9294         922 :                     n->relation = $5;
    9295         922 :                     n->name = NULL;
    9296         922 :                     n->params = $2;
    9297         922 :                     if ($4)
    9298         518 :                         n->params = lappend(n->params,
    9299         518 :                                             makeDefElem("concurrently", NULL, @4));
    9300         922 :                     $$ = (Node *) n;
    9301             :                 }
    9302             :             | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
    9303             :                 {
    9304         114 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9305             : 
    9306         114 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9307         114 :                     n->relation = NULL;
    9308         114 :                     n->name = $5;
    9309         114 :                     n->params = $2;
    9310         114 :                     if ($4)
    9311          40 :                         n->params = lappend(n->params,
    9312          40 :                                             makeDefElem("concurrently", NULL, @4));
    9313         114 :                     $$ = (Node *) n;
    9314             :                 }
    9315             :             | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
    9316             :                 {
    9317          68 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9318             : 
    9319          68 :                     n->kind = $3;
    9320          68 :                     n->relation = NULL;
    9321          68 :                     n->name = $5;
    9322          68 :                     n->params = $2;
    9323          68 :                     if ($4)
    9324          10 :                         n->params = lappend(n->params,
    9325          10 :                                             makeDefElem("concurrently", NULL, @4));
    9326          68 :                     $$ = (Node *) n;
    9327             :                 }
    9328             :         ;
    9329             : reindex_target_relation:
    9330         394 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9331         528 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9332             :         ;
    9333             : reindex_target_all:
    9334          34 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9335          34 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9336             :         ;
    9337             : opt_reindex_option_list:
    9338         156 :             '(' utility_option_list ')'             { $$ = $2; }
    9339         948 :             | /* EMPTY */                           { $$ = NULL; }
    9340             :         ;
    9341             : 
    9342             : /*****************************************************************************
    9343             :  *
    9344             :  * ALTER TABLESPACE
    9345             :  *
    9346             :  *****************************************************************************/
    9347             : 
    9348             : AlterTblSpcStmt:
    9349             :             ALTER TABLESPACE name SET reloptions
    9350             :                 {
    9351             :                     AlterTableSpaceOptionsStmt *n =
    9352          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9353             : 
    9354          12 :                     n->tablespacename = $3;
    9355          12 :                     n->options = $5;
    9356          12 :                     n->isReset = false;
    9357          12 :                     $$ = (Node *) n;
    9358             :                 }
    9359             :             | ALTER TABLESPACE name RESET reloptions
    9360             :                 {
    9361             :                     AlterTableSpaceOptionsStmt *n =
    9362          12 :                         makeNode(AlterTableSpaceOptionsStmt);
    9363             : 
    9364          12 :                     n->tablespacename = $3;
    9365          12 :                     n->options = $5;
    9366          12 :                     n->isReset = true;
    9367          12 :                     $$ = (Node *) n;
    9368             :                 }
    9369             :         ;
    9370             : 
    9371             : /*****************************************************************************
    9372             :  *
    9373             :  * ALTER THING name RENAME TO newname
    9374             :  *
    9375             :  *****************************************************************************/
    9376             : 
    9377             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9378             :                 {
    9379          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9380             : 
    9381          42 :                     n->renameType = OBJECT_AGGREGATE;
    9382          42 :                     n->object = (Node *) $3;
    9383          42 :                     n->newname = $6;
    9384          42 :                     n->missing_ok = false;
    9385          42 :                     $$ = (Node *) n;
    9386             :                 }
    9387             :             | ALTER COLLATION any_name RENAME TO name
    9388             :                 {
    9389          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9390             : 
    9391          18 :                     n->renameType = OBJECT_COLLATION;
    9392          18 :                     n->object = (Node *) $3;
    9393          18 :                     n->newname = $6;
    9394          18 :                     n->missing_ok = false;
    9395          18 :                     $$ = (Node *) n;
    9396             :                 }
    9397             :             | ALTER CONVERSION_P any_name RENAME TO name
    9398             :                 {
    9399          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9400             : 
    9401          24 :                     n->renameType = OBJECT_CONVERSION;
    9402          24 :                     n->object = (Node *) $3;
    9403          24 :                     n->newname = $6;
    9404          24 :                     n->missing_ok = false;
    9405          24 :                     $$ = (Node *) n;
    9406             :                 }
    9407             :             | ALTER DATABASE name RENAME TO name
    9408             :                 {
    9409           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9410             : 
    9411           6 :                     n->renameType = OBJECT_DATABASE;
    9412           6 :                     n->subname = $3;
    9413           6 :                     n->newname = $6;
    9414           6 :                     n->missing_ok = false;
    9415           6 :                     $$ = (Node *) n;
    9416             :                 }
    9417             :             | ALTER DOMAIN_P any_name RENAME TO name
    9418             :                 {
    9419           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9420             : 
    9421           6 :                     n->renameType = OBJECT_DOMAIN;
    9422           6 :                     n->object = (Node *) $3;
    9423           6 :                     n->newname = $6;
    9424           6 :                     n->missing_ok = false;
    9425           6 :                     $$ = (Node *) n;
    9426             :                 }
    9427             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9428             :                 {
    9429           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9430             : 
    9431           6 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9432           6 :                     n->object = (Node *) $3;
    9433           6 :                     n->subname = $6;
    9434           6 :                     n->newname = $8;
    9435           6 :                     $$ = (Node *) n;
    9436             :                 }
    9437             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9438             :                 {
    9439          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9440             : 
    9441          24 :                     n->renameType = OBJECT_FDW;
    9442          24 :                     n->object = (Node *) makeString($5);
    9443          24 :                     n->newname = $8;
    9444          24 :                     n->missing_ok = false;
    9445          24 :                     $$ = (Node *) n;
    9446             :                 }
    9447             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9448             :                 {
    9449          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9450             : 
    9451          24 :                     n->renameType = OBJECT_FUNCTION;
    9452          24 :                     n->object = (Node *) $3;
    9453          24 :                     n->newname = $6;
    9454          24 :                     n->missing_ok = false;
    9455          24 :                     $$ = (Node *) n;
    9456             :                 }
    9457             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9458             :                 {
    9459           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9460             : 
    9461           0 :                     n->renameType = OBJECT_ROLE;
    9462           0 :                     n->subname = $3;
    9463           0 :                     n->newname = $6;
    9464           0 :                     n->missing_ok = false;
    9465           0 :                     $$ = (Node *) n;
    9466             :                 }
    9467             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9468             :                 {
    9469          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9470             : 
    9471          18 :                     n->renameType = OBJECT_LANGUAGE;
    9472          18 :                     n->object = (Node *) makeString($4);
    9473          18 :                     n->newname = $7;
    9474          18 :                     n->missing_ok = false;
    9475          18 :                     $$ = (Node *) n;
    9476             :                 }
    9477             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9478             :                 {
    9479          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9480             : 
    9481          24 :                     n->renameType = OBJECT_OPCLASS;
    9482          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9483          24 :                     n->newname = $9;
    9484          24 :                     n->missing_ok = false;
    9485          24 :                     $$ = (Node *) n;
    9486             :                 }
    9487             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9488             :                 {
    9489          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9490             : 
    9491          24 :                     n->renameType = OBJECT_OPFAMILY;
    9492          24 :                     n->object = (Node *) lcons(makeString($6), $4);
    9493          24 :                     n->newname = $9;
    9494          24 :                     n->missing_ok = false;
    9495          24 :                     $$ = (Node *) n;
    9496             :                 }
    9497             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9498             :                 {
    9499          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9500             : 
    9501          18 :                     n->renameType = OBJECT_POLICY;
    9502          18 :                     n->relation = $5;
    9503          18 :                     n->subname = $3;
    9504          18 :                     n->newname = $8;
    9505          18 :                     n->missing_ok = false;
    9506          18 :                     $$ = (Node *) n;
    9507             :                 }
    9508             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9509             :                 {
    9510           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9511             : 
    9512           0 :                     n->renameType = OBJECT_POLICY;
    9513           0 :                     n->relation = $7;
    9514           0 :                     n->subname = $5;
    9515           0 :                     n->newname = $10;
    9516           0 :                     n->missing_ok = true;
    9517           0 :                     $$ = (Node *) n;
    9518             :                 }
    9519             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9520             :                 {
    9521           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9522             : 
    9523           0 :                     n->renameType = OBJECT_PROCEDURE;
    9524           0 :                     n->object = (Node *) $3;
    9525           0 :                     n->newname = $6;
    9526           0 :                     n->missing_ok = false;
    9527           0 :                     $$ = (Node *) n;
    9528             :                 }
    9529             :             | ALTER PUBLICATION name RENAME TO name
    9530             :                 {
    9531          42 :                     RenameStmt *n = makeNode(RenameStmt);
    9532             : 
    9533          42 :                     n->renameType = OBJECT_PUBLICATION;
    9534          42 :                     n->object = (Node *) makeString($3);
    9535          42 :                     n->newname = $6;
    9536          42 :                     n->missing_ok = false;
    9537          42 :                     $$ = (Node *) n;
    9538             :                 }
    9539             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9540             :                 {
    9541          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9542             : 
    9543          24 :                     n->renameType = OBJECT_ROUTINE;
    9544          24 :                     n->object = (Node *) $3;
    9545          24 :                     n->newname = $6;
    9546          24 :                     n->missing_ok = false;
    9547          24 :                     $$ = (Node *) n;
    9548             :                 }
    9549             :             | ALTER SCHEMA name RENAME TO name
    9550             :                 {
    9551          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9552             : 
    9553          20 :                     n->renameType = OBJECT_SCHEMA;
    9554          20 :                     n->subname = $3;
    9555          20 :                     n->newname = $6;
    9556          20 :                     n->missing_ok = false;
    9557          20 :                     $$ = (Node *) n;
    9558             :                 }
    9559             :             | ALTER SERVER name RENAME TO name
    9560             :                 {
    9561          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9562             : 
    9563          24 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9564          24 :                     n->object = (Node *) makeString($3);
    9565          24 :                     n->newname = $6;
    9566          24 :                     n->missing_ok = false;
    9567          24 :                     $$ = (Node *) n;
    9568             :                 }
    9569             :             | ALTER SUBSCRIPTION name RENAME TO name
    9570             :                 {
    9571          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9572             : 
    9573          38 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9574          38 :                     n->object = (Node *) makeString($3);
    9575          38 :                     n->newname = $6;
    9576          38 :                     n->missing_ok = false;
    9577          38 :                     $$ = (Node *) n;
    9578             :                 }
    9579             :             | ALTER TABLE relation_expr RENAME TO name
    9580             :                 {
    9581         286 :                     RenameStmt *n = makeNode(RenameStmt);
    9582             : 
    9583         286 :                     n->renameType = OBJECT_TABLE;
    9584         286 :                     n->relation = $3;
    9585         286 :                     n->subname = NULL;
    9586         286 :                     n->newname = $6;
    9587         286 :                     n->missing_ok = false;
    9588         286 :                     $$ = (Node *) n;
    9589             :                 }
    9590             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9591             :                 {
    9592           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9593             : 
    9594           0 :                     n->renameType = OBJECT_TABLE;
    9595           0 :                     n->relation = $5;
    9596           0 :                     n->subname = NULL;
    9597           0 :                     n->newname = $8;
    9598           0 :                     n->missing_ok = true;
    9599           0 :                     $$ = (Node *) n;
    9600             :                 }
    9601             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9602             :                 {
    9603           2 :                     RenameStmt *n = makeNode(RenameStmt);
    9604             : 
    9605           2 :                     n->renameType = OBJECT_SEQUENCE;
    9606           2 :                     n->relation = $3;
    9607           2 :                     n->subname = NULL;
    9608           2 :                     n->newname = $6;
    9609           2 :                     n->missing_ok = false;
    9610           2 :                     $$ = (Node *) n;
    9611             :                 }
    9612             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9613             :                 {
    9614           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9615             : 
    9616           0 :                     n->renameType = OBJECT_SEQUENCE;
    9617           0 :                     n->relation = $5;
    9618           0 :                     n->subname = NULL;
    9619           0 :                     n->newname = $8;
    9620           0 :                     n->missing_ok = true;
    9621           0 :                     $$ = (Node *) n;
    9622             :                 }
    9623             :             | ALTER VIEW qualified_name RENAME TO name
    9624             :                 {
    9625           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9626             : 
    9627           6 :                     n->renameType = OBJECT_VIEW;
    9628           6 :                     n->relation = $3;
    9629           6 :                     n->subname = NULL;
    9630           6 :                     n->newname = $6;
    9631           6 :                     n->missing_ok = false;
    9632           6 :                     $$ = (Node *) n;
    9633             :                 }
    9634             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9635             :                 {
    9636           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9637             : 
    9638           0 :                     n->renameType = OBJECT_VIEW;
    9639           0 :                     n->relation = $5;
    9640           0 :                     n->subname = NULL;
    9641           0 :                     n->newname = $8;
    9642           0 :                     n->missing_ok = true;
    9643           0 :                     $$ = (Node *) n;
    9644             :                 }
    9645             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9646             :                 {
    9647           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9648             : 
    9649           0 :                     n->renameType = OBJECT_MATVIEW;
    9650           0 :                     n->relation = $4;
    9651           0 :                     n->subname = NULL;
    9652           0 :                     n->newname = $7;
    9653           0 :                     n->missing_ok = false;
    9654           0 :                     $$ = (Node *) n;
    9655             :                 }
    9656             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9657             :                 {
    9658           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9659             : 
    9660           0 :                     n->renameType = OBJECT_MATVIEW;
    9661           0 :                     n->relation = $6;
    9662           0 :                     n->subname = NULL;
    9663           0 :                     n->newname = $9;
    9664           0 :                     n->missing_ok = true;
    9665           0 :                     $$ = (Node *) n;
    9666             :                 }
    9667             :             | ALTER INDEX qualified_name RENAME TO name
    9668             :                 {
    9669         192 :                     RenameStmt *n = makeNode(RenameStmt);
    9670             : 
    9671         192 :                     n->renameType = OBJECT_INDEX;
    9672         192 :                     n->relation = $3;
    9673         192 :                     n->subname = NULL;
    9674         192 :                     n->newname = $6;
    9675         192 :                     n->missing_ok = false;
    9676         192 :                     $$ = (Node *) n;
    9677             :                 }
    9678             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9679             :                 {
    9680          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9681             : 
    9682          12 :                     n->renameType = OBJECT_INDEX;
    9683          12 :                     n->relation = $5;
    9684          12 :                     n->subname = NULL;
    9685          12 :                     n->newname = $8;
    9686          12 :                     n->missing_ok = true;
    9687          12 :                     $$ = (Node *) n;
    9688             :                 }
    9689             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9690             :                 {
    9691           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9692             : 
    9693           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9694           6 :                     n->relation = $4;
    9695           6 :                     n->subname = NULL;
    9696           6 :                     n->newname = $7;
    9697           6 :                     n->missing_ok = false;
    9698           6 :                     $$ = (Node *) n;
    9699             :                 }
    9700             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9701             :                 {
    9702           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9703             : 
    9704           6 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9705           6 :                     n->relation = $6;
    9706           6 :                     n->subname = NULL;
    9707           6 :                     n->newname = $9;
    9708           6 :                     n->missing_ok = true;
    9709           6 :                     $$ = (Node *) n;
    9710             :                 }
    9711             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9712             :                 {
    9713         238 :                     RenameStmt *n = makeNode(RenameStmt);
    9714             : 
    9715         238 :                     n->renameType = OBJECT_COLUMN;
    9716         238 :                     n->relationType = OBJECT_TABLE;
    9717         238 :                     n->relation = $3;
    9718         238 :                     n->subname = $6;
    9719         238 :                     n->newname = $8;
    9720         238 :                     n->missing_ok = false;
    9721         238 :                     $$ = (Node *) n;
    9722             :                 }
    9723             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9724             :                 {
    9725          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9726             : 
    9727          24 :                     n->renameType = OBJECT_COLUMN;
    9728          24 :                     n->relationType = OBJECT_TABLE;
    9729          24 :                     n->relation = $5;
    9730          24 :                     n->subname = $8;
    9731          24 :                     n->newname = $10;
    9732          24 :                     n->missing_ok = true;
    9733          24 :                     $$ = (Node *) n;
    9734             :                 }
    9735             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9736             :                 {
    9737          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9738             : 
    9739          18 :                     n->renameType = OBJECT_COLUMN;
    9740          18 :                     n->relationType = OBJECT_VIEW;
    9741          18 :                     n->relation = $3;
    9742          18 :                     n->subname = $6;
    9743          18 :                     n->newname = $8;
    9744          18 :                     n->missing_ok = false;
    9745          18 :                     $$ = (Node *) n;
    9746             :                 }
    9747             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9748             :                 {
    9749           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9750             : 
    9751           0 :                     n->renameType = OBJECT_COLUMN;
    9752           0 :                     n->relationType = OBJECT_VIEW;
    9753           0 :                     n->relation = $5;
    9754           0 :                     n->subname = $8;
    9755           0 :                     n->newname = $10;
    9756           0 :                     n->missing_ok = true;
    9757           0 :                     $$ = (Node *) n;
    9758             :                 }
    9759             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9760             :                 {
    9761           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9762             : 
    9763           0 :                     n->renameType = OBJECT_COLUMN;
    9764           0 :                     n->relationType = OBJECT_MATVIEW;
    9765           0 :                     n->relation = $4;
    9766           0 :                     n->subname = $7;
    9767           0 :                     n->newname = $9;
    9768           0 :                     n->missing_ok = false;
    9769           0 :                     $$ = (Node *) n;
    9770             :                 }
    9771             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9772             :                 {
    9773           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9774             : 
    9775           0 :                     n->renameType = OBJECT_COLUMN;
    9776           0 :                     n->relationType = OBJECT_MATVIEW;
    9777           0 :                     n->relation = $6;
    9778           0 :                     n->subname = $9;
    9779           0 :                     n->newname = $11;
    9780           0 :                     n->missing_ok = true;
    9781           0 :                     $$ = (Node *) n;
    9782             :                 }
    9783             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9784             :                 {
    9785          72 :                     RenameStmt *n = makeNode(RenameStmt);
    9786             : 
    9787          72 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9788          72 :                     n->relation = $3;
    9789          72 :                     n->subname = $6;
    9790          72 :                     n->newname = $8;
    9791          72 :                     n->missing_ok = false;
    9792          72 :                     $$ = (Node *) n;
    9793             :                 }
    9794             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9795             :                 {
    9796           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9797             : 
    9798           6 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9799           6 :                     n->relation = $5;
    9800           6 :                     n->subname = $8;
    9801           6 :                     n->newname = $10;
    9802           6 :                     n->missing_ok = true;
    9803           6 :                     $$ = (Node *) n;
    9804             :                 }
    9805             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9806             :                 {
    9807           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9808             : 
    9809           6 :                     n->renameType = OBJECT_COLUMN;
    9810           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9811           6 :                     n->relation = $4;
    9812           6 :                     n->subname = $7;
    9813           6 :                     n->newname = $9;
    9814           6 :                     n->missing_ok = false;
    9815           6 :                     $$ = (Node *) n;
    9816             :                 }
    9817             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9818             :                 {
    9819           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9820             : 
    9821           6 :                     n->renameType = OBJECT_COLUMN;
    9822           6 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9823           6 :                     n->relation = $6;
    9824           6 :                     n->subname = $9;
    9825           6 :                     n->newname = $11;
    9826           6 :                     n->missing_ok = true;
    9827           6 :                     $$ = (Node *) n;
    9828             :                 }
    9829             :             | ALTER RULE name ON qualified_name RENAME TO name
    9830             :                 {
    9831          34 :                     RenameStmt *n = makeNode(RenameStmt);
    9832             : 
    9833          34 :                     n->renameType = OBJECT_RULE;
    9834          34 :                     n->relation = $5;
    9835          34 :                     n->subname = $3;
    9836          34 :                     n->newname = $8;
    9837          34 :                     n->missing_ok = false;
    9838          34 :                     $$ = (Node *) n;
    9839             :                 }
    9840             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9841             :                 {
    9842          40 :                     RenameStmt *n = makeNode(RenameStmt);
    9843             : 
    9844          40 :                     n->renameType = OBJECT_TRIGGER;
    9845          40 :                     n->relation = $5;
    9846          40 :                     n->subname = $3;
    9847          40 :                     n->newname = $8;
    9848          40 :                     n->missing_ok = false;
    9849          40 :                     $$ = (Node *) n;
    9850             :                 }
    9851             :             | ALTER EVENT TRIGGER name RENAME TO name
    9852             :                 {
    9853          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9854             : 
    9855          12 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9856          12 :                     n->object = (Node *) makeString($4);
    9857          12 :                     n->newname = $7;
    9858          12 :                     $$ = (Node *) n;
    9859             :                 }
    9860             :             | ALTER ROLE RoleId RENAME TO RoleId
    9861             :                 {
    9862          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9863             : 
    9864          30 :                     n->renameType = OBJECT_ROLE;
    9865          30 :                     n->subname = $3;
    9866          30 :                     n->newname = $6;
    9867          30 :                     n->missing_ok = false;
    9868          30 :                     $$ = (Node *) n;
    9869             :                 }
    9870             :             | ALTER USER RoleId RENAME TO RoleId
    9871             :                 {
    9872           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9873             : 
    9874           0 :                     n->renameType = OBJECT_ROLE;
    9875           0 :                     n->subname = $3;
    9876           0 :                     n->newname = $6;
    9877           0 :                     n->missing_ok = false;
    9878           0 :                     $$ = (Node *) n;
    9879             :                 }
    9880             :             | ALTER TABLESPACE name RENAME TO name
    9881             :                 {
    9882           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9883             : 
    9884           6 :                     n->renameType = OBJECT_TABLESPACE;
    9885           6 :                     n->subname = $3;
    9886           6 :                     n->newname = $6;
    9887           6 :                     n->missing_ok = false;
    9888           6 :                     $$ = (Node *) n;
    9889             :                 }
    9890             :             | ALTER STATISTICS any_name RENAME TO name
    9891             :                 {
    9892          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9893             : 
    9894          30 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9895          30 :                     n->object = (Node *) $3;
    9896          30 :                     n->newname = $6;
    9897          30 :                     n->missing_ok = false;
    9898          30 :                     $$ = (Node *) n;
    9899             :                 }
    9900             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    9901             :                 {
    9902          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9903             : 
    9904          12 :                     n->renameType = OBJECT_TSPARSER;
    9905          12 :                     n->object = (Node *) $5;
    9906          12 :                     n->newname = $8;
    9907          12 :                     n->missing_ok = false;
    9908          12 :                     $$ = (Node *) n;
    9909             :                 }
    9910             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
    9911             :                 {
    9912          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9913             : 
    9914          24 :                     n->renameType = OBJECT_TSDICTIONARY;
    9915          24 :                     n->object = (Node *) $5;
    9916          24 :                     n->newname = $8;
    9917          24 :                     n->missing_ok = false;
    9918          24 :                     $$ = (Node *) n;
    9919             :                 }
    9920             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
    9921             :                 {
    9922          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9923             : 
    9924          12 :                     n->renameType = OBJECT_TSTEMPLATE;
    9925          12 :                     n->object = (Node *) $5;
    9926          12 :                     n->newname = $8;
    9927          12 :                     n->missing_ok = false;
    9928          12 :                     $$ = (Node *) n;
    9929             :                 }
    9930             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
    9931             :                 {
    9932          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9933             : 
    9934          24 :                     n->renameType = OBJECT_TSCONFIGURATION;
    9935          24 :                     n->object = (Node *) $5;
    9936          24 :                     n->newname = $8;
    9937          24 :                     n->missing_ok = false;
    9938          24 :                     $$ = (Node *) n;
    9939             :                 }
    9940             :             | ALTER TYPE_P any_name RENAME TO name
    9941             :                 {
    9942          26 :                     RenameStmt *n = makeNode(RenameStmt);
    9943             : 
    9944          26 :                     n->renameType = OBJECT_TYPE;
    9945          26 :                     n->object = (Node *) $3;
    9946          26 :                     n->newname = $6;
    9947          26 :                     n->missing_ok = false;
    9948          26 :                     $$ = (Node *) n;
    9949             :                 }
    9950             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
    9951             :                 {
    9952          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9953             : 
    9954          24 :                     n->renameType = OBJECT_ATTRIBUTE;
    9955          24 :                     n->relationType = OBJECT_TYPE;
    9956          24 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    9957          24 :                     n->subname = $6;
    9958          24 :                     n->newname = $8;
    9959          24 :                     n->behavior = $9;
    9960          24 :                     n->missing_ok = false;
    9961          24 :                     $$ = (Node *) n;
    9962             :                 }
    9963             :         ;
    9964             : 
    9965             : opt_column: COLUMN
    9966             :             | /*EMPTY*/
    9967             :         ;
    9968             : 
    9969         184 : opt_set_data: SET DATA_P                            { $$ = 1; }
    9970         872 :             | /*EMPTY*/                             { $$ = 0; }
    9971             :         ;
    9972             : 
    9973             : /*****************************************************************************
    9974             :  *
    9975             :  * ALTER THING name DEPENDS ON EXTENSION name
    9976             :  *
    9977             :  *****************************************************************************/
    9978             : 
    9979             : AlterObjectDependsStmt:
    9980             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9981             :                 {
    9982          12 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9983             : 
    9984          12 :                     n->objectType = OBJECT_FUNCTION;
    9985          12 :                     n->object = (Node *) $3;
    9986          12 :                     n->extname = makeString($8);
    9987          12 :                     n->remove = $4;
    9988          12 :                     $$ = (Node *) n;
    9989             :                 }
    9990             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9991             :                 {
    9992           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9993             : 
    9994           0 :                     n->objectType = OBJECT_PROCEDURE;
    9995           0 :                     n->object = (Node *) $3;
    9996           0 :                     n->extname = makeString($8);
    9997           0 :                     n->remove = $4;
    9998           0 :                     $$ = (Node *) n;
    9999             :                 }
   10000             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10001             :                 {
   10002           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10003             : 
   10004           0 :                     n->objectType = OBJECT_ROUTINE;
   10005           0 :                     n->object = (Node *) $3;
   10006           0 :                     n->extname = makeString($8);
   10007           0 :                     n->remove = $4;
   10008           0 :                     $$ = (Node *) n;
   10009             :                 }
   10010             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
   10011             :                 {
   10012          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10013             : 
   10014          10 :                     n->objectType = OBJECT_TRIGGER;
   10015          10 :                     n->relation = $5;
   10016          10 :                     n->object = (Node *) list_make1(makeString($3));
   10017          10 :                     n->extname = makeString($10);
   10018          10 :                     n->remove = $6;
   10019          10 :                     $$ = (Node *) n;
   10020             :                 }
   10021             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10022             :                 {
   10023          10 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10024             : 
   10025          10 :                     n->objectType = OBJECT_MATVIEW;
   10026          10 :                     n->relation = $4;
   10027          10 :                     n->extname = makeString($9);
   10028          10 :                     n->remove = $5;
   10029          10 :                     $$ = (Node *) n;
   10030             :                 }
   10031             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10032             :                 {
   10033          14 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10034             : 
   10035          14 :                     n->objectType = OBJECT_INDEX;
   10036          14 :                     n->relation = $3;
   10037          14 :                     n->extname = makeString($8);
   10038          14 :                     n->remove = $4;
   10039          14 :                     $$ = (Node *) n;
   10040             :                 }
   10041             :         ;
   10042             : 
   10043           8 : opt_no:     NO              { $$ = true; }
   10044          38 :             | /* EMPTY */   { $$ = false;   }
   10045             :         ;
   10046             : 
   10047             : /*****************************************************************************
   10048             :  *
   10049             :  * ALTER THING name SET SCHEMA name
   10050             :  *
   10051             :  *****************************************************************************/
   10052             : 
   10053             : AlterObjectSchemaStmt:
   10054             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10055             :                 {
   10056          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10057             : 
   10058          24 :                     n->objectType = OBJECT_AGGREGATE;
   10059          24 :                     n->object = (Node *) $3;
   10060          24 :                     n->newschema = $6;
   10061          24 :                     n->missing_ok = false;
   10062          24 :                     $$ = (Node *) n;
   10063             :                 }
   10064             :             | ALTER COLLATION any_name SET SCHEMA name
   10065             :                 {
   10066           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10067             : 
   10068           6 :                     n->objectType = OBJECT_COLLATION;
   10069           6 :                     n->object = (Node *) $3;
   10070           6 :                     n->newschema = $6;
   10071           6 :                     n->missing_ok = false;
   10072           6 :                     $$ = (Node *) n;
   10073             :                 }
   10074             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10075             :                 {
   10076          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10077             : 
   10078          24 :                     n->objectType = OBJECT_CONVERSION;
   10079          24 :                     n->object = (Node *) $3;
   10080          24 :                     n->newschema = $6;
   10081          24 :                     n->missing_ok = false;
   10082          24 :                     $$ = (Node *) n;
   10083             :                 }
   10084             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10085             :                 {
   10086           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10087             : 
   10088           6 :                     n->objectType = OBJECT_DOMAIN;
   10089           6 :                     n->object = (Node *) $3;
   10090           6 :                     n->newschema = $6;
   10091           6 :                     n->missing_ok = false;
   10092           6 :                     $$ = (Node *) n;
   10093             :                 }
   10094             :             | ALTER EXTENSION name SET SCHEMA name
   10095             :                 {
   10096          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10097             : 
   10098          12 :                     n->objectType = OBJECT_EXTENSION;
   10099          12 :                     n->object = (Node *) makeString($3);
   10100          12 :                     n->newschema = $6;
   10101          12 :                     n->missing_ok = false;
   10102          12 :                     $$ = (Node *) n;
   10103             :                 }
   10104             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10105             :                 {
   10106          42 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10107             : 
   10108          42 :                     n->objectType = OBJECT_FUNCTION;
   10109          42 :                     n->object = (Node *) $3;
   10110          42 :                     n->newschema = $6;
   10111          42 :                     n->missing_ok = false;
   10112          42 :                     $$ = (Node *) n;
   10113             :                 }
   10114             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10115             :                 {
   10116          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10117             : 
   10118          18 :                     n->objectType = OBJECT_OPERATOR;
   10119          18 :                     n->object = (Node *) $3;
   10120          18 :                     n->newschema = $6;
   10121          18 :                     n->missing_ok = false;
   10122          18 :                     $$ = (Node *) n;
   10123             :                 }
   10124             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10125             :                 {
   10126          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10127             : 
   10128          24 :                     n->objectType = OBJECT_OPCLASS;
   10129          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10130          24 :                     n->newschema = $9;
   10131          24 :                     n->missing_ok = false;
   10132          24 :                     $$ = (Node *) n;
   10133             :                 }
   10134             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10135             :                 {
   10136          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10137             : 
   10138          24 :                     n->objectType = OBJECT_OPFAMILY;
   10139          24 :                     n->object = (Node *) lcons(makeString($6), $4);
   10140          24 :                     n->newschema = $9;
   10141          24 :                     n->missing_ok = false;
   10142          24 :                     $$ = (Node *) n;
   10143             :                 }
   10144             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10145             :                 {
   10146           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10147             : 
   10148           0 :                     n->objectType = OBJECT_PROCEDURE;
   10149           0 :                     n->object = (Node *) $3;
   10150           0 :                     n->newschema = $6;
   10151           0 :                     n->missing_ok = false;
   10152           0 :                     $$ = (Node *) n;
   10153             :                 }
   10154             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10155             :                 {
   10156           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10157             : 
   10158           0 :                     n->objectType = OBJECT_ROUTINE;
   10159           0 :                     n->object = (Node *) $3;
   10160           0 :                     n->newschema = $6;
   10161           0 :                     n->missing_ok = false;
   10162           0 :                     $$ = (Node *) n;
   10163             :                 }
   10164             :             | ALTER TABLE relation_expr SET SCHEMA name
   10165             :                 {
   10166          66 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10167             : 
   10168          66 :                     n->objectType = OBJECT_TABLE;
   10169          66 :                     n->relation = $3;
   10170          66 :                     n->newschema = $6;
   10171          66 :                     n->missing_ok = false;
   10172          66 :                     $$ = (Node *) n;
   10173             :                 }
   10174             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10175             :                 {
   10176          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10177             : 
   10178          12 :                     n->objectType = OBJECT_TABLE;
   10179          12 :                     n->relation = $5;
   10180          12 :                     n->newschema = $8;
   10181          12 :                     n->missing_ok = true;
   10182          12 :                     $$ = (Node *) n;
   10183             :                 }
   10184             :             | ALTER STATISTICS any_name SET SCHEMA name
   10185             :                 {
   10186          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10187             : 
   10188          18 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10189          18 :                     n->object = (Node *) $3;
   10190          18 :                     n->newschema = $6;
   10191          18 :                     n->missing_ok = false;
   10192          18 :                     $$ = (Node *) n;
   10193             :                 }
   10194             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10195             :                 {
   10196          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10197             : 
   10198          18 :                     n->objectType = OBJECT_TSPARSER;
   10199          18 :                     n->object = (Node *) $5;
   10200          18 :                     n->newschema = $8;
   10201          18 :                     n->missing_ok = false;
   10202          18 :                     $$ = (Node *) n;
   10203             :                 }
   10204             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10205             :                 {
   10206          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10207             : 
   10208          24 :                     n->objectType = OBJECT_TSDICTIONARY;
   10209          24 :                     n->object = (Node *) $5;
   10210          24 :                     n->newschema = $8;
   10211          24 :                     n->missing_ok = false;
   10212          24 :                     $$ = (Node *) n;
   10213             :                 }
   10214             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10215             :                 {
   10216          18 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10217             : 
   10218          18 :                     n->objectType = OBJECT_TSTEMPLATE;
   10219          18 :                     n->object = (Node *) $5;
   10220          18 :                     n->newschema = $8;
   10221          18 :                     n->missing_ok = false;
   10222          18 :                     $$ = (Node *) n;
   10223             :                 }
   10224             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10225             :                 {
   10226          24 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10227             : 
   10228          24 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10229          24 :                     n->object = (Node *) $5;
   10230          24 :                     n->newschema = $8;
   10231          24 :                     n->missing_ok = false;
   10232          24 :                     $$ = (Node *) n;
   10233             :                 }
   10234             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10235             :                 {
   10236           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10237             : 
   10238           8 :                     n->objectType = OBJECT_SEQUENCE;
   10239           8 :                     n->relation = $3;
   10240           8 :                     n->newschema = $6;
   10241           8 :                     n->missing_ok = false;
   10242           8 :                     $$ = (Node *) n;
   10243             :                 }
   10244             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10245             :                 {
   10246           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10247             : 
   10248           0 :                     n->objectType = OBJECT_SEQUENCE;
   10249           0 :                     n->relation = $5;
   10250           0 :                     n->newschema = $8;
   10251           0 :                     n->missing_ok = true;
   10252           0 :                     $$ = (Node *) n;
   10253             :                 }
   10254             :             | ALTER VIEW qualified_name SET SCHEMA name
   10255             :                 {
   10256           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10257             : 
   10258           0 :                     n->objectType = OBJECT_VIEW;
   10259           0 :                     n->relation = $3;
   10260           0 :                     n->newschema = $6;
   10261           0 :                     n->missing_ok = false;
   10262           0 :                     $$ = (Node *) n;
   10263             :                 }
   10264             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10265             :                 {
   10266           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10267             : 
   10268           0 :                     n->objectType = OBJECT_VIEW;
   10269           0 :                     n->relation = $5;
   10270           0 :                     n->newschema = $8;
   10271           0 :                     n->missing_ok = true;
   10272           0 :                     $$ = (Node *) n;
   10273             :                 }
   10274             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10275             :                 {
   10276           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10277             : 
   10278           6 :                     n->objectType = OBJECT_MATVIEW;
   10279           6 :                     n->relation = $4;
   10280           6 :                     n->newschema = $7;
   10281           6 :                     n->missing_ok = false;
   10282           6 :                     $$ = (Node *) n;
   10283             :                 }
   10284             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10285             :                 {
   10286           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10287             : 
   10288           0 :                     n->objectType = OBJECT_MATVIEW;
   10289           0 :                     n->relation = $6;
   10290           0 :                     n->newschema = $9;
   10291           0 :                     n->missing_ok = true;
   10292           0 :                     $$ = (Node *) n;
   10293             :                 }
   10294             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10295             :                 {
   10296           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10297             : 
   10298           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10299           6 :                     n->relation = $4;
   10300           6 :                     n->newschema = $7;
   10301           6 :                     n->missing_ok = false;
   10302           6 :                     $$ = (Node *) n;
   10303             :                 }
   10304             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10305             :                 {
   10306           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10307             : 
   10308           6 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10309           6 :                     n->relation = $6;
   10310           6 :                     n->newschema = $9;
   10311           6 :                     n->missing_ok = true;
   10312           6 :                     $$ = (Node *) n;
   10313             :                 }
   10314             :             | ALTER TYPE_P any_name SET SCHEMA name
   10315             :                 {
   10316          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10317             : 
   10318          12 :                     n->objectType = OBJECT_TYPE;
   10319          12 :                     n->object = (Node *) $3;
   10320          12 :                     n->newschema = $6;
   10321          12 :                     n->missing_ok = false;
   10322          12 :                     $$ = (Node *) n;
   10323             :                 }
   10324             :         ;
   10325             : 
   10326             : /*****************************************************************************
   10327             :  *
   10328             :  * ALTER OPERATOR name SET define
   10329             :  *
   10330             :  *****************************************************************************/
   10331             : 
   10332             : AlterOperatorStmt:
   10333             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10334             :                 {
   10335         608 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10336             : 
   10337         608 :                     n->opername = $3;
   10338         608 :                     n->options = $6;
   10339         608 :                     $$ = (Node *) n;
   10340             :                 }
   10341             :         ;
   10342             : 
   10343         668 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10344         506 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10345             :         ;
   10346             : 
   10347             : operator_def_elem: ColLabel '=' NONE
   10348          30 :                         { $$ = makeDefElem($1, NULL, @1); }
   10349             :                    | ColLabel '=' operator_def_arg
   10350        1110 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10351             :                    | ColLabel
   10352          34 :                         { $$ = makeDefElem($1, NULL, @1); }
   10353             :         ;
   10354             : 
   10355             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10356             : operator_def_arg:
   10357        1032 :             func_type                       { $$ = (Node *) $1; }
   10358          24 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10359          54 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10360           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10361           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10362             :         ;
   10363             : 
   10364             : /*****************************************************************************
   10365             :  *
   10366             :  * ALTER TYPE name SET define
   10367             :  *
   10368             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10369             :  *
   10370             :  *****************************************************************************/
   10371             : 
   10372             : AlterTypeStmt:
   10373             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10374             :                 {
   10375          60 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10376             : 
   10377          60 :                     n->typeName = $3;
   10378          60 :                     n->options = $6;
   10379          60 :                     $$ = (Node *) n;
   10380             :                 }
   10381             :         ;
   10382             : 
   10383             : /*****************************************************************************
   10384             :  *
   10385             :  * ALTER THING name OWNER TO newname
   10386             :  *
   10387             :  *****************************************************************************/
   10388             : 
   10389             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10390             :                 {
   10391         142 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10392             : 
   10393         142 :                     n->objectType = OBJECT_AGGREGATE;
   10394         142 :                     n->object = (Node *) $3;
   10395         142 :                     n->newowner = $6;
   10396         142 :                     $$ = (Node *) n;
   10397             :                 }
   10398             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10399             :                 {
   10400          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10401             : 
   10402          18 :                     n->objectType = OBJECT_COLLATION;
   10403          18 :                     n->object = (Node *) $3;
   10404          18 :                     n->newowner = $6;
   10405          18 :                     $$ = (Node *) n;
   10406             :                 }
   10407             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10408             :                 {
   10409          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10410             : 
   10411          24 :                     n->objectType = OBJECT_CONVERSION;
   10412          24 :                     n->object = (Node *) $3;
   10413          24 :                     n->newowner = $6;
   10414          24 :                     $$ = (Node *) n;
   10415             :                 }
   10416             :             | ALTER DATABASE name OWNER TO RoleSpec
   10417             :                 {
   10418          78 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10419             : 
   10420          78 :                     n->objectType = OBJECT_DATABASE;
   10421          78 :                     n->object = (Node *) makeString($3);
   10422          78 :                     n->newowner = $6;
   10423          78 :                     $$ = (Node *) n;
   10424             :                 }
   10425             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10426             :                 {
   10427          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10428             : 
   10429          42 :                     n->objectType = OBJECT_DOMAIN;
   10430          42 :                     n->object = (Node *) $3;
   10431          42 :                     n->newowner = $6;
   10432          42 :                     $$ = (Node *) n;
   10433             :                 }
   10434             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10435             :                 {
   10436         594 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10437             : 
   10438         594 :                     n->objectType = OBJECT_FUNCTION;
   10439         594 :                     n->object = (Node *) $3;
   10440         594 :                     n->newowner = $6;
   10441         594 :                     $$ = (Node *) n;
   10442             :                 }
   10443             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10444             :                 {
   10445         132 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10446             : 
   10447         132 :                     n->objectType = OBJECT_LANGUAGE;
   10448         132 :                     n->object = (Node *) makeString($4);
   10449         132 :                     n->newowner = $7;
   10450         132 :                     $$ = (Node *) n;
   10451             :                 }
   10452             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10453             :                 {
   10454          12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10455             : 
   10456          12 :                     n->objectType = OBJECT_LARGEOBJECT;
   10457          12 :                     n->object = (Node *) $4;
   10458          12 :                     n->newowner = $7;
   10459          12 :                     $$ = (Node *) n;
   10460             :                 }
   10461             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10462             :                 {
   10463          46 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10464             : 
   10465          46 :                     n->objectType = OBJECT_OPERATOR;
   10466          46 :                     n->object = (Node *) $3;
   10467          46 :                     n->newowner = $6;
   10468          46 :                     $$ = (Node *) n;
   10469             :                 }
   10470             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10471             :                 {
   10472          54 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10473             : 
   10474          54 :                     n->objectType = OBJECT_OPCLASS;
   10475          54 :                     n->object = (Node *) lcons(makeString($6), $4);
   10476          54 :                     n->newowner = $9;
   10477          54 :                     $$ = (Node *) n;
   10478             :                 }
   10479             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10480             :                 {
   10481          62 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10482             : 
   10483          62 :                     n->objectType = OBJECT_OPFAMILY;
   10484          62 :                     n->object = (Node *) lcons(makeString($6), $4);
   10485          62 :                     n->newowner = $9;
   10486          62 :                     $$ = (Node *) n;
   10487             :                 }
   10488             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10489             :                 {
   10490          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10491             : 
   10492          24 :                     n->objectType = OBJECT_PROCEDURE;
   10493          24 :                     n->object = (Node *) $3;
   10494          24 :                     n->newowner = $6;
   10495          24 :                     $$ = (Node *) n;
   10496             :                 }
   10497             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10498             :                 {
   10499           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10500             : 
   10501           0 :                     n->objectType = OBJECT_ROUTINE;
   10502           0 :                     n->object = (Node *) $3;
   10503           0 :                     n->newowner = $6;
   10504           0 :                     $$ = (Node *) n;
   10505             :                 }
   10506             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10507             :                 {
   10508          56 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10509             : 
   10510          56 :                     n->objectType = OBJECT_SCHEMA;
   10511          56 :                     n->object = (Node *) makeString($3);
   10512          56 :                     n->newowner = $6;
   10513          56 :                     $$ = (Node *) n;
   10514             :                 }
   10515             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10516             :                 {
   10517          84 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10518             : 
   10519          84 :                     n->objectType = OBJECT_TYPE;
   10520          84 :                     n->object = (Node *) $3;
   10521          84 :                     n->newowner = $6;
   10522          84 :                     $$ = (Node *) n;
   10523             :                 }
   10524             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10525             :                 {
   10526           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10527             : 
   10528           6 :                     n->objectType = OBJECT_TABLESPACE;
   10529           6 :                     n->object = (Node *) makeString($3);
   10530           6 :                     n->newowner = $6;
   10531           6 :                     $$ = (Node *) n;
   10532             :                 }
   10533             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10534             :                 {
   10535          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10536             : 
   10537          32 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10538          32 :                     n->object = (Node *) $3;
   10539          32 :                     n->newowner = $6;
   10540          32 :                     $$ = (Node *) n;
   10541             :                 }
   10542             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10543             :                 {
   10544          42 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10545             : 
   10546          42 :                     n->objectType = OBJECT_TSDICTIONARY;
   10547          42 :                     n->object = (Node *) $5;
   10548          42 :                     n->newowner = $8;
   10549          42 :                     $$ = (Node *) n;
   10550             :                 }
   10551             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10552             :                 {
   10553          32 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10554             : 
   10555          32 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10556          32 :                     n->object = (Node *) $5;
   10557          32 :                     n->newowner = $8;
   10558          32 :                     $$ = (Node *) n;
   10559             :                 }
   10560             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10561             :                 {
   10562          20 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10563             : 
   10564          20 :                     n->objectType = OBJECT_FDW;
   10565          20 :                     n->object = (Node *) makeString($5);
   10566          20 :                     n->newowner = $8;
   10567          20 :                     $$ = (Node *) n;
   10568             :                 }
   10569             :             | ALTER SERVER name OWNER TO RoleSpec
   10570             :                 {
   10571          68 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10572             : 
   10573          68 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10574          68 :                     n->object = (Node *) makeString($3);
   10575          68 :                     n->newowner = $6;
   10576          68 :                     $$ = (Node *) n;
   10577             :                 }
   10578             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10579             :                 {
   10580          14 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10581             : 
   10582          14 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10583          14 :                     n->object = (Node *) makeString($4);
   10584          14 :                     n->newowner = $7;
   10585          14 :                     $$ = (Node *) n;
   10586             :                 }
   10587             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10588             :                 {
   10589          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10590             : 
   10591          26 :                     n->objectType = OBJECT_PUBLICATION;
   10592          26 :                     n->object = (Node *) makeString($3);
   10593          26 :                     n->newowner = $6;
   10594          26 :                     $$ = (Node *) n;
   10595             :                 }
   10596             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10597             :                 {
   10598          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10599             : 
   10600          18 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10601          18 :                     n->object = (Node *) makeString($3);
   10602          18 :                     n->newowner = $6;
   10603          18 :                     $$ = (Node *) n;
   10604             :                 }
   10605             :         ;
   10606             : 
   10607             : 
   10608             : /*****************************************************************************
   10609             :  *
   10610             :  * CREATE PUBLICATION name [WITH options]
   10611             :  *
   10612             :  * CREATE PUBLICATION FOR ALL TABLES [WITH options]
   10613             :  *
   10614             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10615             :  *
   10616             :  * pub_obj is one of:
   10617             :  *
   10618             :  *      TABLE table [, ...]
   10619             :  *      TABLES IN SCHEMA schema [, ...]
   10620             :  *
   10621             :  *****************************************************************************/
   10622             : 
   10623             : CreatePublicationStmt:
   10624             :             CREATE PUBLICATION name opt_definition
   10625             :                 {
   10626         124 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10627             : 
   10628         124 :                     n->pubname = $3;
   10629         124 :                     n->options = $4;
   10630         124 :                     $$ = (Node *) n;
   10631             :                 }
   10632             :             | CREATE PUBLICATION name FOR ALL TABLES opt_definition
   10633             :                 {
   10634          94 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10635             : 
   10636          94 :                     n->pubname = $3;
   10637          94 :                     n->options = $7;
   10638          94 :                     n->for_all_tables = true;
   10639          94 :                     $$ = (Node *) n;
   10640             :                 }
   10641             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10642             :                 {
   10643         622 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10644             : 
   10645         622 :                     n->pubname = $3;
   10646         622 :                     n->options = $6;
   10647         622 :                     n->pubobjects = (List *) $5;
   10648         622 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10649         592 :                     $$ = (Node *) n;
   10650             :                 }
   10651             :         ;
   10652             : 
   10653             : /*
   10654             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10655             :  *
   10656             :  * This rule parses publication objects with and without keyword prefixes.
   10657             :  *
   10658             :  * The actual type of the object without keyword prefix depends on the previous
   10659             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10660             :  *
   10661             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10662             :  * because some extended expressions in relation_expr cannot be used as a
   10663             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10664             :  * relation_expr here.
   10665             :  */
   10666             : PublicationObjSpec:
   10667             :             TABLE relation_expr opt_column_list OptWhereClause
   10668             :                 {
   10669        1272 :                     $$ = makeNode(PublicationObjSpec);
   10670        1272 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10671        1272 :                     $$->pubtable = makeNode(PublicationTable);
   10672        1272 :                     $$->pubtable->relation = $2;
   10673        1272 :                     $$->pubtable->columns = $3;
   10674        1272 :                     $$->pubtable->whereClause = $4;
   10675             :                 }
   10676             :             | TABLES IN_P SCHEMA ColId
   10677             :                 {
   10678         332 :                     $$ = makeNode(PublicationObjSpec);
   10679         332 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10680         332 :                     $$->name = $4;
   10681         332 :                     $$->location = @4;
   10682             :                 }
   10683             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10684             :                 {
   10685          18 :                     $$ = makeNode(PublicationObjSpec);
   10686          18 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10687          18 :                     $$->location = @4;
   10688             :                 }
   10689             :             | ColId opt_column_list OptWhereClause
   10690             :                 {
   10691         128 :                     $$ = makeNode(PublicationObjSpec);
   10692         128 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10693             :                     /*
   10694             :                      * If either a row filter or column list is specified, create
   10695             :                      * a PublicationTable object.
   10696             :                      */
   10697         128 :                     if ($2 || $3)
   10698             :                     {
   10699             :                         /*
   10700             :                          * The OptWhereClause must be stored here but it is
   10701             :                          * valid only for tables. For non-table objects, an
   10702             :                          * error will be thrown later via
   10703             :                          * preprocess_pubobj_list().
   10704             :                          */
   10705          42 :                         $$->pubtable = makeNode(PublicationTable);
   10706          42 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10707          42 :                         $$->pubtable->columns = $2;
   10708          42 :                         $$->pubtable->whereClause = $3;
   10709             :                     }
   10710             :                     else
   10711             :                     {
   10712          86 :                         $$->name = $1;
   10713             :                     }
   10714         128 :                     $$->location = @1;
   10715             :                 }
   10716             :             | ColId indirection opt_column_list OptWhereClause
   10717             :                 {
   10718          32 :                     $$ = makeNode(PublicationObjSpec);
   10719          32 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10720          32 :                     $$->pubtable = makeNode(PublicationTable);
   10721          32 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10722          32 :                     $$->pubtable->columns = $3;
   10723          32 :                     $$->pubtable->whereClause = $4;
   10724          32 :                     $$->location = @1;
   10725             :                 }
   10726             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10727             :             | extended_relation_expr opt_column_list OptWhereClause
   10728             :                 {
   10729           6 :                     $$ = makeNode(PublicationObjSpec);
   10730           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10731           6 :                     $$->pubtable = makeNode(PublicationTable);
   10732           6 :                     $$->pubtable->relation = $1;
   10733           6 :                     $$->pubtable->columns = $2;
   10734           6 :                     $$->pubtable->whereClause = $3;
   10735             :                 }
   10736             :             | CURRENT_SCHEMA
   10737             :                 {
   10738          18 :                     $$ = makeNode(PublicationObjSpec);
   10739          18 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10740          18 :                     $$->location = @1;
   10741             :                 }
   10742             :                 ;
   10743             : 
   10744             : pub_obj_list:   PublicationObjSpec
   10745        1584 :                     { $$ = list_make1($1); }
   10746             :             | pub_obj_list ',' PublicationObjSpec
   10747         222 :                     { $$ = lappend($1, $3); }
   10748             :     ;
   10749             : 
   10750             : /*****************************************************************************
   10751             :  *
   10752             :  * ALTER PUBLICATION name SET ( options )
   10753             :  *
   10754             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10755             :  *
   10756             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10757             :  *
   10758             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10759             :  *
   10760             :  * pub_obj is one of:
   10761             :  *
   10762             :  *      TABLE table_name [, ...]
   10763             :  *      TABLES IN SCHEMA schema_name [, ...]
   10764             :  *
   10765             :  *****************************************************************************/
   10766             : 
   10767             : AlterPublicationStmt:
   10768             :             ALTER PUBLICATION name SET definition
   10769             :                 {
   10770         116 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10771             : 
   10772         116 :                     n->pubname = $3;
   10773         116 :                     n->options = $5;
   10774         116 :                     $$ = (Node *) n;
   10775             :                 }
   10776             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10777             :                 {
   10778         344 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10779             : 
   10780         344 :                     n->pubname = $3;
   10781         344 :                     n->pubobjects = $5;
   10782         344 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10783         338 :                     n->action = AP_AddObjects;
   10784         338 :                     $$ = (Node *) n;
   10785             :                 }
   10786             :             | ALTER PUBLICATION name SET pub_obj_list
   10787             :                 {
   10788         464 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10789             : 
   10790         464 :                     n->pubname = $3;
   10791         464 :                     n->pubobjects = $5;
   10792         464 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10793         464 :                     n->action = AP_SetObjects;
   10794         464 :                     $$ = (Node *) n;
   10795             :                 }
   10796             :             | ALTER PUBLICATION name DROP pub_obj_list
   10797             :                 {
   10798         154 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10799             : 
   10800         154 :                     n->pubname = $3;
   10801         154 :                     n->pubobjects = $5;
   10802         154 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10803         154 :                     n->action = AP_DropObjects;
   10804         154 :                     $$ = (Node *) n;
   10805             :                 }
   10806             :         ;
   10807             : 
   10808             : /*****************************************************************************
   10809             :  *
   10810             :  * CREATE SUBSCRIPTION name ...
   10811             :  *
   10812             :  *****************************************************************************/
   10813             : 
   10814             : CreateSubscriptionStmt:
   10815             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10816             :                 {
   10817             :                     CreateSubscriptionStmt *n =
   10818         446 :                         makeNode(CreateSubscriptionStmt);
   10819         446 :                     n->subname = $3;
   10820         446 :                     n->conninfo = $5;
   10821         446 :                     n->publication = $7;
   10822         446 :                     n->options = $8;
   10823         446 :                     $$ = (Node *) n;
   10824             :                 }
   10825             :         ;
   10826             : 
   10827             : /*****************************************************************************
   10828             :  *
   10829             :  * ALTER SUBSCRIPTION name ...
   10830             :  *
   10831             :  *****************************************************************************/
   10832             : 
   10833             : AlterSubscriptionStmt:
   10834             :             ALTER SUBSCRIPTION name SET definition
   10835             :                 {
   10836             :                     AlterSubscriptionStmt *n =
   10837         184 :                         makeNode(AlterSubscriptionStmt);
   10838             : 
   10839         184 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10840         184 :                     n->subname = $3;
   10841         184 :                     n->options = $5;
   10842         184 :                     $$ = (Node *) n;
   10843             :                 }
   10844             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10845             :                 {
   10846             :                     AlterSubscriptionStmt *n =
   10847          26 :                         makeNode(AlterSubscriptionStmt);
   10848             : 
   10849          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10850          26 :                     n->subname = $3;
   10851          26 :                     n->conninfo = $5;
   10852          26 :                     $$ = (Node *) n;
   10853             :                 }
   10854             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10855             :                 {
   10856             :                     AlterSubscriptionStmt *n =
   10857          58 :                         makeNode(AlterSubscriptionStmt);
   10858             : 
   10859          58 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
   10860          58 :                     n->subname = $3;
   10861          58 :                     n->options = $6;
   10862          58 :                     $$ = (Node *) n;
   10863             :                 }
   10864             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   10865             :                 {
   10866             :                     AlterSubscriptionStmt *n =
   10867          28 :                         makeNode(AlterSubscriptionStmt);
   10868             : 
   10869          28 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   10870          28 :                     n->subname = $3;
   10871          28 :                     n->publication = $6;
   10872          28 :                     n->options = $7;
   10873          28 :                     $$ = (Node *) n;
   10874             :                 }
   10875             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   10876             :                 {
   10877             :                     AlterSubscriptionStmt *n =
   10878          26 :                         makeNode(AlterSubscriptionStmt);
   10879             : 
   10880          26 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   10881          26 :                     n->subname = $3;
   10882          26 :                     n->publication = $6;
   10883          26 :                     n->options = $7;
   10884          26 :                     $$ = (Node *) n;
   10885             :                 }
   10886             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   10887             :                 {
   10888             :                     AlterSubscriptionStmt *n =
   10889          44 :                         makeNode(AlterSubscriptionStmt);
   10890             : 
   10891          44 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   10892          44 :                     n->subname = $3;
   10893          44 :                     n->publication = $6;
   10894          44 :                     n->options = $7;
   10895          44 :                     $$ = (Node *) n;
   10896             :                 }
   10897             :             | ALTER SUBSCRIPTION name ENABLE_P
   10898             :                 {
   10899             :                     AlterSubscriptionStmt *n =
   10900          48 :                         makeNode(AlterSubscriptionStmt);
   10901             : 
   10902          48 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10903          48 :                     n->subname = $3;
   10904          48 :                     n->options = list_make1(makeDefElem("enabled",
   10905             :                                             (Node *) makeBoolean(true), @1));
   10906          48 :                     $$ = (Node *) n;
   10907             :                 }
   10908             :             | ALTER SUBSCRIPTION name DISABLE_P
   10909             :                 {
   10910             :                     AlterSubscriptionStmt *n =
   10911          32 :                         makeNode(AlterSubscriptionStmt);
   10912             : 
   10913          32 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10914          32 :                     n->subname = $3;
   10915          32 :                     n->options = list_make1(makeDefElem("enabled",
   10916             :                                             (Node *) makeBoolean(false), @1));
   10917          32 :                     $$ = (Node *) n;
   10918             :                 }
   10919             :             | ALTER SUBSCRIPTION name SKIP definition
   10920             :                 {
   10921             :                     AlterSubscriptionStmt *n =
   10922          24 :                         makeNode(AlterSubscriptionStmt);
   10923             : 
   10924          24 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   10925          24 :                     n->subname = $3;
   10926          24 :                     n->options = $5;
   10927          24 :                     $$ = (Node *) n;
   10928             :                 }
   10929             :         ;
   10930             : 
   10931             : /*****************************************************************************
   10932             :  *
   10933             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   10934             :  *
   10935             :  *****************************************************************************/
   10936             : 
   10937             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   10938             :                 {
   10939         222 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10940             : 
   10941         222 :                     n->subname = $3;
   10942         222 :                     n->missing_ok = false;
   10943         222 :                     n->behavior = $4;
   10944         222 :                     $$ = (Node *) n;
   10945             :                 }
   10946             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   10947             :                 {
   10948           6 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10949             : 
   10950           6 :                     n->subname = $5;
   10951           6 :                     n->missing_ok = true;
   10952           6 :                     n->behavior = $6;
   10953           6 :                     $$ = (Node *) n;
   10954             :                 }
   10955             :         ;
   10956             : 
   10957             : /*****************************************************************************
   10958             :  *
   10959             :  *      QUERY:  Define Rewrite Rule
   10960             :  *
   10961             :  *****************************************************************************/
   10962             : 
   10963             : RuleStmt:   CREATE opt_or_replace RULE name AS
   10964             :             ON event TO qualified_name where_clause
   10965             :             DO opt_instead RuleActionList
   10966             :                 {
   10967        1072 :                     RuleStmt   *n = makeNode(RuleStmt);
   10968             : 
   10969        1072 :                     n->replace = $2;
   10970        1072 :                     n->relation = $9;
   10971        1072 :                     n->rulename = $4;
   10972        1072 :                     n->whereClause = $10;
   10973        1072 :                     n->event = $7;
   10974        1072 :                     n->instead = $12;
   10975        1072 :                     n->actions = $13;
   10976        1072 :                     $$ = (Node *) n;
   10977             :                 }
   10978             :         ;
   10979             : 
   10980             : RuleActionList:
   10981         152 :             NOTHING                                 { $$ = NIL; }
   10982         874 :             | RuleActionStmt                        { $$ = list_make1($1); }
   10983          46 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   10984             :         ;
   10985             : 
   10986             : /* the thrashing around here is to discard "empty" statements... */
   10987             : RuleActionMulti:
   10988             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   10989          62 :                 { if ($3 != NULL)
   10990          46 :                     $$ = lappend($1, $3);
   10991             :                   else
   10992          16 :                     $$ = $1;
   10993             :                 }
   10994             :             | RuleActionStmtOrEmpty
   10995          46 :                 { if ($1 != NULL)
   10996          46 :                     $$ = list_make1($1);
   10997             :                   else
   10998           0 :                     $$ = NIL;
   10999             :                 }
   11000             :         ;
   11001             : 
   11002             : RuleActionStmt:
   11003             :             SelectStmt
   11004             :             | InsertStmt
   11005             :             | UpdateStmt
   11006             :             | DeleteStmt
   11007             :             | NotifyStmt
   11008             :         ;
   11009             : 
   11010             : RuleActionStmtOrEmpty:
   11011          92 :             RuleActionStmt                          { $$ = $1; }
   11012          16 :             |   /*EMPTY*/                           { $$ = NULL; }
   11013             :         ;
   11014             : 
   11015          18 : event:      SELECT                                  { $$ = CMD_SELECT; }
   11016         412 :             | UPDATE                                { $$ = CMD_UPDATE; }
   11017         164 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11018         478 :             | INSERT                                { $$ = CMD_INSERT; }
   11019             :          ;
   11020             : 
   11021             : opt_instead:
   11022         742 :             INSTEAD                                 { $$ = true; }
   11023         156 :             | ALSO                                  { $$ = false; }
   11024         174 :             | /*EMPTY*/                             { $$ = false; }
   11025             :         ;
   11026             : 
   11027             : 
   11028             : /*****************************************************************************
   11029             :  *
   11030             :  *      QUERY:
   11031             :  *              NOTIFY <identifier> can appear both in rule bodies and
   11032             :  *              as a query-level command
   11033             :  *
   11034             :  *****************************************************************************/
   11035             : 
   11036             : NotifyStmt: NOTIFY ColId notify_payload
   11037             :                 {
   11038         128 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11039             : 
   11040         128 :                     n->conditionname = $2;
   11041         128 :                     n->payload = $3;
   11042         128 :                     $$ = (Node *) n;
   11043             :                 }
   11044             :         ;
   11045             : 
   11046             : notify_payload:
   11047          62 :             ',' Sconst                          { $$ = $2; }
   11048          66 :             | /*EMPTY*/                         { $$ = NULL; }
   11049             :         ;
   11050             : 
   11051             : ListenStmt: LISTEN ColId
   11052             :                 {
   11053          74 :                     ListenStmt *n = makeNode(ListenStmt);
   11054             : 
   11055          74 :                     n->conditionname = $2;
   11056          74 :                     $$ = (Node *) n;
   11057             :                 }
   11058             :         ;
   11059             : 
   11060             : UnlistenStmt:
   11061             :             UNLISTEN ColId
   11062             :                 {
   11063           6 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11064             : 
   11065           6 :                     n->conditionname = $2;
   11066           6 :                     $$ = (Node *) n;
   11067             :                 }
   11068             :             | UNLISTEN '*'
   11069             :                 {
   11070          32 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11071             : 
   11072          32 :                     n->conditionname = NULL;
   11073          32 :                     $$ = (Node *) n;
   11074             :                 }
   11075             :         ;
   11076             : 
   11077             : 
   11078             : /*****************************************************************************
   11079             :  *
   11080             :  *      Transactions:
   11081             :  *
   11082             :  *      BEGIN / COMMIT / ROLLBACK
   11083             :  *      (also older versions END / ABORT)
   11084             :  *
   11085             :  *****************************************************************************/
   11086             : 
   11087             : TransactionStmt:
   11088             :             ABORT_P opt_transaction opt_transaction_chain
   11089             :                 {
   11090         216 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11091             : 
   11092         216 :                     n->kind = TRANS_STMT_ROLLBACK;
   11093         216 :                     n->options = NIL;
   11094         216 :                     n->chain = $3;
   11095         216 :                     n->location = -1;
   11096         216 :                     $$ = (Node *) n;
   11097             :                 }
   11098             :             | START TRANSACTION transaction_mode_list_or_empty
   11099             :                 {
   11100        1604 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11101             : 
   11102        1604 :                     n->kind = TRANS_STMT_START;
   11103        1604 :                     n->options = $3;
   11104        1604 :                     n->location = -1;
   11105        1604 :                     $$ = (Node *) n;
   11106             :                 }
   11107             :             | COMMIT opt_transaction opt_transaction_chain
   11108             :                 {
   11109       11706 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11110             : 
   11111       11706 :                     n->kind = TRANS_STMT_COMMIT;
   11112       11706 :                     n->options = NIL;
   11113       11706 :                     n->chain = $3;
   11114       11706 :                     n->location = -1;
   11115       11706 :                     $$ = (Node *) n;
   11116             :                 }
   11117             :             | ROLLBACK opt_transaction opt_transaction_chain
   11118             :                 {
   11119        2580 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11120             : 
   11121        2580 :                     n->kind = TRANS_STMT_ROLLBACK;
   11122        2580 :                     n->options = NIL;
   11123        2580 :                     n->chain = $3;
   11124        2580 :                     n->location = -1;
   11125        2580 :                     $$ = (Node *) n;
   11126             :                 }
   11127             :             | SAVEPOINT ColId
   11128             :                 {
   11129        1924 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11130             : 
   11131        1924 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11132        1924 :                     n->savepoint_name = $2;
   11133        1924 :                     n->location = @2;
   11134        1924 :                     $$ = (Node *) n;
   11135             :                 }
   11136             :             | RELEASE SAVEPOINT ColId
   11137             :                 {
   11138         208 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11139             : 
   11140         208 :                     n->kind = TRANS_STMT_RELEASE;
   11141         208 :                     n->savepoint_name = $3;
   11142         208 :                     n->location = @3;
   11143         208 :                     $$ = (Node *) n;
   11144             :                 }
   11145             :             | RELEASE ColId
   11146             :                 {
   11147          86 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11148             : 
   11149          86 :                     n->kind = TRANS_STMT_RELEASE;
   11150          86 :                     n->savepoint_name = $2;
   11151          86 :                     n->location = @2;
   11152          86 :                     $$ = (Node *) n;
   11153             :                 }
   11154             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11155             :                 {
   11156         224 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11157             : 
   11158         224 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11159         224 :                     n->savepoint_name = $5;
   11160         224 :                     n->location = @5;
   11161         224 :                     $$ = (Node *) n;
   11162             :                 }
   11163             :             | ROLLBACK opt_transaction TO ColId
   11164             :                 {
   11165         496 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11166             : 
   11167         496 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11168         496 :                     n->savepoint_name = $4;
   11169         496 :                     n->location = @4;
   11170         496 :                     $$ = (Node *) n;
   11171             :                 }
   11172             :             | PREPARE TRANSACTION Sconst
   11173             :                 {
   11174         666 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11175             : 
   11176         666 :                     n->kind = TRANS_STMT_PREPARE;
   11177         666 :                     n->gid = $3;
   11178         666 :                     n->location = @3;
   11179         666 :                     $$ = (Node *) n;
   11180             :                 }
   11181             :             | COMMIT PREPARED Sconst
   11182             :                 {
   11183         510 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11184             : 
   11185         510 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11186         510 :                     n->gid = $3;
   11187         510 :                     n->location = @3;
   11188         510 :                     $$ = (Node *) n;
   11189             :                 }
   11190             :             | ROLLBACK PREPARED Sconst
   11191             :                 {
   11192          76 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11193             : 
   11194          76 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11195          76 :                     n->gid = $3;
   11196          76 :                     n->location = @3;
   11197          76 :                     $$ = (Node *) n;
   11198             :                 }
   11199             :         ;
   11200             : 
   11201             : TransactionStmtLegacy:
   11202             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11203             :                 {
   11204       14264 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11205             : 
   11206       14264 :                     n->kind = TRANS_STMT_BEGIN;
   11207       14264 :                     n->options = $3;
   11208       14264 :                     n->location = -1;
   11209       14264 :                     $$ = (Node *) n;
   11210             :                 }
   11211             :             | END_P opt_transaction opt_transaction_chain
   11212             :                 {
   11213         360 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11214             : 
   11215         360 :                     n->kind = TRANS_STMT_COMMIT;
   11216         360 :                     n->options = NIL;
   11217         360 :                     n->chain = $3;
   11218         360 :                     n->location = -1;
   11219         360 :                     $$ = (Node *) n;
   11220             :                 }
   11221             :         ;
   11222             : 
   11223             : opt_transaction:    WORK
   11224             :             | TRANSACTION
   11225             :             | /*EMPTY*/
   11226             :         ;
   11227             : 
   11228             : transaction_mode_item:
   11229             :             ISOLATION LEVEL iso_level
   11230        6656 :                     { $$ = makeDefElem("transaction_isolation",
   11231        6656 :                                        makeStringConst($3, @3), @1); }
   11232             :             | READ ONLY
   11233        1388 :                     { $$ = makeDefElem("transaction_read_only",
   11234        1388 :                                        makeIntConst(true, @1), @1); }
   11235             :             | READ WRITE
   11236          90 :                     { $$ = makeDefElem("transaction_read_only",
   11237          90 :                                        makeIntConst(false, @1), @1); }
   11238             :             | DEFERRABLE
   11239          44 :                     { $$ = makeDefElem("transaction_deferrable",
   11240             :                                        makeIntConst(true, @1), @1); }
   11241             :             | NOT DEFERRABLE
   11242          10 :                     { $$ = makeDefElem("transaction_deferrable",
   11243          10 :                                        makeIntConst(false, @1), @1); }
   11244             :         ;
   11245             : 
   11246             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11247             : transaction_mode_list:
   11248             :             transaction_mode_item
   11249        6872 :                     { $$ = list_make1($1); }
   11250             :             | transaction_mode_list ',' transaction_mode_item
   11251         924 :                     { $$ = lappend($1, $3); }
   11252             :             | transaction_mode_list transaction_mode_item
   11253         392 :                     { $$ = lappend($1, $2); }
   11254             :         ;
   11255             : 
   11256             : transaction_mode_list_or_empty:
   11257             :             transaction_mode_list
   11258             :             | /* EMPTY */
   11259        9580 :                     { $$ = NIL; }
   11260             :         ;
   11261             : 
   11262             : opt_transaction_chain:
   11263         120 :             AND CHAIN       { $$ = true; }
   11264           2 :             | AND NO CHAIN  { $$ = false; }
   11265       14740 :             | /* EMPTY */   { $$ = false; }
   11266             :         ;
   11267             : 
   11268             : 
   11269             : /*****************************************************************************
   11270             :  *
   11271             :  *  QUERY:
   11272             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11273             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11274             :  *
   11275             :  *****************************************************************************/
   11276             : 
   11277             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11278             :                 AS SelectStmt opt_check_option
   11279             :                 {
   11280       14954 :                     ViewStmt   *n = makeNode(ViewStmt);
   11281             : 
   11282       14954 :                     n->view = $4;
   11283       14954 :                     n->view->relpersistence = $2;
   11284       14954 :                     n->aliases = $5;
   11285       14954 :                     n->query = $8;
   11286       14954 :                     n->replace = false;
   11287       14954 :                     n->options = $6;
   11288       14954 :                     n->withCheckOption = $9;
   11289       14954 :                     $$ = (Node *) n;
   11290             :                 }
   11291             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11292             :                 AS SelectStmt opt_check_option
   11293             :                 {
   11294         244 :                     ViewStmt   *n = makeNode(ViewStmt);
   11295             : 
   11296         244 :                     n->view = $6;
   11297         244 :                     n->view->relpersistence = $4;
   11298         244 :                     n->aliases = $7;
   11299         244 :                     n->query = $10;
   11300         244 :                     n->replace = true;
   11301         244 :                     n->options = $8;
   11302         244 :                     n->withCheckOption = $11;
   11303         244 :                     $$ = (Node *) n;
   11304             :                 }
   11305             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11306             :                 AS SelectStmt opt_check_option
   11307             :                 {
   11308           8 :                     ViewStmt   *n = makeNode(ViewStmt);
   11309             : 
   11310           8 :                     n->view = $5;
   11311           8 :                     n->view->relpersistence = $2;
   11312           8 :                     n->aliases = $7;
   11313           8 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11314           8 :                     n->replace = false;
   11315           8 :                     n->options = $9;
   11316           8 :                     n->withCheckOption = $12;
   11317           8 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11318           0 :                         ereport(ERROR,
   11319             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11320             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11321             :                                  parser_errposition(@12)));
   11322           8 :                     $$ = (Node *) n;
   11323             :                 }
   11324             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11325             :                 AS SelectStmt opt_check_option
   11326             :                 {
   11327           6 :                     ViewStmt   *n = makeNode(ViewStmt);
   11328             : 
   11329           6 :                     n->view = $7;
   11330           6 :                     n->view->relpersistence = $4;
   11331           6 :                     n->aliases = $9;
   11332           6 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11333           6 :                     n->replace = true;
   11334           6 :                     n->options = $11;
   11335           6 :                     n->withCheckOption = $14;
   11336           6 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11337           0 :                         ereport(ERROR,
   11338             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11339             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11340             :                                  parser_errposition(@14)));
   11341           6 :                     $$ = (Node *) n;
   11342             :                 }
   11343             :         ;
   11344             : 
   11345             : opt_check_option:
   11346          96 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11347           6 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11348          24 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11349       15086 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11350             :         ;
   11351             : 
   11352             : /*****************************************************************************
   11353             :  *
   11354             :  *      QUERY:
   11355             :  *              LOAD "filename"
   11356             :  *
   11357             :  *****************************************************************************/
   11358             : 
   11359             : LoadStmt:   LOAD file_name
   11360             :                 {
   11361          60 :                     LoadStmt   *n = makeNode(LoadStmt);
   11362             : 
   11363          60 :                     n->filename = $2;
   11364          60 :                     $$ = (Node *) n;
   11365             :                 }
   11366             :         ;
   11367             : 
   11368             : 
   11369             : /*****************************************************************************
   11370             :  *
   11371             :  *      CREATE DATABASE
   11372             :  *
   11373             :  *****************************************************************************/
   11374             : 
   11375             : CreatedbStmt:
   11376             :             CREATE DATABASE name opt_with createdb_opt_list
   11377             :                 {
   11378         736 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11379             : 
   11380         736 :                     n->dbname = $3;
   11381         736 :                     n->options = $5;
   11382         736 :                     $$ = (Node *) n;
   11383             :                 }
   11384             :         ;
   11385             : 
   11386             : createdb_opt_list:
   11387         596 :             createdb_opt_items                      { $$ = $1; }
   11388         200 :             | /* EMPTY */                           { $$ = NIL; }
   11389             :         ;
   11390             : 
   11391             : createdb_opt_items:
   11392         596 :             createdb_opt_item                       { $$ = list_make1($1); }
   11393         886 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11394             :         ;
   11395             : 
   11396             : createdb_opt_item:
   11397             :             createdb_opt_name opt_equal NumericOnly
   11398             :                 {
   11399         238 :                     $$ = makeDefElem($1, $3, @1);
   11400             :                 }
   11401             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11402             :                 {
   11403        1244 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11404             :                 }
   11405             :             | createdb_opt_name opt_equal DEFAULT
   11406             :                 {
   11407           0 :                     $$ = makeDefElem($1, NULL, @1);
   11408             :                 }
   11409             :         ;
   11410             : 
   11411             : /*
   11412             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11413             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11414             :  * we need, and allow IDENT so that database option names don't have to be
   11415             :  * parser keywords unless they are already keywords for other reasons.
   11416             :  *
   11417             :  * XXX this coding technique is fragile since if someone makes a formerly
   11418             :  * non-keyword option name into a keyword and forgets to add it here, the
   11419             :  * option will silently break.  Best defense is to provide a regression test
   11420             :  * exercising every such option, at least at the syntax level.
   11421             :  */
   11422             : createdb_opt_name:
   11423        1036 :             IDENT                           { $$ = $1; }
   11424           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11425          96 :             | ENCODING                      { $$ = pstrdup($1); }
   11426           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11427           2 :             | OWNER                         { $$ = pstrdup($1); }
   11428          16 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11429         330 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11430             :         ;
   11431             : 
   11432             : /*
   11433             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11434             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11435             :  */
   11436             : opt_equal:  '='
   11437             :             | /*EMPTY*/
   11438             :         ;
   11439             : 
   11440             : 
   11441             : /*****************************************************************************
   11442             :  *
   11443             :  *      ALTER DATABASE
   11444             :  *
   11445             :  *****************************************************************************/
   11446             : 
   11447             : AlterDatabaseStmt:
   11448             :             ALTER DATABASE name WITH createdb_opt_list
   11449             :                  {
   11450           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11451             : 
   11452           0 :                     n->dbname = $3;
   11453           0 :                     n->options = $5;
   11454           0 :                     $$ = (Node *) n;
   11455             :                  }
   11456             :             | ALTER DATABASE name createdb_opt_list
   11457             :                  {
   11458          60 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11459             : 
   11460          60 :                     n->dbname = $3;
   11461          60 :                     n->options = $4;
   11462          60 :                     $$ = (Node *) n;
   11463             :                  }
   11464             :             | ALTER DATABASE name SET TABLESPACE name
   11465             :                  {
   11466          16 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11467             : 
   11468          16 :                     n->dbname = $3;
   11469          16 :                     n->options = list_make1(makeDefElem("tablespace",
   11470             :                                                         (Node *) makeString($6), @6));
   11471          16 :                     $$ = (Node *) n;
   11472             :                  }
   11473             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11474             :                  {
   11475           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11476             : 
   11477           6 :                     n->dbname = $3;
   11478           6 :                     $$ = (Node *) n;
   11479             :                  }
   11480             :         ;
   11481             : 
   11482             : AlterDatabaseSetStmt:
   11483             :             ALTER DATABASE name SetResetClause
   11484             :                 {
   11485        1162 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11486             : 
   11487        1162 :                     n->dbname = $3;
   11488        1162 :                     n->setstmt = $4;
   11489        1162 :                     $$ = (Node *) n;
   11490             :                 }
   11491             :         ;
   11492             : 
   11493             : 
   11494             : /*****************************************************************************
   11495             :  *
   11496             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11497             :  *
   11498             :  * This is implicitly CASCADE, no need for drop behavior
   11499             :  *****************************************************************************/
   11500             : 
   11501             : DropdbStmt: DROP DATABASE name
   11502             :                 {
   11503          92 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11504             : 
   11505          92 :                     n->dbname = $3;
   11506          92 :                     n->missing_ok = false;
   11507          92 :                     n->options = NULL;
   11508          92 :                     $$ = (Node *) n;
   11509             :                 }
   11510             :             | DROP DATABASE IF_P EXISTS name
   11511             :                 {
   11512           4 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11513             : 
   11514           4 :                     n->dbname = $5;
   11515           4 :                     n->missing_ok = true;
   11516           4 :                     n->options = NULL;
   11517           4 :                     $$ = (Node *) n;
   11518             :                 }
   11519             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11520             :                 {
   11521          14 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11522             : 
   11523          14 :                     n->dbname = $3;
   11524          14 :                     n->missing_ok = false;
   11525          14 :                     n->options = $6;
   11526          14 :                     $$ = (Node *) n;
   11527             :                 }
   11528             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11529             :                 {
   11530          12 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11531             : 
   11532          12 :                     n->dbname = $5;
   11533          12 :                     n->missing_ok = true;
   11534          12 :                     n->options = $8;
   11535          12 :                     $$ = (Node *) n;
   11536             :                 }
   11537             :         ;
   11538             : 
   11539             : drop_option_list:
   11540             :             drop_option
   11541             :                 {
   11542          26 :                     $$ = list_make1((Node *) $1);
   11543             :                 }
   11544             :             | drop_option_list ',' drop_option
   11545             :                 {
   11546           0 :                     $$ = lappend($1, (Node *) $3);
   11547             :                 }
   11548             :         ;
   11549             : 
   11550             : /*
   11551             :  * Currently only the FORCE option is supported, but the syntax is designed
   11552             :  * to be extensible so that we can add more options in the future if required.
   11553             :  */
   11554             : drop_option:
   11555             :             FORCE
   11556             :                 {
   11557          26 :                     $$ = makeDefElem("force", NULL, @1);
   11558             :                 }
   11559             :         ;
   11560             : 
   11561             : /*****************************************************************************
   11562             :  *
   11563             :  *      ALTER COLLATION
   11564             :  *
   11565             :  *****************************************************************************/
   11566             : 
   11567             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11568             :                 {
   11569           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11570             : 
   11571           6 :                     n->collname = $3;
   11572           6 :                     $$ = (Node *) n;
   11573             :                 }
   11574             :         ;
   11575             : 
   11576             : 
   11577             : /*****************************************************************************
   11578             :  *
   11579             :  *      ALTER SYSTEM
   11580             :  *
   11581             :  * This is used to change configuration parameters persistently.
   11582             :  *****************************************************************************/
   11583             : 
   11584             : AlterSystemStmt:
   11585             :             ALTER SYSTEM_P SET generic_set
   11586             :                 {
   11587         116 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11588             : 
   11589         116 :                     n->setstmt = $4;
   11590         116 :                     $$ = (Node *) n;
   11591             :                 }
   11592             :             | ALTER SYSTEM_P RESET generic_reset
   11593             :                 {
   11594          54 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11595             : 
   11596          54 :                     n->setstmt = $4;
   11597          54 :                     $$ = (Node *) n;
   11598             :                 }
   11599             :         ;
   11600             : 
   11601             : 
   11602             : /*****************************************************************************
   11603             :  *
   11604             :  * Manipulate a domain
   11605             :  *
   11606             :  *****************************************************************************/
   11607             : 
   11608             : CreateDomainStmt:
   11609             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11610             :                 {
   11611        1372 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11612             : 
   11613        1372 :                     n->domainname = $3;
   11614        1372 :                     n->typeName = $5;
   11615        1372 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11616             :                                      yyscanner);
   11617        1372 :                     $$ = (Node *) n;
   11618             :                 }
   11619             :         ;
   11620             : 
   11621             : AlterDomainStmt:
   11622             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11623             :             ALTER DOMAIN_P any_name alter_column_default
   11624             :                 {
   11625          14 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11626             : 
   11627          14 :                     n->subtype = 'T';
   11628          14 :                     n->typeName = $3;
   11629          14 :                     n->def = $4;
   11630          14 :                     $$ = (Node *) n;
   11631             :                 }
   11632             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11633             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11634             :                 {
   11635          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11636             : 
   11637          12 :                     n->subtype = 'N';
   11638          12 :                     n->typeName = $3;
   11639          12 :                     $$ = (Node *) n;
   11640             :                 }
   11641             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11642             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11643             :                 {
   11644          24 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11645             : 
   11646          24 :                     n->subtype = 'O';
   11647          24 :                     n->typeName = $3;
   11648          24 :                     $$ = (Node *) n;
   11649             :                 }
   11650             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11651             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11652             :                 {
   11653         174 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11654             : 
   11655         174 :                     n->subtype = 'C';
   11656         174 :                     n->typeName = $3;
   11657         174 :                     n->def = $5;
   11658         174 :                     $$ = (Node *) n;
   11659             :                 }
   11660             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11661             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11662             :                 {
   11663          54 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11664             : 
   11665          54 :                     n->subtype = 'X';
   11666          54 :                     n->typeName = $3;
   11667          54 :                     n->name = $6;
   11668          54 :                     n->behavior = $7;
   11669          54 :                     n->missing_ok = false;
   11670          54 :                     $$ = (Node *) n;
   11671             :                 }
   11672             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11673             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11674             :                 {
   11675           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11676             : 
   11677           6 :                     n->subtype = 'X';
   11678           6 :                     n->typeName = $3;
   11679           6 :                     n->name = $8;
   11680           6 :                     n->behavior = $9;
   11681           6 :                     n->missing_ok = true;
   11682           6 :                     $$ = (Node *) n;
   11683             :                 }
   11684             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11685             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11686             :                 {
   11687          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11688             : 
   11689          12 :                     n->subtype = 'V';
   11690          12 :                     n->typeName = $3;
   11691          12 :                     n->name = $6;
   11692          12 :                     $$ = (Node *) n;
   11693             :                 }
   11694             :             ;
   11695             : 
   11696             : opt_as:     AS
   11697             :             | /* EMPTY */
   11698             :         ;
   11699             : 
   11700             : 
   11701             : /*****************************************************************************
   11702             :  *
   11703             :  * Manipulate a text search dictionary or configuration
   11704             :  *
   11705             :  *****************************************************************************/
   11706             : 
   11707             : AlterTSDictionaryStmt:
   11708             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11709             :                 {
   11710          40 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11711             : 
   11712          40 :                     n->dictname = $5;
   11713          40 :                     n->options = $6;
   11714          40 :                     $$ = (Node *) n;
   11715             :                 }
   11716             :         ;
   11717             : 
   11718             : AlterTSConfigurationStmt:
   11719             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11720             :                 {
   11721        7648 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11722             : 
   11723        7648 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11724        7648 :                     n->cfgname = $5;
   11725        7648 :                     n->tokentype = $9;
   11726        7648 :                     n->dicts = $11;
   11727        7648 :                     n->override = false;
   11728        7648 :                     n->replace = false;
   11729        7648 :                     $$ = (Node *) n;
   11730             :                 }
   11731             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11732             :                 {
   11733          26 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11734             : 
   11735          26 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11736          26 :                     n->cfgname = $5;
   11737          26 :                     n->tokentype = $9;
   11738          26 :                     n->dicts = $11;
   11739          26 :                     n->override = true;
   11740          26 :                     n->replace = false;
   11741          26 :                     $$ = (Node *) n;
   11742             :                 }
   11743             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11744             :                 {
   11745          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11746             : 
   11747          18 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11748          18 :                     n->cfgname = $5;
   11749          18 :                     n->tokentype = NIL;
   11750          18 :                     n->dicts = list_make2($9,$11);
   11751          18 :                     n->override = false;
   11752          18 :                     n->replace = true;
   11753          18 :                     $$ = (Node *) n;
   11754             :                 }
   11755             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11756             :                 {
   11757           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11758             : 
   11759           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11760           0 :                     n->cfgname = $5;
   11761           0 :                     n->tokentype = $9;
   11762           0 :                     n->dicts = list_make2($11,$13);
   11763           0 :                     n->override = false;
   11764           0 :                     n->replace = true;
   11765           0 :                     $$ = (Node *) n;
   11766             :                 }
   11767             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11768             :                 {
   11769          18 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11770             : 
   11771          18 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11772          18 :                     n->cfgname = $5;
   11773          18 :                     n->tokentype = $9;
   11774          18 :                     n->missing_ok = false;
   11775          18 :                     $$ = (Node *) n;
   11776             :                 }
   11777             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11778             :                 {
   11779          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11780             : 
   11781          12 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11782          12 :                     n->cfgname = $5;
   11783          12 :                     n->tokentype = $11;
   11784          12 :                     n->missing_ok = true;
   11785          12 :                     $$ = (Node *) n;
   11786             :                 }
   11787             :         ;
   11788             : 
   11789             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11790             : any_with:   WITH
   11791             :             | WITH_LA
   11792             :         ;
   11793             : 
   11794             : 
   11795             : /*****************************************************************************
   11796             :  *
   11797             :  * Manipulate a conversion
   11798             :  *
   11799             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11800             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11801             :  *
   11802             :  *****************************************************************************/
   11803             : 
   11804             : CreateConversionStmt:
   11805             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11806             :             TO Sconst FROM any_name
   11807             :             {
   11808          64 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11809             : 
   11810          64 :                 n->conversion_name = $4;
   11811          64 :                 n->for_encoding_name = $6;
   11812          64 :                 n->to_encoding_name = $8;
   11813          64 :                 n->func_name = $10;
   11814          64 :                 n->def = $2;
   11815          64 :                 $$ = (Node *) n;
   11816             :             }
   11817             :         ;
   11818             : 
   11819             : /*****************************************************************************
   11820             :  *
   11821             :  *      QUERY:
   11822             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   11823             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   11824             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11825             :  *
   11826             :  *****************************************************************************/
   11827             : 
   11828             : ClusterStmt:
   11829             :             CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11830             :                 {
   11831           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11832             : 
   11833           0 :                     n->relation = $5;
   11834           0 :                     n->indexname = $6;
   11835           0 :                     n->params = $3;
   11836           0 :                     $$ = (Node *) n;
   11837             :                 }
   11838             :             | CLUSTER '(' utility_option_list ')'
   11839             :                 {
   11840           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11841             : 
   11842           0 :                     n->relation = NULL;
   11843           0 :                     n->indexname = NULL;
   11844           0 :                     n->params = $3;
   11845           0 :                     $$ = (Node *) n;
   11846             :                 }
   11847             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   11848             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   11849             :                 {
   11850         190 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11851             : 
   11852         190 :                     n->relation = $3;
   11853         190 :                     n->indexname = $4;
   11854         190 :                     n->params = NIL;
   11855         190 :                     if ($2)
   11856           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11857         190 :                     $$ = (Node *) n;
   11858             :                 }
   11859             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   11860             :             | CLUSTER opt_verbose
   11861             :                 {
   11862          28 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11863             : 
   11864          28 :                     n->relation = NULL;
   11865          28 :                     n->indexname = NULL;
   11866          28 :                     n->params = NIL;
   11867          28 :                     if ($2)
   11868          12 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11869          28 :                     $$ = (Node *) n;
   11870             :                 }
   11871             :             /* kept for pre-8.3 compatibility */
   11872             :             | CLUSTER opt_verbose name ON qualified_name
   11873             :                 {
   11874          18 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11875             : 
   11876          18 :                     n->relation = $5;
   11877          18 :                     n->indexname = $3;
   11878          18 :                     n->params = NIL;
   11879          18 :                     if ($2)
   11880           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11881          18 :                     $$ = (Node *) n;
   11882             :                 }
   11883             :         ;
   11884             : 
   11885             : cluster_index_specification:
   11886         156 :             USING name              { $$ = $2; }
   11887          34 :             | /*EMPTY*/             { $$ = NULL; }
   11888             :         ;
   11889             : 
   11890             : 
   11891             : /*****************************************************************************
   11892             :  *
   11893             :  *      QUERY:
   11894             :  *              VACUUM
   11895             :  *              ANALYZE
   11896             :  *
   11897             :  *****************************************************************************/
   11898             : 
   11899             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   11900             :                 {
   11901        1206 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11902             : 
   11903        1206 :                     n->options = NIL;
   11904        1206 :                     if ($2)
   11905         146 :                         n->options = lappend(n->options,
   11906         146 :                                              makeDefElem("full", NULL, @2));
   11907        1206 :                     if ($3)
   11908         158 :                         n->options = lappend(n->options,
   11909         158 :                                              makeDefElem("freeze", NULL, @3));
   11910        1206 :                     if ($4)
   11911          18 :                         n->options = lappend(n->options,
   11912          18 :                                              makeDefElem("verbose", NULL, @4));
   11913        1206 :                     if ($5)
   11914         286 :                         n->options = lappend(n->options,
   11915         286 :                                              makeDefElem("analyze", NULL, @5));
   11916        1206 :                     n->rels = $6;
   11917        1206 :                     n->is_vacuumcmd = true;
   11918        1206 :                     $$ = (Node *) n;
   11919             :                 }
   11920             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   11921             :                 {
   11922        7766 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11923             : 
   11924        7766 :                     n->options = $3;
   11925        7766 :                     n->rels = $5;
   11926        7766 :                     n->is_vacuumcmd = true;
   11927        7766 :                     $$ = (Node *) n;
   11928             :                 }
   11929             :         ;
   11930             : 
   11931             : AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
   11932             :                 {
   11933        4480 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11934             : 
   11935        4480 :                     n->options = NIL;
   11936        4480 :                     if ($2)
   11937           0 :                         n->options = lappend(n->options,
   11938           0 :                                              makeDefElem("verbose", NULL, @2));
   11939        4480 :                     n->rels = $3;
   11940        4480 :                     n->is_vacuumcmd = false;
   11941        4480 :                     $$ = (Node *) n;
   11942             :                 }
   11943             :             | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
   11944             :                 {
   11945         186 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11946             : 
   11947         186 :                     n->options = $3;
   11948         186 :                     n->rels = $5;
   11949         186 :                     n->is_vacuumcmd = false;
   11950         186 :                     $$ = (Node *) n;
   11951             :                 }
   11952             :         ;
   11953             : 
   11954             : utility_option_list:
   11955             :             utility_option_elem
   11956             :                 {
   11957       21586 :                     $$ = list_make1($1);
   11958             :                 }
   11959             :             | utility_option_list ',' utility_option_elem
   11960             :                 {
   11961       12264 :                     $$ = lappend($1, $3);
   11962             :                 }
   11963             :         ;
   11964             : 
   11965             : analyze_keyword:
   11966             :             ANALYZE
   11967             :             | ANALYSE /* British */
   11968             :         ;
   11969             : 
   11970             : utility_option_elem:
   11971             :             utility_option_name utility_option_arg
   11972             :                 {
   11973       33850 :                     $$ = makeDefElem($1, $2, @1);
   11974             :                 }
   11975             :         ;
   11976             : 
   11977             : utility_option_name:
   11978       30106 :             NonReservedWord                         { $$ = $1; }
   11979        3602 :             | analyze_keyword                       { $$ = "analyze"; }
   11980         148 :             | FORMAT_LA                             { $$ = "format"; }
   11981             :         ;
   11982             : 
   11983             : utility_option_arg:
   11984       16944 :             opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
   11985         380 :             | NumericOnly                           { $$ = (Node *) $1; }
   11986       16526 :             | /* EMPTY */                           { $$ = NULL; }
   11987             :         ;
   11988             : 
   11989             : opt_analyze:
   11990         286 :             analyze_keyword                         { $$ = true; }
   11991         920 :             | /*EMPTY*/                             { $$ = false; }
   11992             :         ;
   11993             : 
   11994             : opt_verbose:
   11995          30 :             VERBOSE                                 { $$ = true; }
   11996        8196 :             | /*EMPTY*/                             { $$ = false; }
   11997             :         ;
   11998             : 
   11999         146 : opt_full:   FULL                                    { $$ = true; }
   12000        1060 :             | /*EMPTY*/                             { $$ = false; }
   12001             :         ;
   12002             : 
   12003         158 : opt_freeze: FREEZE                                  { $$ = true; }
   12004        1048 :             | /*EMPTY*/                             { $$ = false; }
   12005             :         ;
   12006             : 
   12007             : opt_name_list:
   12008        2786 :             '(' name_list ')'                       { $$ = $2; }
   12009       15754 :             | /*EMPTY*/                             { $$ = NIL; }
   12010             :         ;
   12011             : 
   12012             : vacuum_relation:
   12013             :             relation_expr opt_name_list
   12014             :                 {
   12015       13432 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   12016             :                 }
   12017             :         ;
   12018             : 
   12019             : vacuum_relation_list:
   12020             :             vacuum_relation
   12021       13276 :                     { $$ = list_make1($1); }
   12022             :             | vacuum_relation_list ',' vacuum_relation
   12023         156 :                     { $$ = lappend($1, $3); }
   12024             :         ;
   12025             : 
   12026             : opt_vacuum_relation_list:
   12027       13276 :             vacuum_relation_list                    { $$ = $1; }
   12028         362 :             | /*EMPTY*/                             { $$ = NIL; }
   12029             :         ;
   12030             : 
   12031             : 
   12032             : /*****************************************************************************
   12033             :  *
   12034             :  *      QUERY:
   12035             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12036             :  *              EXPLAIN ( options ) query
   12037             :  *
   12038             :  *****************************************************************************/
   12039             : 
   12040             : ExplainStmt:
   12041             :         EXPLAIN ExplainableStmt
   12042             :                 {
   12043        7714 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12044             : 
   12045        7714 :                     n->query = $2;
   12046        7714 :                     n->options = NIL;
   12047        7714 :                     $$ = (Node *) n;
   12048             :                 }
   12049             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12050             :                 {
   12051        2304 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12052             : 
   12053        2304 :                     n->query = $4;
   12054        2304 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12055        2304 :                     if ($3)
   12056           0 :                         n->options = lappend(n->options,
   12057           0 :                                              makeDefElem("verbose", NULL, @3));
   12058        2304 :                     $$ = (Node *) n;
   12059             :                 }
   12060             :         | EXPLAIN VERBOSE ExplainableStmt
   12061             :                 {
   12062          12 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12063             : 
   12064          12 :                     n->query = $3;
   12065          12 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12066          12 :                     $$ = (Node *) n;
   12067             :                 }
   12068             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12069             :                 {
   12070       13478 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12071             : 
   12072       13478 :                     n->query = $5;
   12073       13478 :                     n->options = $3;
   12074       13478 :                     $$ = (Node *) n;
   12075             :                 }
   12076             :         ;
   12077             : 
   12078             : ExplainableStmt:
   12079             :             SelectStmt
   12080             :             | InsertStmt
   12081             :             | UpdateStmt
   12082             :             | DeleteStmt
   12083             :             | MergeStmt
   12084             :             | DeclareCursorStmt
   12085             :             | CreateAsStmt
   12086             :             | CreateMatViewStmt
   12087             :             | RefreshMatViewStmt
   12088             :             | ExecuteStmt                   /* by default all are $$=$1 */
   12089             :         ;
   12090             : 
   12091             : /*****************************************************************************
   12092             :  *
   12093             :  *      QUERY:
   12094             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12095             :  *
   12096             :  *****************************************************************************/
   12097             : 
   12098             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12099             :                 {
   12100        2038 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12101             : 
   12102        2038 :                     n->name = $2;
   12103        2038 :                     n->argtypes = $3;
   12104        2038 :                     n->query = $5;
   12105        2038 :                     $$ = (Node *) n;
   12106             :                 }
   12107             :         ;
   12108             : 
   12109        1730 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12110         326 :                 | /* EMPTY */               { $$ = NIL; }
   12111             :         ;
   12112             : 
   12113             : PreparableStmt:
   12114             :             SelectStmt
   12115             :             | InsertStmt
   12116             :             | UpdateStmt
   12117             :             | DeleteStmt
   12118             :             | MergeStmt                     /* by default all are $$=$1 */
   12119             :         ;
   12120             : 
   12121             : /*****************************************************************************
   12122             :  *
   12123             :  * EXECUTE <plan_name> [(params, ...)]
   12124             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12125             :  *
   12126             :  *****************************************************************************/
   12127             : 
   12128             : ExecuteStmt: EXECUTE name execute_param_clause
   12129             :                 {
   12130       27942 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12131             : 
   12132       27942 :                     n->name = $2;
   12133       27942 :                     n->params = $3;
   12134       27942 :                     $$ = (Node *) n;
   12135             :                 }
   12136             :             | CREATE OptTemp TABLE create_as_target AS
   12137             :                 EXECUTE name execute_param_clause opt_with_data
   12138             :                 {
   12139          76 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12140          76 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12141             : 
   12142          76 :                     n->name = $7;
   12143          76 :                     n->params = $8;
   12144          76 :                     ctas->query = (Node *) n;
   12145          76 :                     ctas->into = $4;
   12146          76 :                     ctas->objtype = OBJECT_TABLE;
   12147          76 :                     ctas->is_select_into = false;
   12148          76 :                     ctas->if_not_exists = false;
   12149             :                     /* cram additional flags into the IntoClause */
   12150          76 :                     $4->rel->relpersistence = $2;
   12151          76 :                     $4->skipData = !($9);
   12152          76 :                     $$ = (Node *) ctas;
   12153             :                 }
   12154             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12155             :                 EXECUTE name execute_param_clause opt_with_data
   12156             :                 {
   12157          12 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12158          12 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12159             : 
   12160          12 :                     n->name = $10;
   12161          12 :                     n->params = $11;
   12162          12 :                     ctas->query = (Node *) n;
   12163          12 :                     ctas->into = $7;
   12164          12 :                     ctas->objtype = OBJECT_TABLE;
   12165          12 :                     ctas->is_select_into = false;
   12166          12 :                     ctas->if_not_exists = true;
   12167             :                     /* cram additional flags into the IntoClause */
   12168          12 :                     $7->rel->relpersistence = $2;
   12169          12 :                     $7->skipData = !($12);
   12170          12 :                     $$ = (Node *) ctas;
   12171             :                 }
   12172             :         ;
   12173             : 
   12174       26888 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12175        1142 :                     | /* EMPTY */                   { $$ = NIL; }
   12176             :                     ;
   12177             : 
   12178             : /*****************************************************************************
   12179             :  *
   12180             :  *      QUERY:
   12181             :  *              DEALLOCATE [PREPARE] <plan_name>
   12182             :  *
   12183             :  *****************************************************************************/
   12184             : 
   12185             : DeallocateStmt: DEALLOCATE name
   12186             :                     {
   12187        3978 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12188             : 
   12189        3978 :                         n->name = $2;
   12190        3978 :                         n->isall = false;
   12191        3978 :                         n->location = @2;
   12192        3978 :                         $$ = (Node *) n;
   12193             :                     }
   12194             :                 | DEALLOCATE PREPARE name
   12195             :                     {
   12196          20 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12197             : 
   12198          20 :                         n->name = $3;
   12199          20 :                         n->isall = false;
   12200          20 :                         n->location = @3;
   12201          20 :                         $$ = (Node *) n;
   12202             :                     }
   12203             :                 | DEALLOCATE ALL
   12204             :                     {
   12205          54 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12206             : 
   12207          54 :                         n->name = NULL;
   12208          54 :                         n->isall = true;
   12209          54 :                         n->location = -1;
   12210          54 :                         $$ = (Node *) n;
   12211             :                     }
   12212             :                 | DEALLOCATE PREPARE ALL
   12213             :                     {
   12214           2 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12215             : 
   12216           2 :                         n->name = NULL;
   12217           2 :                         n->isall = true;
   12218           2 :                         n->location = -1;
   12219           2 :                         $$ = (Node *) n;
   12220             :                     }
   12221             :         ;
   12222             : 
   12223             : /*****************************************************************************
   12224             :  *
   12225             :  *      QUERY:
   12226             :  *              INSERT STATEMENTS
   12227             :  *
   12228             :  *****************************************************************************/
   12229             : 
   12230             : InsertStmt:
   12231             :             opt_with_clause INSERT INTO insert_target insert_rest
   12232             :             opt_on_conflict returning_clause
   12233             :                 {
   12234       73678 :                     $5->relation = $4;
   12235       73678 :                     $5->onConflictClause = $6;
   12236       73678 :                     $5->returningClause = $7;
   12237       73678 :                     $5->withClause = $1;
   12238       73678 :                     $5->stmt_location = @$;
   12239       73678 :                     $$ = (Node *) $5;
   12240             :                 }
   12241             :         ;
   12242             : 
   12243             : /*
   12244             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12245             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12246             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12247             :  * divergence from other places.  So just require AS for now.
   12248             :  */
   12249             : insert_target:
   12250             :             qualified_name
   12251             :                 {
   12252       73552 :                     $$ = $1;
   12253             :                 }
   12254             :             | qualified_name AS ColId
   12255             :                 {
   12256         132 :                     $1->alias = makeAlias($3, NIL);
   12257         132 :                     $$ = $1;
   12258             :                 }
   12259             :         ;
   12260             : 
   12261             : insert_rest:
   12262             :             SelectStmt
   12263             :                 {
   12264       48676 :                     $$ = makeNode(InsertStmt);
   12265       48676 :                     $$->cols = NIL;
   12266       48676 :                     $$->selectStmt = $1;
   12267             :                 }
   12268             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12269             :                 {
   12270          96 :                     $$ = makeNode(InsertStmt);
   12271          96 :                     $$->cols = NIL;
   12272          96 :                     $$->override = $2;
   12273          96 :                     $$->selectStmt = $4;
   12274             :                 }
   12275             :             | '(' insert_column_list ')' SelectStmt
   12276             :                 {
   12277       14098 :                     $$ = makeNode(InsertStmt);
   12278       14098 :                     $$->cols = $2;
   12279       14098 :                     $$->selectStmt = $4;
   12280             :                 }
   12281             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12282             :                 {
   12283           0 :                     $$ = makeNode(InsertStmt);
   12284           0 :                     $$->cols = $2;
   12285           0 :                     $$->override = $5;
   12286           0 :                     $$->selectStmt = $7;
   12287             :                 }
   12288             :             | DEFAULT VALUES
   12289             :                 {
   12290       10814 :                     $$ = makeNode(InsertStmt);
   12291       10814 :                     $$->cols = NIL;
   12292       10814 :                     $$->selectStmt = NULL;
   12293             :                 }
   12294             :         ;
   12295             : 
   12296             : override_kind:
   12297          66 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12298          60 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12299             :         ;
   12300             : 
   12301             : insert_column_list:
   12302             :             insert_column_item
   12303       14396 :                     { $$ = list_make1($1); }
   12304             :             | insert_column_list ',' insert_column_item
   12305       15628 :                     { $$ = lappend($1, $3); }
   12306             :         ;
   12307             : 
   12308             : insert_column_item:
   12309             :             ColId opt_indirection
   12310             :                 {
   12311       30024 :                     $$ = makeNode(ResTarget);
   12312       30024 :                     $$->name = $1;
   12313       30024 :                     $$->indirection = check_indirection($2, yyscanner);
   12314       30024 :                     $$->val = NULL;
   12315       30024 :                     $$->location = @1;
   12316             :                 }
   12317             :         ;
   12318             : 
   12319             : opt_on_conflict:
   12320             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12321             :                 {
   12322        1306 :                     $$ = makeNode(OnConflictClause);
   12323        1306 :                     $$->action = ONCONFLICT_UPDATE;
   12324        1306 :                     $$->infer = $3;
   12325        1306 :                     $$->targetList = $7;
   12326        1306 :                     $$->whereClause = $8;
   12327        1306 :                     $$->location = @1;
   12328             :                 }
   12329             :             |
   12330             :             ON CONFLICT opt_conf_expr DO NOTHING
   12331             :                 {
   12332         550 :                     $$ = makeNode(OnConflictClause);
   12333         550 :                     $$->action = ONCONFLICT_NOTHING;
   12334         550 :                     $$->infer = $3;
   12335         550 :                     $$->targetList = NIL;
   12336         550 :                     $$->whereClause = NULL;
   12337         550 :                     $$->location = @1;
   12338             :                 }
   12339             :             | /*EMPTY*/
   12340             :                 {
   12341       71828 :                     $$ = NULL;
   12342             :                 }
   12343             :         ;
   12344             : 
   12345             : opt_conf_expr:
   12346             :             '(' index_params ')' where_clause
   12347             :                 {
   12348        1430 :                     $$ = makeNode(InferClause);
   12349        1430 :                     $$->indexElems = $2;
   12350        1430 :                     $$->whereClause = $4;
   12351        1430 :                     $$->conname = NULL;
   12352        1430 :                     $$->location = @1;
   12353             :                 }
   12354             :             |
   12355             :             ON CONSTRAINT name
   12356             :                 {
   12357         192 :                     $$ = makeNode(InferClause);
   12358         192 :                     $$->indexElems = NIL;
   12359         192 :                     $$->whereClause = NULL;
   12360         192 :                     $$->conname = $3;
   12361         192 :                     $$->location = @1;
   12362             :                 }
   12363             :             | /*EMPTY*/
   12364             :                 {
   12365         234 :                     $$ = NULL;
   12366             :                 }
   12367             :         ;
   12368             : 
   12369             : returning_clause:
   12370             :             RETURNING returning_with_clause target_list
   12371             :                 {
   12372        3144 :                     ReturningClause *n = makeNode(ReturningClause);
   12373             : 
   12374        3144 :                     n->options = $2;
   12375        3144 :                     n->exprs = $3;
   12376        3144 :                     $$ = n;
   12377             :                 }
   12378             :             | /* EMPTY */
   12379             :                 {
   12380       91086 :                     $$ = NULL;
   12381             :                 }
   12382             :         ;
   12383             : 
   12384             : returning_with_clause:
   12385          72 :             WITH '(' returning_options ')'      { $$ = $3; }
   12386        3072 :             | /* EMPTY */                       { $$ = NIL; }
   12387             :         ;
   12388             : 
   12389             : returning_options:
   12390          72 :             returning_option                            { $$ = list_make1($1); }
   12391          54 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12392             :         ;
   12393             : 
   12394             : returning_option:
   12395             :             returning_option_kind AS ColId
   12396             :                 {
   12397         126 :                     ReturningOption *n = makeNode(ReturningOption);
   12398             : 
   12399         126 :                     n->option = $1;
   12400         126 :                     n->value = $3;
   12401         126 :                     n->location = @1;
   12402         126 :                     $$ = (Node *) n;
   12403             :                 }
   12404             :         ;
   12405             : 
   12406             : returning_option_kind:
   12407          54 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12408          72 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12409             :         ;
   12410             : 
   12411             : 
   12412             : /*****************************************************************************
   12413             :  *
   12414             :  *      QUERY:
   12415             :  *              DELETE STATEMENTS
   12416             :  *
   12417             :  *****************************************************************************/
   12418             : 
   12419             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12420             :             using_clause where_or_current_clause returning_clause
   12421             :                 {
   12422        4612 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12423             : 
   12424        4612 :                     n->relation = $4;
   12425        4612 :                     n->usingClause = $5;
   12426        4612 :                     n->whereClause = $6;
   12427        4612 :                     n->returningClause = $7;
   12428        4612 :                     n->withClause = $1;
   12429        4612 :                     n->stmt_location = @$;
   12430        4612 :                     $$ = (Node *) n;
   12431             :                 }
   12432             :         ;
   12433             : 
   12434             : using_clause:
   12435         108 :                 USING from_list                     { $$ = $2; }
   12436        4504 :             | /*EMPTY*/                             { $$ = NIL; }
   12437             :         ;
   12438             : 
   12439             : 
   12440             : /*****************************************************************************
   12441             :  *
   12442             :  *      QUERY:
   12443             :  *              LOCK TABLE
   12444             :  *
   12445             :  *****************************************************************************/
   12446             : 
   12447             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12448             :                 {
   12449        1138 :                     LockStmt   *n = makeNode(LockStmt);
   12450             : 
   12451        1138 :                     n->relations = $3;
   12452        1138 :                     n->mode = $4;
   12453        1138 :                     n->nowait = $5;
   12454        1138 :                     $$ = (Node *) n;
   12455             :                 }
   12456             :         ;
   12457             : 
   12458        1030 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12459         108 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12460             :         ;
   12461             : 
   12462         540 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12463          14 :             | ROW SHARE                     { $$ = RowShareLock; }
   12464          88 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12465          66 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12466          80 :             | SHARE                         { $$ = ShareLock; }
   12467          14 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12468         102 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12469         126 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12470             :         ;
   12471             : 
   12472         292 : opt_nowait: NOWAIT                          { $$ = true; }
   12473         876 :             | /*EMPTY*/                     { $$ = false; }
   12474             :         ;
   12475             : 
   12476             : opt_nowait_or_skip:
   12477          50 :             NOWAIT                          { $$ = LockWaitError; }
   12478         190 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12479        4906 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12480             :         ;
   12481             : 
   12482             : 
   12483             : /*****************************************************************************
   12484             :  *
   12485             :  *      QUERY:
   12486             :  *              UpdateStmt (UPDATE)
   12487             :  *
   12488             :  *****************************************************************************/
   12489             : 
   12490             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12491             :             SET set_clause_list
   12492             :             from_clause
   12493             :             where_or_current_clause
   12494             :             returning_clause
   12495             :                 {
   12496       13888 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12497             : 
   12498       13888 :                     n->relation = $3;
   12499       13888 :                     n->targetList = $5;
   12500       13888 :                     n->fromClause = $6;
   12501       13888 :                     n->whereClause = $7;
   12502       13888 :                     n->returningClause = $8;
   12503       13888 :                     n->withClause = $1;
   12504       13888 :                     n->stmt_location = @$;
   12505       13888 :                     $$ = (Node *) n;
   12506             :                 }
   12507             :         ;
   12508             : 
   12509             : set_clause_list:
   12510       16744 :             set_clause                          { $$ = $1; }
   12511        4066 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12512             :         ;
   12513             : 
   12514             : set_clause:
   12515             :             set_target '=' a_expr
   12516             :                 {
   12517       20626 :                     $1->val = (Node *) $3;
   12518       20626 :                     $$ = list_make1($1);
   12519             :                 }
   12520             :             | '(' set_target_list ')' '=' a_expr
   12521             :                 {
   12522         184 :                     int         ncolumns = list_length($2);
   12523         184 :                     int         i = 1;
   12524             :                     ListCell   *col_cell;
   12525             : 
   12526             :                     /* Create a MultiAssignRef source for each target */
   12527         568 :                     foreach(col_cell, $2)
   12528             :                     {
   12529         384 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12530         384 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12531             : 
   12532         384 :                         r->source = (Node *) $5;
   12533         384 :                         r->colno = i;
   12534         384 :                         r->ncolumns = ncolumns;
   12535         384 :                         res_col->val = (Node *) r;
   12536         384 :                         i++;
   12537             :                     }
   12538             : 
   12539         184 :                     $$ = $2;
   12540             :                 }
   12541             :         ;
   12542             : 
   12543             : set_target:
   12544             :             ColId opt_indirection
   12545             :                 {
   12546       21016 :                     $$ = makeNode(ResTarget);
   12547       21016 :                     $$->name = $1;
   12548       21016 :                     $$->indirection = check_indirection($2, yyscanner);
   12549       21016 :                     $$->val = NULL;  /* upper production sets this */
   12550       21016 :                     $$->location = @1;
   12551             :                 }
   12552             :         ;
   12553             : 
   12554             : set_target_list:
   12555         190 :             set_target                              { $$ = list_make1($1); }
   12556         200 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12557             :         ;
   12558             : 
   12559             : 
   12560             : /*****************************************************************************
   12561             :  *
   12562             :  *      QUERY:
   12563             :  *              MERGE
   12564             :  *
   12565             :  *****************************************************************************/
   12566             : 
   12567             : MergeStmt:
   12568             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12569             :             USING table_ref
   12570             :             ON a_expr
   12571             :             merge_when_list
   12572             :             returning_clause
   12573             :                 {
   12574        2052 :                     MergeStmt  *m = makeNode(MergeStmt);
   12575             : 
   12576        2052 :                     m->withClause = $1;
   12577        2052 :                     m->relation = $4;
   12578        2052 :                     m->sourceRelation = $6;
   12579        2052 :                     m->joinCondition = $8;
   12580        2052 :                     m->mergeWhenClauses = $9;
   12581        2052 :                     m->returningClause = $10;
   12582        2052 :                     m->stmt_location = @$;
   12583             : 
   12584        2052 :                     $$ = (Node *) m;
   12585             :                 }
   12586             :         ;
   12587             : 
   12588             : merge_when_list:
   12589        2052 :             merge_when_clause                       { $$ = list_make1($1); }
   12590        1164 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12591             :         ;
   12592             : 
   12593             : /*
   12594             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12595             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12596             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12597             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12598             :  */
   12599             : merge_when_clause:
   12600             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12601             :                 {
   12602        1550 :                     $4->matchKind = $1;
   12603        1550 :                     $4->condition = $2;
   12604             : 
   12605        1550 :                     $$ = (Node *) $4;
   12606             :                 }
   12607             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12608             :                 {
   12609         518 :                     $4->matchKind = $1;
   12610         518 :                     $4->condition = $2;
   12611             : 
   12612         518 :                     $$ = (Node *) $4;
   12613             :                 }
   12614             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12615             :                 {
   12616        1064 :                     $4->matchKind = $1;
   12617        1064 :                     $4->condition = $2;
   12618             : 
   12619        1064 :                     $$ = (Node *) $4;
   12620             :                 }
   12621             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12622             :                 {
   12623          64 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12624             : 
   12625          64 :                     m->matchKind = $1;
   12626          64 :                     m->commandType = CMD_NOTHING;
   12627          64 :                     m->condition = $2;
   12628             : 
   12629          64 :                     $$ = (Node *) m;
   12630             :                 }
   12631             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12632             :                 {
   12633          20 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12634             : 
   12635          20 :                     m->matchKind = $1;
   12636          20 :                     m->commandType = CMD_NOTHING;
   12637          20 :                     m->condition = $2;
   12638             : 
   12639          20 :                     $$ = (Node *) m;
   12640             :                 }
   12641             :         ;
   12642             : 
   12643             : merge_when_tgt_matched:
   12644        1970 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12645         180 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12646             :         ;
   12647             : 
   12648             : merge_when_tgt_not_matched:
   12649        1090 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12650          18 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12651             :         ;
   12652             : 
   12653             : opt_merge_when_condition:
   12654         808 :             AND a_expr              { $$ = $2; }
   12655        2450 :             |                       { $$ = NULL; }
   12656             :         ;
   12657             : 
   12658             : merge_update:
   12659             :             UPDATE SET set_clause_list
   12660             :                 {
   12661        1550 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12662        1550 :                     n->commandType = CMD_UPDATE;
   12663        1550 :                     n->override = OVERRIDING_NOT_SET;
   12664        1550 :                     n->targetList = $3;
   12665        1550 :                     n->values = NIL;
   12666             : 
   12667        1550 :                     $$ = n;
   12668             :                 }
   12669             :         ;
   12670             : 
   12671             : merge_delete:
   12672             :             DELETE_P
   12673             :                 {
   12674         518 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12675         518 :                     n->commandType = CMD_DELETE;
   12676         518 :                     n->override = OVERRIDING_NOT_SET;
   12677         518 :                     n->targetList = NIL;
   12678         518 :                     n->values = NIL;
   12679             : 
   12680         518 :                     $$ = n;
   12681             :                 }
   12682             :         ;
   12683             : 
   12684             : merge_insert:
   12685             :             INSERT merge_values_clause
   12686             :                 {
   12687         730 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12688         730 :                     n->commandType = CMD_INSERT;
   12689         730 :                     n->override = OVERRIDING_NOT_SET;
   12690         730 :                     n->targetList = NIL;
   12691         730 :                     n->values = $2;
   12692         730 :                     $$ = n;
   12693             :                 }
   12694             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12695             :                 {
   12696           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12697           0 :                     n->commandType = CMD_INSERT;
   12698           0 :                     n->override = $3;
   12699           0 :                     n->targetList = NIL;
   12700           0 :                     n->values = $5;
   12701           0 :                     $$ = n;
   12702             :                 }
   12703             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12704             :                 {
   12705         268 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12706         268 :                     n->commandType = CMD_INSERT;
   12707         268 :                     n->override = OVERRIDING_NOT_SET;
   12708         268 :                     n->targetList = $3;
   12709         268 :                     n->values = $5;
   12710         268 :                     $$ = n;
   12711             :                 }
   12712             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12713             :                 {
   12714          30 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12715          30 :                     n->commandType = CMD_INSERT;
   12716          30 :                     n->override = $6;
   12717          30 :                     n->targetList = $3;
   12718          30 :                     n->values = $8;
   12719          30 :                     $$ = n;
   12720             :                 }
   12721             :             | INSERT DEFAULT VALUES
   12722             :                 {
   12723          36 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12724          36 :                     n->commandType = CMD_INSERT;
   12725          36 :                     n->override = OVERRIDING_NOT_SET;
   12726          36 :                     n->targetList = NIL;
   12727          36 :                     n->values = NIL;
   12728          36 :                     $$ = n;
   12729             :                 }
   12730             :         ;
   12731             : 
   12732             : merge_values_clause:
   12733             :             VALUES '(' expr_list ')'
   12734             :                 {
   12735        1028 :                     $$ = $3;
   12736             :                 }
   12737             :         ;
   12738             : 
   12739             : /*****************************************************************************
   12740             :  *
   12741             :  *      QUERY:
   12742             :  *              CURSOR STATEMENTS
   12743             :  *
   12744             :  *****************************************************************************/
   12745             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12746             :                 {
   12747        4550 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12748             : 
   12749        4550 :                     n->portalname = $2;
   12750             :                     /* currently we always set FAST_PLAN option */
   12751        4550 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12752        4550 :                     n->query = $7;
   12753        4550 :                     $$ = (Node *) n;
   12754             :                 }
   12755             :         ;
   12756             : 
   12757       14510 : cursor_name:    name                        { $$ = $1; }
   12758             :         ;
   12759             : 
   12760        4550 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12761          24 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12762         240 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12763          14 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12764           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12765           6 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12766             :         ;
   12767             : 
   12768        4452 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12769          92 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12770           6 :             | WITHOUT HOLD                  { $$ = 0; }
   12771             :         ;
   12772             : 
   12773             : /*****************************************************************************
   12774             :  *
   12775             :  *      QUERY:
   12776             :  *              SELECT STATEMENTS
   12777             :  *
   12778             :  *****************************************************************************/
   12779             : 
   12780             : /* A complete SELECT statement looks like this.
   12781             :  *
   12782             :  * The rule returns either a single SelectStmt node or a tree of them,
   12783             :  * representing a set-operation tree.
   12784             :  *
   12785             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12786             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12787             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12788             :  * To resolve the ambiguity, we are careful to define the grammar so that
   12789             :  * the decision is staved off as long as possible: as long as we can keep
   12790             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12791             :  * it's no longer possible to do that will we decide that parens belong to
   12792             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12793             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12794             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12795             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12796             :  * SELECT viewpoint when we see the UNION.
   12797             :  *
   12798             :  * This approach is implemented by defining a nonterminal select_with_parens,
   12799             :  * which represents a SELECT with at least one outer layer of parentheses,
   12800             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12801             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12802             :  * which we can resolve in favor of always treating '(' <select> ')' as
   12803             :  * a select_with_parens.  To resolve the conflicts, the productions that
   12804             :  * conflict with the select_with_parens productions are manually given
   12805             :  * precedences lower than the precedence of ')', thereby ensuring that we
   12806             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12807             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12808             :  * precedence for this, which is a fairly arbitrary choice.
   12809             :  *
   12810             :  * To be able to define select_with_parens itself without ambiguity, we need
   12811             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12812             :  * outermost parentheses.  This is a little bit tedious, but it works.
   12813             :  *
   12814             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12815             :  * with or without outer parentheses.
   12816             :  */
   12817             : 
   12818             : SelectStmt: select_no_parens            %prec UMINUS
   12819             :             | select_with_parens        %prec UMINUS
   12820             :         ;
   12821             : 
   12822             : select_with_parens:
   12823             :             '(' select_no_parens ')'
   12824             :                 {
   12825       59980 :                     SelectStmt *n = (SelectStmt *) $2;
   12826             : 
   12827             :                     /*
   12828             :                      * As SelectStmt's location starts at the SELECT keyword,
   12829             :                      * we need to track the length of the SelectStmt within
   12830             :                      * parentheses to be able to extract the relevant part
   12831             :                      * of the query.  Without this, the RawStmt's length would
   12832             :                      * be used and would include the closing parenthesis.
   12833             :                      */
   12834       59980 :                     n->stmt_len = @3 - @2;
   12835       59980 :                     $$ = $2;
   12836             :                 }
   12837         150 :             | '(' select_with_parens ')'            { $$ = $2; }
   12838             :         ;
   12839             : 
   12840             : /*
   12841             :  * This rule parses the equivalent of the standard's <query expression>.
   12842             :  * The duplicative productions are annoying, but hard to get rid of without
   12843             :  * creating shift/reduce conflicts.
   12844             :  *
   12845             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12846             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12847             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12848             :  * clause.
   12849             :  *  2002-08-28 bjm
   12850             :  */
   12851             : select_no_parens:
   12852      427670 :             simple_select                       { $$ = $1; }
   12853             :             | select_clause sort_clause
   12854             :                 {
   12855       64116 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12856             :                                         NULL, NULL,
   12857             :                                         yyscanner);
   12858       64116 :                     $$ = $1;
   12859             :                 }
   12860             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12861             :                 {
   12862        4702 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12863        4702 :                                         $4,
   12864             :                                         NULL,
   12865             :                                         yyscanner);
   12866        4702 :                     $$ = $1;
   12867             :                 }
   12868             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12869             :                 {
   12870        4820 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12871        4820 :                                         $3,
   12872             :                                         NULL,
   12873             :                                         yyscanner);
   12874        4808 :                     $$ = $1;
   12875             :                 }
   12876             :             | with_clause select_clause
   12877             :                 {
   12878        2114 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12879             :                                         NULL,
   12880        2114 :                                         $1,
   12881             :                                         yyscanner);
   12882        2114 :                     $$ = $2;
   12883             :                 }
   12884             :             | with_clause select_clause sort_clause
   12885             :                 {
   12886         582 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12887             :                                         NULL,
   12888         582 :                                         $1,
   12889             :                                         yyscanner);
   12890         582 :                     $$ = $2;
   12891             :                 }
   12892             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12893             :                 {
   12894           6 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12895           6 :                                         $5,
   12896           6 :                                         $1,
   12897             :                                         yyscanner);
   12898           6 :                     $$ = $2;
   12899             :                 }
   12900             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12901             :                 {
   12902          64 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12903          64 :                                         $4,
   12904          64 :                                         $1,
   12905             :                                         yyscanner);
   12906          64 :                     $$ = $2;
   12907             :                 }
   12908             :         ;
   12909             : 
   12910             : select_clause:
   12911      107854 :             simple_select                           { $$ = $1; }
   12912         578 :             | select_with_parens                    { $$ = $1; }
   12913             :         ;
   12914             : 
   12915             : /*
   12916             :  * This rule parses SELECT statements that can appear within set operations,
   12917             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   12918             :  * the ordering of the set operations.  Without '(' and ')' we want the
   12919             :  * operations to be ordered per the precedence specs at the head of this file.
   12920             :  *
   12921             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   12922             :  * but can have parenthesized subclauses.
   12923             :  *
   12924             :  * It might appear that we could fold the first two alternatives into one
   12925             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   12926             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   12927             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   12928             :  *
   12929             :  * Note that sort clauses cannot be included at this level --- SQL requires
   12930             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   12931             :  * to be parsed as
   12932             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   12933             :  * not
   12934             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   12935             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   12936             :  * described as part of the select_no_parens production, not simple_select.
   12937             :  * This does not limit functionality, because you can reintroduce these
   12938             :  * clauses inside parentheses.
   12939             :  *
   12940             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   12941             :  * However, this is not checked by the grammar; parse analysis must check it.
   12942             :  */
   12943             : simple_select:
   12944             :             SELECT opt_all_clause opt_target_list
   12945             :             into_clause from_clause where_clause
   12946             :             group_clause having_clause window_clause
   12947             :                 {
   12948      454072 :                     SelectStmt *n = makeNode(SelectStmt);
   12949             : 
   12950      454072 :                     n->targetList = $3;
   12951      454072 :                     n->intoClause = $4;
   12952      454072 :                     n->fromClause = $5;
   12953      454072 :                     n->whereClause = $6;
   12954      454072 :                     n->groupClause = ($7)->list;
   12955      454072 :                     n->groupDistinct = ($7)->distinct;
   12956      454072 :                     n->havingClause = $8;
   12957      454072 :                     n->windowClause = $9;
   12958      454072 :                     n->stmt_location = @1;
   12959      454072 :                     $$ = (Node *) n;
   12960             :                 }
   12961             :             | SELECT distinct_clause target_list
   12962             :             into_clause from_clause where_clause
   12963             :             group_clause having_clause window_clause
   12964             :                 {
   12965        3490 :                     SelectStmt *n = makeNode(SelectStmt);
   12966             : 
   12967        3490 :                     n->distinctClause = $2;
   12968        3490 :                     n->targetList = $3;
   12969        3490 :                     n->intoClause = $4;
   12970        3490 :                     n->fromClause = $5;
   12971        3490 :                     n->whereClause = $6;
   12972        3490 :                     n->groupClause = ($7)->list;
   12973        3490 :                     n->groupDistinct = ($7)->distinct;
   12974        3490 :                     n->havingClause = $8;
   12975        3490 :                     n->windowClause = $9;
   12976        3490 :                     n->stmt_location = @1;
   12977        3490 :                     $$ = (Node *) n;
   12978             :                 }
   12979       61658 :             | values_clause                         { $$ = $1; }
   12980             :             | TABLE relation_expr
   12981             :                 {
   12982             :                     /* same as SELECT * FROM relation_expr */
   12983         296 :                     ColumnRef  *cr = makeNode(ColumnRef);
   12984         296 :                     ResTarget  *rt = makeNode(ResTarget);
   12985         296 :                     SelectStmt *n = makeNode(SelectStmt);
   12986             : 
   12987         296 :                     cr->fields = list_make1(makeNode(A_Star));
   12988         296 :                     cr->location = -1;
   12989             : 
   12990         296 :                     rt->name = NULL;
   12991         296 :                     rt->indirection = NIL;
   12992         296 :                     rt->val = (Node *) cr;
   12993         296 :                     rt->location = -1;
   12994             : 
   12995         296 :                     n->targetList = list_make1(rt);
   12996         296 :                     n->fromClause = list_make1($2);
   12997         296 :                     n->stmt_location = @1;
   12998         296 :                     $$ = (Node *) n;
   12999             :                 }
   13000             :             | select_clause UNION set_quantifier select_clause
   13001             :                 {
   13002       15274 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   13003             :                 }
   13004             :             | select_clause INTERSECT set_quantifier select_clause
   13005             :                 {
   13006         258 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   13007             :                 }
   13008             :             | select_clause EXCEPT set_quantifier select_clause
   13009             :                 {
   13010         476 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4, @1);
   13011             :                 }
   13012             :         ;
   13013             : 
   13014             : /*
   13015             :  * SQL standard WITH clause looks like:
   13016             :  *
   13017             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   13018             :  *      AS (query) [ SEARCH or CYCLE clause ]
   13019             :  *
   13020             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   13021             :  */
   13022             : with_clause:
   13023             :         WITH cte_list
   13024             :             {
   13025        1988 :                 $$ = makeNode(WithClause);
   13026        1988 :                 $$->ctes = $2;
   13027        1988 :                 $$->recursive = false;
   13028        1988 :                 $$->location = @1;
   13029             :             }
   13030             :         | WITH_LA cte_list
   13031             :             {
   13032           6 :                 $$ = makeNode(WithClause);
   13033           6 :                 $$->ctes = $2;
   13034           6 :                 $$->recursive = false;
   13035           6 :                 $$->location = @1;
   13036             :             }
   13037             :         | WITH RECURSIVE cte_list
   13038             :             {
   13039        1206 :                 $$ = makeNode(WithClause);
   13040        1206 :                 $$->ctes = $3;
   13041        1206 :                 $$->recursive = true;
   13042        1206 :                 $$->location = @1;
   13043             :             }
   13044             :         ;
   13045             : 
   13046             : cte_list:
   13047        3200 :         common_table_expr                       { $$ = list_make1($1); }
   13048        1214 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13049             :         ;
   13050             : 
   13051             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13052             :             {
   13053        4414 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13054             : 
   13055        4414 :                 n->ctename = $1;
   13056        4414 :                 n->aliascolnames = $2;
   13057        4414 :                 n->ctematerialized = $4;
   13058        4414 :                 n->ctequery = $6;
   13059        4414 :                 n->search_clause = castNode(CTESearchClause, $8);
   13060        4414 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13061        4414 :                 n->location = @1;
   13062        4414 :                 $$ = (Node *) n;
   13063             :             }
   13064             :         ;
   13065             : 
   13066             : opt_materialized:
   13067         178 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13068          48 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13069        4188 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13070             :         ;
   13071             : 
   13072             : opt_search_clause:
   13073             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13074             :             {
   13075          90 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13076             : 
   13077          90 :                 n->search_col_list = $5;
   13078          90 :                 n->search_breadth_first = false;
   13079          90 :                 n->search_seq_column = $7;
   13080          90 :                 n->location = @1;
   13081          90 :                 $$ = (Node *) n;
   13082             :             }
   13083             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13084             :             {
   13085          36 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13086             : 
   13087          36 :                 n->search_col_list = $5;
   13088          36 :                 n->search_breadth_first = true;
   13089          36 :                 n->search_seq_column = $7;
   13090          36 :                 n->location = @1;
   13091          36 :                 $$ = (Node *) n;
   13092             :             }
   13093             :         | /*EMPTY*/
   13094             :             {
   13095        4288 :                 $$ = NULL;
   13096             :             }
   13097             :         ;
   13098             : 
   13099             : opt_cycle_clause:
   13100             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13101             :             {
   13102          66 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13103             : 
   13104          66 :                 n->cycle_col_list = $2;
   13105          66 :                 n->cycle_mark_column = $4;
   13106          66 :                 n->cycle_mark_value = $6;
   13107          66 :                 n->cycle_mark_default = $8;
   13108          66 :                 n->cycle_path_column = $10;
   13109          66 :                 n->location = @1;
   13110          66 :                 $$ = (Node *) n;
   13111             :             }
   13112             :         | CYCLE columnList SET ColId USING ColId
   13113             :             {
   13114          60 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13115             : 
   13116          60 :                 n->cycle_col_list = $2;
   13117          60 :                 n->cycle_mark_column = $4;
   13118          60 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13119          60 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13120          60 :                 n->cycle_path_column = $6;
   13121          60 :                 n->location = @1;
   13122          60 :                 $$ = (Node *) n;
   13123             :             }
   13124             :         | /*EMPTY*/
   13125             :             {
   13126        4288 :                 $$ = NULL;
   13127             :             }
   13128             :         ;
   13129             : 
   13130             : opt_with_clause:
   13131         434 :         with_clause                             { $$ = $1; }
   13132       93912 :         | /*EMPTY*/                             { $$ = NULL; }
   13133             :         ;
   13134             : 
   13135             : into_clause:
   13136             :             INTO OptTempTableName
   13137             :                 {
   13138         132 :                     $$ = makeNode(IntoClause);
   13139         132 :                     $$->rel = $2;
   13140         132 :                     $$->colNames = NIL;
   13141         132 :                     $$->options = NIL;
   13142         132 :                     $$->onCommit = ONCOMMIT_NOOP;
   13143         132 :                     $$->tableSpaceName = NULL;
   13144         132 :                     $$->viewQuery = NULL;
   13145         132 :                     $$->skipData = false;
   13146             :                 }
   13147             :             | /*EMPTY*/
   13148      457454 :                 { $$ = NULL; }
   13149             :         ;
   13150             : 
   13151             : /*
   13152             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13153             :  * since TEMP is not a reserved word.  See also OptTemp.
   13154             :  */
   13155             : OptTempTableName:
   13156             :             TEMPORARY opt_table qualified_name
   13157             :                 {
   13158           0 :                     $$ = $3;
   13159           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13160             :                 }
   13161             :             | TEMP opt_table qualified_name
   13162             :                 {
   13163           6 :                     $$ = $3;
   13164           6 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13165             :                 }
   13166             :             | LOCAL TEMPORARY opt_table qualified_name
   13167             :                 {
   13168           0 :                     $$ = $4;
   13169           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13170             :                 }
   13171             :             | LOCAL TEMP opt_table qualified_name
   13172             :                 {
   13173           0 :                     $$ = $4;
   13174           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13175             :                 }
   13176             :             | GLOBAL TEMPORARY opt_table qualified_name
   13177             :                 {
   13178           0 :                     ereport(WARNING,
   13179             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13180             :                              parser_errposition(@1)));
   13181           0 :                     $$ = $4;
   13182           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13183             :                 }
   13184             :             | GLOBAL TEMP opt_table qualified_name
   13185             :                 {
   13186           0 :                     ereport(WARNING,
   13187             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13188             :                              parser_errposition(@1)));
   13189           0 :                     $$ = $4;
   13190           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13191             :                 }
   13192             :             | UNLOGGED opt_table qualified_name
   13193             :                 {
   13194           0 :                     $$ = $3;
   13195           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13196             :                 }
   13197             :             | TABLE qualified_name
   13198             :                 {
   13199          30 :                     $$ = $2;
   13200          30 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13201             :                 }
   13202             :             | qualified_name
   13203             :                 {
   13204          96 :                     $$ = $1;
   13205          96 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13206             :                 }
   13207             :         ;
   13208             : 
   13209             : opt_table:  TABLE
   13210             :             | /*EMPTY*/
   13211             :         ;
   13212             : 
   13213             : set_quantifier:
   13214        7604 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13215          32 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13216       12988 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13217             :         ;
   13218             : 
   13219             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13220             :  * should be placed in the DISTINCT list during parsetree analysis.
   13221             :  */
   13222             : distinct_clause:
   13223        3246 :             DISTINCT                                { $$ = list_make1(NIL); }
   13224         250 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13225             :         ;
   13226             : 
   13227             : opt_all_clause:
   13228             :             ALL
   13229             :             | /*EMPTY*/
   13230             :         ;
   13231             : 
   13232             : opt_distinct_clause:
   13233           0 :             distinct_clause                         { $$ = $1; }
   13234       40284 :             | opt_all_clause                        { $$ = NIL; }
   13235             :         ;
   13236             : 
   13237             : opt_sort_clause:
   13238        7220 :             sort_clause                             { $$ = $1; }
   13239      358638 :             | /*EMPTY*/                             { $$ = NIL; }
   13240             :         ;
   13241             : 
   13242             : sort_clause:
   13243       72266 :             ORDER BY sortby_list                    { $$ = $3; }
   13244             :         ;
   13245             : 
   13246             : sortby_list:
   13247       72284 :             sortby                                  { $$ = list_make1($1); }
   13248       27660 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13249             :         ;
   13250             : 
   13251             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13252             :                 {
   13253         220 :                     $$ = makeNode(SortBy);
   13254         220 :                     $$->node = $1;
   13255         220 :                     $$->sortby_dir = SORTBY_USING;
   13256         220 :                     $$->sortby_nulls = $4;
   13257         220 :                     $$->useOp = $3;
   13258         220 :                     $$->location = @3;
   13259             :                 }
   13260             :             | a_expr opt_asc_desc opt_nulls_order
   13261             :                 {
   13262       99724 :                     $$ = makeNode(SortBy);
   13263       99724 :                     $$->node = $1;
   13264       99724 :                     $$->sortby_dir = $2;
   13265       99724 :                     $$->sortby_nulls = $3;
   13266       99724 :                     $$->useOp = NIL;
   13267       99724 :                     $$->location = -1;       /* no operator */
   13268             :                 }
   13269             :         ;
   13270             : 
   13271             : 
   13272             : select_limit:
   13273             :             limit_clause offset_clause
   13274             :                 {
   13275         172 :                     $$ = $1;
   13276         172 :                     ($$)->limitOffset = $2;
   13277         172 :                     ($$)->offsetLoc = @2;
   13278             :                 }
   13279             :             | offset_clause limit_clause
   13280             :                 {
   13281         222 :                     $$ = $2;
   13282         222 :                     ($$)->limitOffset = $1;
   13283         222 :                     ($$)->offsetLoc = @1;
   13284             :                 }
   13285             :             | limit_clause
   13286             :                 {
   13287        4248 :                     $$ = $1;
   13288             :                 }
   13289             :             | offset_clause
   13290             :                 {
   13291         432 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13292             : 
   13293         432 :                     n->limitOffset = $1;
   13294         432 :                     n->limitCount = NULL;
   13295         432 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13296         432 :                     n->offsetLoc = @1;
   13297         432 :                     n->countLoc = -1;
   13298         432 :                     n->optionLoc = -1;
   13299         432 :                     $$ = n;
   13300             :                 }
   13301             :         ;
   13302             : 
   13303             : opt_select_limit:
   13304         190 :             select_limit                        { $$ = $1; }
   13305       44802 :             | /* EMPTY */                       { $$ = NULL; }
   13306             :         ;
   13307             : 
   13308             : limit_clause:
   13309             :             LIMIT select_limit_value
   13310             :                 {
   13311        4554 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13312             : 
   13313        4554 :                     n->limitOffset = NULL;
   13314        4554 :                     n->limitCount = $2;
   13315        4554 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13316        4554 :                     n->offsetLoc = -1;
   13317        4554 :                     n->countLoc = @1;
   13318        4554 :                     n->optionLoc = -1;
   13319        4554 :                     $$ = n;
   13320             :                 }
   13321             :             | LIMIT select_limit_value ',' select_offset_value
   13322             :                 {
   13323             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13324           0 :                     ereport(ERROR,
   13325             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13326             :                              errmsg("LIMIT #,# syntax is not supported"),
   13327             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13328             :                              parser_errposition(@1)));
   13329             :                 }
   13330             :             /* SQL:2008 syntax */
   13331             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13332             :              * a separate production rather than an opt_ expression.  The fact
   13333             :              * that ONLY is fully reserved means that this way, we defer any
   13334             :              * decision about what rule reduces ROW or ROWS to the point where
   13335             :              * we can see the ONLY token in the lookahead slot.
   13336             :              */
   13337             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13338             :                 {
   13339          24 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13340             : 
   13341          24 :                     n->limitOffset = NULL;
   13342          24 :                     n->limitCount = $3;
   13343          24 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13344          24 :                     n->offsetLoc = -1;
   13345          24 :                     n->countLoc = @1;
   13346          24 :                     n->optionLoc = -1;
   13347          24 :                     $$ = n;
   13348             :                 }
   13349             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13350             :                 {
   13351          58 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13352             : 
   13353          58 :                     n->limitOffset = NULL;
   13354          58 :                     n->limitCount = $3;
   13355          58 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13356          58 :                     n->offsetLoc = -1;
   13357          58 :                     n->countLoc = @1;
   13358          58 :                     n->optionLoc = @5;
   13359          58 :                     $$ = n;
   13360             :                 }
   13361             :             | FETCH first_or_next row_or_rows ONLY
   13362             :                 {
   13363           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13364             : 
   13365           0 :                     n->limitOffset = NULL;
   13366           0 :                     n->limitCount = makeIntConst(1, -1);
   13367           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13368           0 :                     n->offsetLoc = -1;
   13369           0 :                     n->countLoc = @1;
   13370           0 :                     n->optionLoc = -1;
   13371           0 :                     $$ = n;
   13372             :                 }
   13373             :             | FETCH first_or_next row_or_rows WITH TIES
   13374             :                 {
   13375           6 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13376             : 
   13377           6 :                     n->limitOffset = NULL;
   13378           6 :                     n->limitCount = makeIntConst(1, -1);
   13379           6 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13380           6 :                     n->offsetLoc = -1;
   13381           6 :                     n->countLoc = @1;
   13382           6 :                     n->optionLoc = @4;
   13383           6 :                     $$ = n;
   13384             :                 }
   13385             :         ;
   13386             : 
   13387             : offset_clause:
   13388             :             OFFSET select_offset_value
   13389         826 :                 { $$ = $2; }
   13390             :             /* SQL:2008 syntax */
   13391             :             | OFFSET select_fetch_first_value row_or_rows
   13392           0 :                 { $$ = $2; }
   13393             :         ;
   13394             : 
   13395             : select_limit_value:
   13396        4552 :             a_expr                                  { $$ = $1; }
   13397             :             | ALL
   13398             :                 {
   13399             :                     /* LIMIT ALL is represented as a NULL constant */
   13400           2 :                     $$ = makeNullAConst(@1);
   13401             :                 }
   13402             :         ;
   13403             : 
   13404             : select_offset_value:
   13405         826 :             a_expr                                  { $$ = $1; }
   13406             :         ;
   13407             : 
   13408             : /*
   13409             :  * Allowing full expressions without parentheses causes various parsing
   13410             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13411             :  * <simple value specification>, which is either a literal or a parameter (but
   13412             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13413             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13414             :  * to determine whether the expression is missing rather than trying to make it
   13415             :  * optional in this rule.
   13416             :  *
   13417             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13418             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13419             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13420             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13421             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13422             :  * builds.)
   13423             :  */
   13424             : select_fetch_first_value:
   13425          82 :             c_expr                                  { $$ = $1; }
   13426             :             | '+' I_or_F_const
   13427           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13428             :             | '-' I_or_F_const
   13429           0 :                 { $$ = doNegate($2, @1); }
   13430             :         ;
   13431             : 
   13432             : I_or_F_const:
   13433           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13434           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13435             :         ;
   13436             : 
   13437             : /* noise words */
   13438          36 : row_or_rows: ROW                                    { $$ = 0; }
   13439          52 :             | ROWS                                  { $$ = 0; }
   13440             :         ;
   13441             : 
   13442          88 : first_or_next: FIRST_P                              { $$ = 0; }
   13443           0 :             | NEXT                                  { $$ = 0; }
   13444             :         ;
   13445             : 
   13446             : 
   13447             : /*
   13448             :  * This syntax for group_clause tries to follow the spec quite closely.
   13449             :  * However, the spec allows only column references, not expressions,
   13450             :  * which introduces an ambiguity between implicit row constructors
   13451             :  * (a,b) and lists of column references.
   13452             :  *
   13453             :  * We handle this by using the a_expr production for what the spec calls
   13454             :  * <ordinary grouping set>, which in the spec represents either one column
   13455             :  * reference or a parenthesized list of column references. Then, we check the
   13456             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13457             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13458             :  * not here)
   13459             :  *
   13460             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13461             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13462             :  * in a group clause, but if they have a reason to, we make it possible.)
   13463             :  *
   13464             :  * Each item in the group_clause list is either an expression tree or a
   13465             :  * GroupingSet node of some type.
   13466             :  */
   13467             : group_clause:
   13468             :             GROUP_P BY set_quantifier group_by_list
   13469             :                 {
   13470        4604 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13471             : 
   13472        4604 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13473        4604 :                     n->list = $4;
   13474        4604 :                     $$ = n;
   13475             :                 }
   13476             :             | /*EMPTY*/
   13477             :                 {
   13478      493242 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13479             : 
   13480      493242 :                     n->distinct = false;
   13481      493242 :                     n->list = NIL;
   13482      493242 :                     $$ = n;
   13483             :                 }
   13484             :         ;
   13485             : 
   13486             : group_by_list:
   13487        5202 :             group_by_item                           { $$ = list_make1($1); }
   13488        2974 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13489             :         ;
   13490             : 
   13491             : group_by_item:
   13492        6886 :             a_expr                                  { $$ = $1; }
   13493         222 :             | empty_grouping_set                    { $$ = $1; }
   13494         184 :             | cube_clause                           { $$ = $1; }
   13495         286 :             | rollup_clause                         { $$ = $1; }
   13496         598 :             | grouping_sets_clause                  { $$ = $1; }
   13497             :         ;
   13498             : 
   13499             : empty_grouping_set:
   13500             :             '(' ')'
   13501             :                 {
   13502         222 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13503             :                 }
   13504             :         ;
   13505             : 
   13506             : /*
   13507             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13508             :  * so that they shift in these rules rather than reducing the conflicting
   13509             :  * unreserved_keyword rule.
   13510             :  */
   13511             : 
   13512             : rollup_clause:
   13513             :             ROLLUP '(' expr_list ')'
   13514             :                 {
   13515         286 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13516             :                 }
   13517             :         ;
   13518             : 
   13519             : cube_clause:
   13520             :             CUBE '(' expr_list ')'
   13521             :                 {
   13522         184 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13523             :                 }
   13524             :         ;
   13525             : 
   13526             : grouping_sets_clause:
   13527             :             GROUPING SETS '(' group_by_list ')'
   13528             :                 {
   13529         598 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13530             :                 }
   13531             :         ;
   13532             : 
   13533             : having_clause:
   13534         680 :             HAVING a_expr                           { $$ = $2; }
   13535      497166 :             | /*EMPTY*/                             { $$ = NULL; }
   13536             :         ;
   13537             : 
   13538             : for_locking_clause:
   13539        5048 :             for_locking_items                       { $$ = $1; }
   13540           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13541             :         ;
   13542             : 
   13543             : opt_for_locking_clause:
   13544         340 :             for_locking_clause                      { $$ = $1; }
   13545       44828 :             | /* EMPTY */                           { $$ = NIL; }
   13546             :         ;
   13547             : 
   13548             : for_locking_items:
   13549        5048 :             for_locking_item                        { $$ = list_make1($1); }
   13550          98 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13551             :         ;
   13552             : 
   13553             : for_locking_item:
   13554             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13555             :                 {
   13556        5146 :                     LockingClause *n = makeNode(LockingClause);
   13557             : 
   13558        5146 :                     n->lockedRels = $2;
   13559        5146 :                     n->strength = $1;
   13560        5146 :                     n->waitPolicy = $3;
   13561        5146 :                     $$ = (Node *) n;
   13562             :                 }
   13563             :         ;
   13564             : 
   13565             : for_locking_strength:
   13566        1516 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13567          76 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13568         214 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13569        3340 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13570             :         ;
   13571             : 
   13572             : locked_rels_list:
   13573        3360 :             OF qualified_name_list                  { $$ = $2; }
   13574        1786 :             | /* EMPTY */                           { $$ = NIL; }
   13575             :         ;
   13576             : 
   13577             : 
   13578             : /*
   13579             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13580             :  * making VALUES a fully reserved word, which will probably break more apps
   13581             :  * than allowing the noise-word is worth.
   13582             :  */
   13583             : values_clause:
   13584             :             VALUES '(' expr_list ')'
   13585             :                 {
   13586       61658 :                     SelectStmt *n = makeNode(SelectStmt);
   13587             : 
   13588       61658 :                     n->stmt_location = @1;
   13589       61658 :                     n->valuesLists = list_make1($3);
   13590       61658 :                     $$ = (Node *) n;
   13591             :                 }
   13592             :             | values_clause ',' '(' expr_list ')'
   13593             :                 {
   13594       25118 :                     SelectStmt *n = (SelectStmt *) $1;
   13595             : 
   13596       25118 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13597       25118 :                     $$ = (Node *) n;
   13598             :                 }
   13599             :         ;
   13600             : 
   13601             : 
   13602             : /*****************************************************************************
   13603             :  *
   13604             :  *  clauses common to all Optimizable Stmts:
   13605             :  *      from_clause     - allow list of both JOIN expressions and table names
   13606             :  *      where_clause    - qualifications for joins or restrictions
   13607             :  *
   13608             :  *****************************************************************************/
   13609             : 
   13610             : from_clause:
   13611      304330 :             FROM from_list                          { $$ = $2; }
   13612      207404 :             | /*EMPTY*/                             { $$ = NIL; }
   13613             :         ;
   13614             : 
   13615             : from_list:
   13616      305102 :             table_ref                               { $$ = list_make1($1); }
   13617       58592 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13618             :         ;
   13619             : 
   13620             : /*
   13621             :  * table_ref is where an alias clause can be attached.
   13622             :  */
   13623             : table_ref:  relation_expr opt_alias_clause
   13624             :                 {
   13625      381760 :                     $1->alias = $2;
   13626      381760 :                     $$ = (Node *) $1;
   13627             :                 }
   13628             :             | relation_expr opt_alias_clause tablesample_clause
   13629             :                 {
   13630         260 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13631             : 
   13632         260 :                     $1->alias = $2;
   13633             :                     /* relation_expr goes inside the RangeTableSample node */
   13634         260 :                     n->relation = (Node *) $1;
   13635         260 :                     $$ = (Node *) n;
   13636             :                 }
   13637             :             | func_table func_alias_clause
   13638             :                 {
   13639       46510 :                     RangeFunction *n = (RangeFunction *) $1;
   13640             : 
   13641       46510 :                     n->alias = linitial($2);
   13642       46510 :                     n->coldeflist = lsecond($2);
   13643       46510 :                     $$ = (Node *) n;
   13644             :                 }
   13645             :             | LATERAL_P func_table func_alias_clause
   13646             :                 {
   13647        1124 :                     RangeFunction *n = (RangeFunction *) $2;
   13648             : 
   13649        1124 :                     n->lateral = true;
   13650        1124 :                     n->alias = linitial($3);
   13651        1124 :                     n->coldeflist = lsecond($3);
   13652        1124 :                     $$ = (Node *) n;
   13653             :                 }
   13654             :             | xmltable opt_alias_clause
   13655             :                 {
   13656          80 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13657             : 
   13658          80 :                     n->alias = $2;
   13659          80 :                     $$ = (Node *) n;
   13660             :                 }
   13661             :             | LATERAL_P xmltable opt_alias_clause
   13662             :                 {
   13663         140 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13664             : 
   13665         140 :                     n->lateral = true;
   13666         140 :                     n->alias = $3;
   13667         140 :                     $$ = (Node *) n;
   13668             :                 }
   13669             :             | select_with_parens opt_alias_clause
   13670             :                 {
   13671       13556 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13672             : 
   13673       13556 :                     n->lateral = false;
   13674       13556 :                     n->subquery = $1;
   13675       13556 :                     n->alias = $2;
   13676       13556 :                     $$ = (Node *) n;
   13677             :                 }
   13678             :             | LATERAL_P select_with_parens opt_alias_clause
   13679             :                 {
   13680        1792 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13681             : 
   13682        1792 :                     n->lateral = true;
   13683        1792 :                     n->subquery = $2;
   13684        1792 :                     n->alias = $3;
   13685        1792 :                     $$ = (Node *) n;
   13686             :                 }
   13687             :             | joined_table
   13688             :                 {
   13689       79784 :                     $$ = (Node *) $1;
   13690             :                 }
   13691             :             | '(' joined_table ')' alias_clause
   13692             :                 {
   13693         174 :                     $2->alias = $4;
   13694         174 :                     $$ = (Node *) $2;
   13695             :                 }
   13696             :             | json_table opt_alias_clause
   13697             :                 {
   13698         524 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13699             : 
   13700         524 :                     jt->alias = $2;
   13701         524 :                     $$ = (Node *) jt;
   13702             :                 }
   13703             :             | LATERAL_P json_table opt_alias_clause
   13704             :                 {
   13705           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13706             : 
   13707           0 :                     jt->alias = $3;
   13708           0 :                     jt->lateral = true;
   13709           0 :                     $$ = (Node *) jt;
   13710             :                 }
   13711             :         ;
   13712             : 
   13713             : 
   13714             : /*
   13715             :  * It may seem silly to separate joined_table from table_ref, but there is
   13716             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13717             :  * reduce conflicts, because it's not clear to the parser generator whether
   13718             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13719             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13720             :  * join_type to expand to empty; if we try it, the parser generator can't
   13721             :  * figure out when to reduce an empty join_type right after table_ref.
   13722             :  *
   13723             :  * Note that a CROSS JOIN is the same as an unqualified
   13724             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13725             :  * but a qualification expression to limit membership.
   13726             :  * A NATURAL JOIN implicitly matches column names between
   13727             :  * tables and the shape is determined by which columns are
   13728             :  * in common. We'll collect columns during the later transformations.
   13729             :  */
   13730             : 
   13731             : joined_table:
   13732             :             '(' joined_table ')'
   13733             :                 {
   13734        3738 :                     $$ = $2;
   13735             :                 }
   13736             :             | table_ref CROSS JOIN table_ref
   13737             :                 {
   13738             :                     /* CROSS JOIN is same as unqualified inner join */
   13739         506 :                     JoinExpr   *n = makeNode(JoinExpr);
   13740             : 
   13741         506 :                     n->jointype = JOIN_INNER;
   13742         506 :                     n->isNatural = false;
   13743         506 :                     n->larg = $1;
   13744         506 :                     n->rarg = $4;
   13745         506 :                     n->usingClause = NIL;
   13746         506 :                     n->join_using_alias = NULL;
   13747         506 :                     n->quals = NULL;
   13748         506 :                     $$ = n;
   13749             :                 }
   13750             :             | table_ref join_type JOIN table_ref join_qual
   13751             :                 {
   13752       45418 :                     JoinExpr   *n = makeNode(JoinExpr);
   13753             : 
   13754       45418 :                     n->jointype = $2;
   13755       45418 :                     n->isNatural = false;
   13756       45418 :                     n->larg = $1;
   13757       45418 :                     n->rarg = $4;
   13758       45418 :                     if ($5 != NULL && IsA($5, List))
   13759             :                     {
   13760             :                          /* USING clause */
   13761         492 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13762         492 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13763             :                     }
   13764             :                     else
   13765             :                     {
   13766             :                         /* ON clause */
   13767       44926 :                         n->quals = $5;
   13768             :                     }
   13769       45418 :                     $$ = n;
   13770             :                 }
   13771             :             | table_ref JOIN table_ref join_qual
   13772             :                 {
   13773             :                     /* letting join_type reduce to empty doesn't work */
   13774       33776 :                     JoinExpr   *n = makeNode(JoinExpr);
   13775             : 
   13776       33776 :                     n->jointype = JOIN_INNER;
   13777       33776 :                     n->isNatural = false;
   13778       33776 :                     n->larg = $1;
   13779       33776 :                     n->rarg = $3;
   13780       33776 :                     if ($4 != NULL && IsA($4, List))
   13781             :                     {
   13782             :                         /* USING clause */
   13783         732 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13784         732 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13785             :                     }
   13786             :                     else
   13787             :                     {
   13788             :                         /* ON clause */
   13789       33044 :                         n->quals = $4;
   13790             :                     }
   13791       33776 :                     $$ = n;
   13792             :                 }
   13793             :             | table_ref NATURAL join_type JOIN table_ref
   13794             :                 {
   13795          78 :                     JoinExpr   *n = makeNode(JoinExpr);
   13796             : 
   13797          78 :                     n->jointype = $3;
   13798          78 :                     n->isNatural = true;
   13799          78 :                     n->larg = $1;
   13800          78 :                     n->rarg = $5;
   13801          78 :                     n->usingClause = NIL; /* figure out which columns later... */
   13802          78 :                     n->join_using_alias = NULL;
   13803          78 :                     n->quals = NULL; /* fill later */
   13804          78 :                     $$ = n;
   13805             :                 }
   13806             :             | table_ref NATURAL JOIN table_ref
   13807             :                 {
   13808             :                     /* letting join_type reduce to empty doesn't work */
   13809         180 :                     JoinExpr   *n = makeNode(JoinExpr);
   13810             : 
   13811         180 :                     n->jointype = JOIN_INNER;
   13812         180 :                     n->isNatural = true;
   13813         180 :                     n->larg = $1;
   13814         180 :                     n->rarg = $4;
   13815         180 :                     n->usingClause = NIL; /* figure out which columns later... */
   13816         180 :                     n->join_using_alias = NULL;
   13817         180 :                     n->quals = NULL; /* fill later */
   13818         180 :                     $$ = n;
   13819             :                 }
   13820             :         ;
   13821             : 
   13822             : alias_clause:
   13823             :             AS ColId '(' name_list ')'
   13824             :                 {
   13825        6230 :                     $$ = makeNode(Alias);
   13826        6230 :                     $$->aliasname = $2;
   13827        6230 :                     $$->colnames = $4;
   13828             :                 }
   13829             :             | AS ColId
   13830             :                 {
   13831       10410 :                     $$ = makeNode(Alias);
   13832       10410 :                     $$->aliasname = $2;
   13833             :                 }
   13834             :             | ColId '(' name_list ')'
   13835             :                 {
   13836        5724 :                     $$ = makeNode(Alias);
   13837        5724 :                     $$->aliasname = $1;
   13838        5724 :                     $$->colnames = $3;
   13839             :                 }
   13840             :             | ColId
   13841             :                 {
   13842      251784 :                     $$ = makeNode(Alias);
   13843      251784 :                     $$->aliasname = $1;
   13844             :                 }
   13845             :         ;
   13846             : 
   13847      244262 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13848      153850 :             | /*EMPTY*/                             { $$ = NULL; }
   13849             :         ;
   13850             : 
   13851             : /*
   13852             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13853             :  * per SQL standard.  (The grammar could parse the other variants, but they
   13854             :  * don't seem to be useful, and it might lead to parser problems in the
   13855             :  * future.)
   13856             :  */
   13857             : opt_alias_clause_for_join_using:
   13858             :             AS ColId
   13859             :                 {
   13860          84 :                     $$ = makeNode(Alias);
   13861          84 :                     $$->aliasname = $2;
   13862             :                     /* the column name list will be inserted later */
   13863             :                 }
   13864        1140 :             | /*EMPTY*/                             { $$ = NULL; }
   13865             :         ;
   13866             : 
   13867             : /*
   13868             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13869             :  * return a 2-element list that gets disassembled by calling production.
   13870             :  */
   13871             : func_alias_clause:
   13872             :             alias_clause
   13873             :                 {
   13874       29712 :                     $$ = list_make2($1, NIL);
   13875             :                 }
   13876             :             | AS '(' TableFuncElementList ')'
   13877             :                 {
   13878         114 :                     $$ = list_make2(NULL, $3);
   13879             :                 }
   13880             :             | AS ColId '(' TableFuncElementList ')'
   13881             :                 {
   13882         594 :                     Alias      *a = makeNode(Alias);
   13883             : 
   13884         594 :                     a->aliasname = $2;
   13885         594 :                     $$ = list_make2(a, $4);
   13886             :                 }
   13887             :             | ColId '(' TableFuncElementList ')'
   13888             :                 {
   13889          50 :                     Alias      *a = makeNode(Alias);
   13890             : 
   13891          50 :                     a->aliasname = $1;
   13892          50 :                     $$ = list_make2(a, $3);
   13893             :                 }
   13894             :             | /*EMPTY*/
   13895             :                 {
   13896       17164 :                     $$ = list_make2(NULL, NIL);
   13897             :                 }
   13898             :         ;
   13899             : 
   13900        1042 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13901       40184 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13902         360 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13903        3910 :             | INNER_P                               { $$ = JOIN_INNER; }
   13904             :         ;
   13905             : 
   13906             : /* OUTER is just noise... */
   13907             : opt_outer: OUTER_P
   13908             :             | /*EMPTY*/
   13909             :         ;
   13910             : 
   13911             : /* JOIN qualification clauses
   13912             :  * Possibilities are:
   13913             :  *  USING ( column list ) [ AS alias ]
   13914             :  *                        allows only unqualified column names,
   13915             :  *                        which must match between tables.
   13916             :  *  ON expr allows more general qualifications.
   13917             :  *
   13918             :  * We return USING as a two-element List (the first item being a sub-List
   13919             :  * of the common column names, and the second either an Alias item or NULL).
   13920             :  * An ON-expr will not be a List, so it can be told apart that way.
   13921             :  */
   13922             : 
   13923             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   13924             :                 {
   13925        1224 :                     $$ = (Node *) list_make2($3, $5);
   13926             :                 }
   13927             :             | ON a_expr
   13928             :                 {
   13929       77970 :                     $$ = $2;
   13930             :                 }
   13931             :         ;
   13932             : 
   13933             : 
   13934             : relation_expr:
   13935             :             qualified_name
   13936             :                 {
   13937             :                     /* inheritance query, implicitly */
   13938      459582 :                     $$ = $1;
   13939      459582 :                     $$->inh = true;
   13940      459582 :                     $$->alias = NULL;
   13941             :                 }
   13942             :             | extended_relation_expr
   13943             :                 {
   13944        6934 :                     $$ = $1;
   13945             :                 }
   13946             :         ;
   13947             : 
   13948             : extended_relation_expr:
   13949             :             qualified_name '*'
   13950             :                 {
   13951             :                     /* inheritance query, explicitly */
   13952         204 :                     $$ = $1;
   13953         204 :                     $$->inh = true;
   13954         204 :                     $$->alias = NULL;
   13955             :                 }
   13956             :             | ONLY qualified_name
   13957             :                 {
   13958             :                     /* no inheritance */
   13959        6736 :                     $$ = $2;
   13960        6736 :                     $$->inh = false;
   13961        6736 :                     $$->alias = NULL;
   13962             :                 }
   13963             :             | ONLY '(' qualified_name ')'
   13964             :                 {
   13965             :                     /* no inheritance, SQL99-style syntax */
   13966           0 :                     $$ = $3;
   13967           0 :                     $$->inh = false;
   13968           0 :                     $$->alias = NULL;
   13969             :                 }
   13970             :         ;
   13971             : 
   13972             : 
   13973             : relation_expr_list:
   13974        2838 :             relation_expr                           { $$ = list_make1($1); }
   13975       10720 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   13976             :         ;
   13977             : 
   13978             : 
   13979             : /*
   13980             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   13981             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   13982             :  * keyword.  Since "set" is allowed as a column name both interpretations
   13983             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   13984             :  * relation_expr_opt_alias production a higher precedence than the SET token
   13985             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   13986             :  * SET is not an alias.
   13987             :  */
   13988             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   13989             :                 {
   13990       18330 :                     $$ = $1;
   13991             :                 }
   13992             :             | relation_expr ColId
   13993             :                 {
   13994        2186 :                     Alias      *alias = makeNode(Alias);
   13995             : 
   13996        2186 :                     alias->aliasname = $2;
   13997        2186 :                     $1->alias = alias;
   13998        2186 :                     $$ = $1;
   13999             :                 }
   14000             :             | relation_expr AS ColId
   14001             :                 {
   14002          90 :                     Alias      *alias = makeNode(Alias);
   14003             : 
   14004          90 :                     alias->aliasname = $3;
   14005          90 :                     $1->alias = alias;
   14006          90 :                     $$ = $1;
   14007             :                 }
   14008             :         ;
   14009             : 
   14010             : /*
   14011             :  * TABLESAMPLE decoration in a FROM item
   14012             :  */
   14013             : tablesample_clause:
   14014             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   14015             :                 {
   14016         260 :                     RangeTableSample *n = makeNode(RangeTableSample);
   14017             : 
   14018             :                     /* n->relation will be filled in later */
   14019         260 :                     n->method = $2;
   14020         260 :                     n->args = $4;
   14021         260 :                     n->repeatable = $6;
   14022         260 :                     n->location = @2;
   14023         260 :                     $$ = (Node *) n;
   14024             :                 }
   14025             :         ;
   14026             : 
   14027             : opt_repeatable_clause:
   14028         108 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14029         152 :             | /*EMPTY*/                 { $$ = NULL; }
   14030             :         ;
   14031             : 
   14032             : /*
   14033             :  * func_table represents a function invocation in a FROM list. It can be
   14034             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14035             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14036             :  * optionally with WITH ORDINALITY attached.
   14037             :  * In the ROWS FROM syntax, a column definition list can be given for each
   14038             :  * function, for example:
   14039             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14040             :  *                bar() AS (bar_res_a text, bar_res_b text))
   14041             :  * It's also possible to attach a column definition list to the RangeFunction
   14042             :  * as a whole, but that's handled by the table_ref production.
   14043             :  */
   14044             : func_table: func_expr_windowless opt_ordinality
   14045             :                 {
   14046       47508 :                     RangeFunction *n = makeNode(RangeFunction);
   14047             : 
   14048       47508 :                     n->lateral = false;
   14049       47508 :                     n->ordinality = $2;
   14050       47508 :                     n->is_rowsfrom = false;
   14051       47508 :                     n->functions = list_make1(list_make2($1, NIL));
   14052             :                     /* alias and coldeflist are set by table_ref production */
   14053       47508 :                     $$ = (Node *) n;
   14054             :                 }
   14055             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14056             :                 {
   14057         132 :                     RangeFunction *n = makeNode(RangeFunction);
   14058             : 
   14059         132 :                     n->lateral = false;
   14060         132 :                     n->ordinality = $6;
   14061         132 :                     n->is_rowsfrom = true;
   14062         132 :                     n->functions = $4;
   14063             :                     /* alias and coldeflist are set by table_ref production */
   14064         132 :                     $$ = (Node *) n;
   14065             :                 }
   14066             :         ;
   14067             : 
   14068             : rowsfrom_item: func_expr_windowless opt_col_def_list
   14069         318 :                 { $$ = list_make2($1, $2); }
   14070             :         ;
   14071             : 
   14072             : rowsfrom_list:
   14073         132 :             rowsfrom_item                       { $$ = list_make1($1); }
   14074         186 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14075             :         ;
   14076             : 
   14077          54 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14078         264 :             | /*EMPTY*/                             { $$ = NIL; }
   14079             :         ;
   14080             : 
   14081         784 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14082       46856 :             | /*EMPTY*/                             { $$ = false; }
   14083             :         ;
   14084             : 
   14085             : 
   14086             : where_clause:
   14087      203062 :             WHERE a_expr                            { $$ = $2; }
   14088      315456 :             | /*EMPTY*/                             { $$ = NULL; }
   14089             :         ;
   14090             : 
   14091             : /* variant for UPDATE and DELETE */
   14092             : where_or_current_clause:
   14093       13264 :             WHERE a_expr                            { $$ = $2; }
   14094             :             | WHERE CURRENT_P OF cursor_name
   14095             :                 {
   14096         266 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14097             : 
   14098             :                     /* cvarno is filled in by parse analysis */
   14099         266 :                     n->cursor_name = $4;
   14100         266 :                     n->cursor_param = 0;
   14101         266 :                     $$ = (Node *) n;
   14102             :                 }
   14103        4970 :             | /*EMPTY*/                             { $$ = NULL; }
   14104             :         ;
   14105             : 
   14106             : 
   14107             : OptTableFuncElementList:
   14108         714 :             TableFuncElementList                { $$ = $1; }
   14109        3786 :             | /*EMPTY*/                         { $$ = NIL; }
   14110             :         ;
   14111             : 
   14112             : TableFuncElementList:
   14113             :             TableFuncElement
   14114             :                 {
   14115        1526 :                     $$ = list_make1($1);
   14116             :                 }
   14117             :             | TableFuncElementList ',' TableFuncElement
   14118             :                 {
   14119        2050 :                     $$ = lappend($1, $3);
   14120             :                 }
   14121             :         ;
   14122             : 
   14123             : TableFuncElement:   ColId Typename opt_collate_clause
   14124             :                 {
   14125        3640 :                     ColumnDef *n = makeNode(ColumnDef);
   14126             : 
   14127        3640 :                     n->colname = $1;
   14128        3640 :                     n->typeName = $2;
   14129        3640 :                     n->inhcount = 0;
   14130        3640 :                     n->is_local = true;
   14131        3640 :                     n->is_not_null = false;
   14132        3640 :                     n->is_from_type = false;
   14133        3640 :                     n->storage = 0;
   14134        3640 :                     n->raw_default = NULL;
   14135        3640 :                     n->cooked_default = NULL;
   14136        3640 :                     n->collClause = (CollateClause *) $3;
   14137        3640 :                     n->collOid = InvalidOid;
   14138        3640 :                     n->constraints = NIL;
   14139        3640 :                     n->location = @1;
   14140        3640 :                     $$ = (Node *) n;
   14141             :                 }
   14142             :         ;
   14143             : 
   14144             : /*
   14145             :  * XMLTABLE
   14146             :  */
   14147             : xmltable:
   14148             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14149             :                 {
   14150         200 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14151             : 
   14152         200 :                     n->rowexpr = $3;
   14153         200 :                     n->docexpr = $4;
   14154         200 :                     n->columns = $6;
   14155         200 :                     n->namespaces = NIL;
   14156         200 :                     n->location = @1;
   14157         200 :                     $$ = (Node *) n;
   14158             :                 }
   14159             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14160             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14161             :                 {
   14162          20 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14163             : 
   14164          20 :                     n->rowexpr = $8;
   14165          20 :                     n->docexpr = $9;
   14166          20 :                     n->columns = $11;
   14167          20 :                     n->namespaces = $5;
   14168          20 :                     n->location = @1;
   14169          20 :                     $$ = (Node *) n;
   14170             :                 }
   14171             :         ;
   14172             : 
   14173         220 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14174         530 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14175             :         ;
   14176             : 
   14177             : xmltable_column_el:
   14178             :             ColId Typename
   14179             :                 {
   14180         198 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14181             : 
   14182         198 :                     fc->colname = $1;
   14183         198 :                     fc->for_ordinality = false;
   14184         198 :                     fc->typeName = $2;
   14185         198 :                     fc->is_not_null = false;
   14186         198 :                     fc->colexpr = NULL;
   14187         198 :                     fc->coldefexpr = NULL;
   14188         198 :                     fc->location = @1;
   14189             : 
   14190         198 :                     $$ = (Node *) fc;
   14191             :                 }
   14192             :             | ColId Typename xmltable_column_option_list
   14193             :                 {
   14194         490 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14195             :                     ListCell   *option;
   14196         490 :                     bool        nullability_seen = false;
   14197             : 
   14198         490 :                     fc->colname = $1;
   14199         490 :                     fc->typeName = $2;
   14200         490 :                     fc->for_ordinality = false;
   14201         490 :                     fc->is_not_null = false;
   14202         490 :                     fc->colexpr = NULL;
   14203         490 :                     fc->coldefexpr = NULL;
   14204         490 :                     fc->location = @1;
   14205             : 
   14206        1092 :                     foreach(option, $3)
   14207             :                     {
   14208         602 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14209             : 
   14210         602 :                         if (strcmp(defel->defname, "default") == 0)
   14211             :                         {
   14212          56 :                             if (fc->coldefexpr != NULL)
   14213           0 :                                 ereport(ERROR,
   14214             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14215             :                                          errmsg("only one DEFAULT value is allowed"),
   14216             :                                          parser_errposition(defel->location)));
   14217          56 :                             fc->coldefexpr = defel->arg;
   14218             :                         }
   14219         546 :                         else if (strcmp(defel->defname, "path") == 0)
   14220             :                         {
   14221         490 :                             if (fc->colexpr != NULL)
   14222           0 :                                 ereport(ERROR,
   14223             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14224             :                                          errmsg("only one PATH value per column is allowed"),
   14225             :                                          parser_errposition(defel->location)));
   14226         490 :                             fc->colexpr = defel->arg;
   14227             :                         }
   14228          56 :                         else if (strcmp(defel->defname, "is_not_null") == 0)
   14229             :                         {
   14230          56 :                             if (nullability_seen)
   14231           0 :                                 ereport(ERROR,
   14232             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14233             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14234             :                                          parser_errposition(defel->location)));
   14235          56 :                             fc->is_not_null = boolVal(defel->arg);
   14236          56 :                             nullability_seen = true;
   14237             :                         }
   14238             :                         else
   14239             :                         {
   14240           0 :                             ereport(ERROR,
   14241             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14242             :                                      errmsg("unrecognized column option \"%s\"",
   14243             :                                             defel->defname),
   14244             :                                      parser_errposition(defel->location)));
   14245             :                         }
   14246             :                     }
   14247         490 :                     $$ = (Node *) fc;
   14248             :                 }
   14249             :             | ColId FOR ORDINALITY
   14250             :                 {
   14251          62 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14252             : 
   14253          62 :                     fc->colname = $1;
   14254          62 :                     fc->for_ordinality = true;
   14255             :                     /* other fields are ignored, initialized by makeNode */
   14256          62 :                     fc->location = @1;
   14257             : 
   14258          62 :                     $$ = (Node *) fc;
   14259             :                 }
   14260             :         ;
   14261             : 
   14262             : xmltable_column_option_list:
   14263             :             xmltable_column_option_el
   14264         490 :                 { $$ = list_make1($1); }
   14265             :             | xmltable_column_option_list xmltable_column_option_el
   14266         112 :                 { $$ = lappend($1, $2); }
   14267             :         ;
   14268             : 
   14269             : xmltable_column_option_el:
   14270             :             IDENT b_expr
   14271           0 :                 { $$ = makeDefElem($1, $2, @1); }
   14272             :             | DEFAULT b_expr
   14273          56 :                 { $$ = makeDefElem("default", $2, @1); }
   14274             :             | NOT NULL_P
   14275          56 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
   14276             :             | NULL_P
   14277           0 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
   14278             :             | PATH b_expr
   14279         490 :                 { $$ = makeDefElem("path", $2, @1); }
   14280             :         ;
   14281             : 
   14282             : xml_namespace_list:
   14283             :             xml_namespace_el
   14284          20 :                 { $$ = list_make1($1); }
   14285             :             | xml_namespace_list ',' xml_namespace_el
   14286           0 :                 { $$ = lappend($1, $3); }
   14287             :         ;
   14288             : 
   14289             : xml_namespace_el:
   14290             :             b_expr AS ColLabel
   14291             :                 {
   14292          14 :                     $$ = makeNode(ResTarget);
   14293          14 :                     $$->name = $3;
   14294          14 :                     $$->indirection = NIL;
   14295          14 :                     $$->val = $1;
   14296          14 :                     $$->location = @1;
   14297             :                 }
   14298             :             | DEFAULT b_expr
   14299             :                 {
   14300           6 :                     $$ = makeNode(ResTarget);
   14301           6 :                     $$->name = NULL;
   14302           6 :                     $$->indirection = NIL;
   14303           6 :                     $$->val = $2;
   14304           6 :                     $$->location = @1;
   14305             :                 }
   14306             :         ;
   14307             : 
   14308             : json_table:
   14309             :             JSON_TABLE '('
   14310             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14311             :                 json_passing_clause_opt
   14312             :                 COLUMNS '(' json_table_column_definition_list ')'
   14313             :                 json_on_error_clause_opt
   14314             :             ')'
   14315             :                 {
   14316         530 :                     JsonTable *n = makeNode(JsonTable);
   14317             :                     char      *pathstring;
   14318             : 
   14319         530 :                     n->context_item = (JsonValueExpr *) $3;
   14320         530 :                     if (!IsA($5, A_Const) ||
   14321         524 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14322           6 :                         ereport(ERROR,
   14323             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14324             :                                 errmsg("only string constants are supported in JSON_TABLE path specification"),
   14325             :                                 parser_errposition(@5));
   14326         524 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14327         524 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14328         524 :                     n->passing = $7;
   14329         524 :                     n->columns = $10;
   14330         524 :                     n->on_error = (JsonBehavior *) $12;
   14331         524 :                     n->location = @1;
   14332         524 :                     $$ = (Node *) n;
   14333             :                 }
   14334             :         ;
   14335             : 
   14336             : json_table_path_name_opt:
   14337          62 :             AS name         { $$ = $2; }
   14338         480 :             | /* empty */   { $$ = NULL; }
   14339             :         ;
   14340             : 
   14341             : json_table_column_definition_list:
   14342             :             json_table_column_definition
   14343         820 :                 { $$ = list_make1($1); }
   14344             :             | json_table_column_definition_list ',' json_table_column_definition
   14345         528 :                 { $$ = lappend($1, $3); }
   14346             :         ;
   14347             : 
   14348             : json_table_column_definition:
   14349             :             ColId FOR ORDINALITY
   14350             :                 {
   14351          84 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14352             : 
   14353          84 :                     n->coltype = JTC_FOR_ORDINALITY;
   14354          84 :                     n->name = $1;
   14355          84 :                     n->location = @1;
   14356          84 :                     $$ = (Node *) n;
   14357             :                 }
   14358             :             | ColId Typename
   14359             :                 json_table_column_path_clause_opt
   14360             :                 json_wrapper_behavior
   14361             :                 json_quotes_clause_opt
   14362             :                 json_behavior_clause_opt
   14363             :                 {
   14364         728 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14365             : 
   14366         728 :                     n->coltype = JTC_REGULAR;
   14367         728 :                     n->name = $1;
   14368         728 :                     n->typeName = $2;
   14369         728 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14370         728 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14371         728 :                     n->wrapper = $4;
   14372         728 :                     n->quotes = $5;
   14373         728 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14374         728 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14375         728 :                     n->location = @1;
   14376         728 :                     $$ = (Node *) n;
   14377             :                 }
   14378             :             | ColId Typename json_format_clause
   14379             :                 json_table_column_path_clause_opt
   14380             :                 json_wrapper_behavior
   14381             :                 json_quotes_clause_opt
   14382             :                 json_behavior_clause_opt
   14383             :                 {
   14384         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14385             : 
   14386         108 :                     n->coltype = JTC_FORMATTED;
   14387         108 :                     n->name = $1;
   14388         108 :                     n->typeName = $2;
   14389         108 :                     n->format = (JsonFormat *) $3;
   14390         108 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14391         108 :                     n->wrapper = $5;
   14392         108 :                     n->quotes = $6;
   14393         108 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14394         108 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14395         108 :                     n->location = @1;
   14396         108 :                     $$ = (Node *) n;
   14397             :                 }
   14398             :             | ColId Typename
   14399             :                 EXISTS json_table_column_path_clause_opt
   14400             :                 json_on_error_clause_opt
   14401             :                 {
   14402         138 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14403             : 
   14404         138 :                     n->coltype = JTC_EXISTS;
   14405         138 :                     n->name = $1;
   14406         138 :                     n->typeName = $2;
   14407         138 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14408         138 :                     n->wrapper = JSW_NONE;
   14409         138 :                     n->quotes = JS_QUOTES_UNSPEC;
   14410         138 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14411         138 :                     n->on_empty = NULL;
   14412         138 :                     n->on_error = (JsonBehavior *) $5;
   14413         138 :                     n->location = @1;
   14414         138 :                     $$ = (Node *) n;
   14415             :                 }
   14416             :             | NESTED path_opt Sconst
   14417             :                 COLUMNS '(' json_table_column_definition_list ')'
   14418             :                 {
   14419         144 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14420             : 
   14421         144 :                     n->coltype = JTC_NESTED;
   14422         288 :                     n->pathspec = (JsonTablePathSpec *)
   14423         144 :                         makeJsonTablePathSpec($3, NULL, @3, -1);
   14424         144 :                     n->columns = $6;
   14425         144 :                     n->location = @1;
   14426         144 :                     $$ = (Node *) n;
   14427             :                 }
   14428             :             | NESTED path_opt Sconst AS name
   14429             :                 COLUMNS '(' json_table_column_definition_list ')'
   14430             :                 {
   14431         146 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14432             : 
   14433         146 :                     n->coltype = JTC_NESTED;
   14434         292 :                     n->pathspec = (JsonTablePathSpec *)
   14435         146 :                         makeJsonTablePathSpec($3, $5, @3, @5);
   14436         146 :                     n->columns = $8;
   14437         146 :                     n->location = @1;
   14438         146 :                     $$ = (Node *) n;
   14439             :                 }
   14440             :         ;
   14441             : 
   14442             : path_opt:
   14443             :             PATH
   14444             :             | /* EMPTY */
   14445             :         ;
   14446             : 
   14447             : json_table_column_path_clause_opt:
   14448             :             PATH Sconst
   14449         828 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14450             :             | /* EMPTY */
   14451         152 :                 { $$ = NULL; }
   14452             :         ;
   14453             : 
   14454             : /*****************************************************************************
   14455             :  *
   14456             :  *  Type syntax
   14457             :  *      SQL introduces a large amount of type-specific syntax.
   14458             :  *      Define individual clauses to handle these cases, and use
   14459             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14460             :  *      - thomas 1997-10-10
   14461             :  *
   14462             :  *****************************************************************************/
   14463             : 
   14464             : Typename:   SimpleTypename opt_array_bounds
   14465             :                 {
   14466      479922 :                     $$ = $1;
   14467      479922 :                     $$->arrayBounds = $2;
   14468             :                 }
   14469             :             | SETOF SimpleTypename opt_array_bounds
   14470             :                 {
   14471        2170 :                     $$ = $2;
   14472        2170 :                     $$->arrayBounds = $3;
   14473        2170 :                     $$->setof = true;
   14474             :                 }
   14475             :             /* SQL standard syntax, currently only one-dimensional */
   14476             :             | SimpleTypename ARRAY '[' Iconst ']'
   14477             :                 {
   14478           6 :                     $$ = $1;
   14479           6 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14480             :                 }
   14481             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14482             :                 {
   14483           0 :                     $$ = $2;
   14484           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14485           0 :                     $$->setof = true;
   14486             :                 }
   14487             :             | SimpleTypename ARRAY
   14488             :                 {
   14489           0 :                     $$ = $1;
   14490           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14491             :                 }
   14492             :             | SETOF SimpleTypename ARRAY
   14493             :                 {
   14494           0 :                     $$ = $2;
   14495           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14496           0 :                     $$->setof = true;
   14497             :                 }
   14498             :         ;
   14499             : 
   14500             : opt_array_bounds:
   14501             :             opt_array_bounds '[' ']'
   14502       13276 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14503             :             | opt_array_bounds '[' Iconst ']'
   14504          62 :                     {  $$ = lappend($1, makeInteger($3)); }
   14505             :             | /*EMPTY*/
   14506      482092 :                     {  $$ = NIL; }
   14507             :         ;
   14508             : 
   14509             : SimpleTypename:
   14510      373614 :             GenericType                             { $$ = $1; }
   14511       94062 :             | Numeric                               { $$ = $1; }
   14512        1890 :             | Bit                                   { $$ = $1; }
   14513        2966 :             | Character                             { $$ = $1; }
   14514        4604 :             | ConstDatetime                         { $$ = $1; }
   14515             :             | ConstInterval opt_interval
   14516             :                 {
   14517        3520 :                     $$ = $1;
   14518        3520 :                     $$->typmods = $2;
   14519             :                 }
   14520             :             | ConstInterval '(' Iconst ')'
   14521             :                 {
   14522           0 :                     $$ = $1;
   14523           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14524             :                                              makeIntConst($3, @3));
   14525             :                 }
   14526        1850 :             | JsonType                              { $$ = $1; }
   14527             :         ;
   14528             : 
   14529             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14530             :  * types such as CHAR() and BIT() to an unspecified length.
   14531             :  * SQL9x requires that these default to a length of one, but this
   14532             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14533             :  * where there is an obvious better choice to make.
   14534             :  * Note that ConstInterval is not included here since it must
   14535             :  * be pushed up higher in the rules to accommodate the postfix
   14536             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14537             :  * the generic-type-name case in AexprConst to avoid premature
   14538             :  * reduce/reduce conflicts against function names.
   14539             :  */
   14540             : ConstTypename:
   14541          78 :             Numeric                                 { $$ = $1; }
   14542           0 :             | ConstBit                              { $$ = $1; }
   14543          34 :             | ConstCharacter                        { $$ = $1; }
   14544        2738 :             | ConstDatetime                         { $$ = $1; }
   14545         264 :             | JsonType                              { $$ = $1; }
   14546             :         ;
   14547             : 
   14548             : /*
   14549             :  * GenericType covers all type names that don't have special syntax mandated
   14550             :  * by the standard, including qualified names.  We also allow type modifiers.
   14551             :  * To avoid parsing conflicts against function invocations, the modifiers
   14552             :  * have to be shown as expr_list here, but parse analysis will only accept
   14553             :  * constants for them.
   14554             :  */
   14555             : GenericType:
   14556             :             type_function_name opt_type_modifiers
   14557             :                 {
   14558      266904 :                     $$ = makeTypeName($1);
   14559      266904 :                     $$->typmods = $2;
   14560      266904 :                     $$->location = @1;
   14561             :                 }
   14562             :             | type_function_name attrs opt_type_modifiers
   14563             :                 {
   14564      106710 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14565      106710 :                     $$->typmods = $3;
   14566      106710 :                     $$->location = @1;
   14567             :                 }
   14568             :         ;
   14569             : 
   14570        1350 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14571      378244 :                     | /* EMPTY */                   { $$ = NIL; }
   14572             :         ;
   14573             : 
   14574             : /*
   14575             :  * SQL numeric data types
   14576             :  */
   14577             : Numeric:    INT_P
   14578             :                 {
   14579       37370 :                     $$ = SystemTypeName("int4");
   14580       37370 :                     $$->location = @1;
   14581             :                 }
   14582             :             | INTEGER
   14583             :                 {
   14584       24644 :                     $$ = SystemTypeName("int4");
   14585       24644 :                     $$->location = @1;
   14586             :                 }
   14587             :             | SMALLINT
   14588             :                 {
   14589        1252 :                     $$ = SystemTypeName("int2");
   14590        1252 :                     $$->location = @1;
   14591             :                 }
   14592             :             | BIGINT
   14593             :                 {
   14594        4758 :                     $$ = SystemTypeName("int8");
   14595        4758 :                     $$->location = @1;
   14596             :                 }
   14597             :             | REAL
   14598             :                 {
   14599        6908 :                     $$ = SystemTypeName("float4");
   14600        6908 :                     $$->location = @1;
   14601             :                 }
   14602             :             | FLOAT_P opt_float
   14603             :                 {
   14604         538 :                     $$ = $2;
   14605         538 :                     $$->location = @1;
   14606             :                 }
   14607             :             | DOUBLE_P PRECISION
   14608             :                 {
   14609         702 :                     $$ = SystemTypeName("float8");
   14610         702 :                     $$->location = @1;
   14611             :                 }
   14612             :             | DECIMAL_P opt_type_modifiers
   14613             :                 {
   14614          36 :                     $$ = SystemTypeName("numeric");
   14615          36 :                     $$->typmods = $2;
   14616          36 :                     $$->location = @1;
   14617             :                 }
   14618             :             | DEC opt_type_modifiers
   14619             :                 {
   14620           0 :                     $$ = SystemTypeName("numeric");
   14621           0 :                     $$->typmods = $2;
   14622           0 :                     $$->location = @1;
   14623             :                 }
   14624             :             | NUMERIC opt_type_modifiers
   14625             :                 {
   14626        5944 :                     $$ = SystemTypeName("numeric");
   14627        5944 :                     $$->typmods = $2;
   14628        5944 :                     $$->location = @1;
   14629             :                 }
   14630             :             | BOOLEAN_P
   14631             :                 {
   14632       11988 :                     $$ = SystemTypeName("bool");
   14633       11988 :                     $$->location = @1;
   14634             :                 }
   14635             :         ;
   14636             : 
   14637             : opt_float:  '(' Iconst ')'
   14638             :                 {
   14639             :                     /*
   14640             :                      * Check FLOAT() precision limits assuming IEEE floating
   14641             :                      * types - thomas 1997-09-18
   14642             :                      */
   14643           2 :                     if ($2 < 1)
   14644           0 :                         ereport(ERROR,
   14645             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14646             :                                  errmsg("precision for type float must be at least 1 bit"),
   14647             :                                  parser_errposition(@2)));
   14648           2 :                     else if ($2 <= 24)
   14649           2 :                         $$ = SystemTypeName("float4");
   14650           0 :                     else if ($2 <= 53)
   14651           0 :                         $$ = SystemTypeName("float8");
   14652             :                     else
   14653           0 :                         ereport(ERROR,
   14654             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14655             :                                  errmsg("precision for type float must be less than 54 bits"),
   14656             :                                  parser_errposition(@2)));
   14657             :                 }
   14658             :             | /*EMPTY*/
   14659             :                 {
   14660         536 :                     $$ = SystemTypeName("float8");
   14661             :                 }
   14662             :         ;
   14663             : 
   14664             : /*
   14665             :  * SQL bit-field data types
   14666             :  * The following implements BIT() and BIT VARYING().
   14667             :  */
   14668             : Bit:        BitWithLength
   14669             :                 {
   14670        1696 :                     $$ = $1;
   14671             :                 }
   14672             :             | BitWithoutLength
   14673             :                 {
   14674         194 :                     $$ = $1;
   14675             :                 }
   14676             :         ;
   14677             : 
   14678             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14679             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14680             : ConstBit:   BitWithLength
   14681             :                 {
   14682           0 :                     $$ = $1;
   14683             :                 }
   14684             :             | BitWithoutLength
   14685             :                 {
   14686           0 :                     $$ = $1;
   14687           0 :                     $$->typmods = NIL;
   14688             :                 }
   14689             :         ;
   14690             : 
   14691             : BitWithLength:
   14692             :             BIT opt_varying '(' expr_list ')'
   14693             :                 {
   14694             :                     char *typname;
   14695             : 
   14696        1696 :                     typname = $2 ? "varbit" : "bit";
   14697        1696 :                     $$ = SystemTypeName(typname);
   14698        1696 :                     $$->typmods = $4;
   14699        1696 :                     $$->location = @1;
   14700             :                 }
   14701             :         ;
   14702             : 
   14703             : BitWithoutLength:
   14704             :             BIT opt_varying
   14705             :                 {
   14706             :                     /* bit defaults to bit(1), varbit to no limit */
   14707         194 :                     if ($2)
   14708             :                     {
   14709          20 :                         $$ = SystemTypeName("varbit");
   14710             :                     }
   14711             :                     else
   14712             :                     {
   14713         174 :                         $$ = SystemTypeName("bit");
   14714         174 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14715             :                     }
   14716         194 :                     $$->location = @1;
   14717             :                 }
   14718             :         ;
   14719             : 
   14720             : 
   14721             : /*
   14722             :  * SQL character data types
   14723             :  * The following implements CHAR() and VARCHAR().
   14724             :  */
   14725             : Character:  CharacterWithLength
   14726             :                 {
   14727        1706 :                     $$ = $1;
   14728             :                 }
   14729             :             | CharacterWithoutLength
   14730             :                 {
   14731        1260 :                     $$ = $1;
   14732             :                 }
   14733             :         ;
   14734             : 
   14735             : ConstCharacter:  CharacterWithLength
   14736             :                 {
   14737          12 :                     $$ = $1;
   14738             :                 }
   14739             :             | CharacterWithoutLength
   14740             :                 {
   14741             :                     /* Length was not specified so allow to be unrestricted.
   14742             :                      * This handles problems with fixed-length (bpchar) strings
   14743             :                      * which in column definitions must default to a length
   14744             :                      * of one, but should not be constrained if the length
   14745             :                      * was not specified.
   14746             :                      */
   14747          22 :                     $$ = $1;
   14748          22 :                     $$->typmods = NIL;
   14749             :                 }
   14750             :         ;
   14751             : 
   14752             : CharacterWithLength:  character '(' Iconst ')'
   14753             :                 {
   14754        1718 :                     $$ = SystemTypeName($1);
   14755        1718 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14756        1718 :                     $$->location = @1;
   14757             :                 }
   14758             :         ;
   14759             : 
   14760             : CharacterWithoutLength:  character
   14761             :                 {
   14762        1282 :                     $$ = SystemTypeName($1);
   14763             :                     /* char defaults to char(1), varchar to no limit */
   14764        1282 :                     if (strcmp($1, "bpchar") == 0)
   14765         252 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14766        1282 :                     $$->location = @1;
   14767             :                 }
   14768             :         ;
   14769             : 
   14770             : character:  CHARACTER opt_varying
   14771         532 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14772             :             | CHAR_P opt_varying
   14773        1170 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14774             :             | VARCHAR
   14775        1294 :                                         { $$ = "varchar"; }
   14776             :             | NATIONAL CHARACTER opt_varying
   14777           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14778             :             | NATIONAL CHAR_P opt_varying
   14779           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14780             :             | NCHAR opt_varying
   14781           4 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14782             :         ;
   14783             : 
   14784             : opt_varying:
   14785         428 :             VARYING                                 { $$ = true; }
   14786        3168 :             | /*EMPTY*/                             { $$ = false; }
   14787             :         ;
   14788             : 
   14789             : /*
   14790             :  * SQL date/time types
   14791             :  */
   14792             : ConstDatetime:
   14793             :             TIMESTAMP '(' Iconst ')' opt_timezone
   14794             :                 {
   14795         124 :                     if ($5)
   14796         100 :                         $$ = SystemTypeName("timestamptz");
   14797             :                     else
   14798          24 :                         $$ = SystemTypeName("timestamp");
   14799         124 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14800         124 :                     $$->location = @1;
   14801             :                 }
   14802             :             | TIMESTAMP opt_timezone
   14803             :                 {
   14804        4848 :                     if ($2)
   14805        1364 :                         $$ = SystemTypeName("timestamptz");
   14806             :                     else
   14807        3484 :                         $$ = SystemTypeName("timestamp");
   14808        4848 :                     $$->location = @1;
   14809             :                 }
   14810             :             | TIME '(' Iconst ')' opt_timezone
   14811             :                 {
   14812          22 :                     if ($5)
   14813           8 :                         $$ = SystemTypeName("timetz");
   14814             :                     else
   14815          14 :                         $$ = SystemTypeName("time");
   14816          22 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14817          22 :                     $$->location = @1;
   14818             :                 }
   14819             :             | TIME opt_timezone
   14820             :                 {
   14821        2348 :                     if ($2)
   14822         344 :                         $$ = SystemTypeName("timetz");
   14823             :                     else
   14824        2004 :                         $$ = SystemTypeName("time");
   14825        2348 :                     $$->location = @1;
   14826             :                 }
   14827             :         ;
   14828             : 
   14829             : ConstInterval:
   14830             :             INTERVAL
   14831             :                 {
   14832        6830 :                     $$ = SystemTypeName("interval");
   14833        6830 :                     $$->location = @1;
   14834             :                 }
   14835             :         ;
   14836             : 
   14837             : opt_timezone:
   14838        1816 :             WITH_LA TIME ZONE                       { $$ = true; }
   14839         592 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14840        4934 :             | /*EMPTY*/                             { $$ = false; }
   14841             :         ;
   14842             : 
   14843             : opt_interval:
   14844             :             YEAR_P
   14845          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14846             :             | MONTH_P
   14847          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14848             :             | DAY_P
   14849          18 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14850             :             | HOUR_P
   14851          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14852             :             | MINUTE_P
   14853          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14854             :             | interval_second
   14855          36 :                 { $$ = $1; }
   14856             :             | YEAR_P TO MONTH_P
   14857             :                 {
   14858          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14859             :                                                  INTERVAL_MASK(MONTH), @1));
   14860             :                 }
   14861             :             | DAY_P TO HOUR_P
   14862             :                 {
   14863          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14864             :                                                  INTERVAL_MASK(HOUR), @1));
   14865             :                 }
   14866             :             | DAY_P TO MINUTE_P
   14867             :                 {
   14868          24 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14869             :                                                  INTERVAL_MASK(HOUR) |
   14870             :                                                  INTERVAL_MASK(MINUTE), @1));
   14871             :                 }
   14872             :             | DAY_P TO interval_second
   14873             :                 {
   14874          48 :                     $$ = $3;
   14875          48 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14876             :                                                 INTERVAL_MASK(HOUR) |
   14877             :                                                 INTERVAL_MASK(MINUTE) |
   14878          48 :                                                 INTERVAL_MASK(SECOND), @1);
   14879             :                 }
   14880             :             | HOUR_P TO MINUTE_P
   14881             :                 {
   14882          18 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14883             :                                                  INTERVAL_MASK(MINUTE), @1));
   14884             :                 }
   14885             :             | HOUR_P TO interval_second
   14886             :                 {
   14887          36 :                     $$ = $3;
   14888          36 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14889             :                                                 INTERVAL_MASK(MINUTE) |
   14890          36 :                                                 INTERVAL_MASK(SECOND), @1);
   14891             :                 }
   14892             :             | MINUTE_P TO interval_second
   14893             :                 {
   14894          66 :                     $$ = $3;
   14895          66 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14896          66 :                                                 INTERVAL_MASK(SECOND), @1);
   14897             :                 }
   14898             :             | /*EMPTY*/
   14899        6476 :                 { $$ = NIL; }
   14900             :         ;
   14901             : 
   14902             : interval_second:
   14903             :             SECOND_P
   14904             :                 {
   14905         102 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   14906             :                 }
   14907             :             | SECOND_P '(' Iconst ')'
   14908             :                 {
   14909          84 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   14910             :                                     makeIntConst($3, @3));
   14911             :                 }
   14912             :         ;
   14913             : 
   14914             : JsonType:
   14915             :             JSON
   14916             :                 {
   14917        2114 :                     $$ = SystemTypeName("json");
   14918        2114 :                     $$->location = @1;
   14919             :                 }
   14920             :         ;
   14921             : 
   14922             : /*****************************************************************************
   14923             :  *
   14924             :  *  expression grammar
   14925             :  *
   14926             :  *****************************************************************************/
   14927             : 
   14928             : /*
   14929             :  * General expressions
   14930             :  * This is the heart of the expression syntax.
   14931             :  *
   14932             :  * We have two expression types: a_expr is the unrestricted kind, and
   14933             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   14934             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   14935             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   14936             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   14937             :  *
   14938             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   14939             :  * always be used by surrounding it with parens.
   14940             :  *
   14941             :  * c_expr is all the productions that are common to a_expr and b_expr;
   14942             :  * it's factored out just to eliminate redundant coding.
   14943             :  *
   14944             :  * Be careful of productions involving more than one terminal token.
   14945             :  * By default, bison will assign such productions the precedence of their
   14946             :  * last terminal, but in nearly all cases you want it to be the precedence
   14947             :  * of the first terminal instead; otherwise you will not get the behavior
   14948             :  * you expect!  So we use %prec annotations freely to set precedences.
   14949             :  */
   14950     3720740 : a_expr:     c_expr                                  { $$ = $1; }
   14951             :             | a_expr TYPECAST Typename
   14952      221450 :                     { $$ = makeTypeCast($1, $3, @2); }
   14953             :             | a_expr COLLATE any_name
   14954             :                 {
   14955        8874 :                     CollateClause *n = makeNode(CollateClause);
   14956             : 
   14957        8874 :                     n->arg = $1;
   14958        8874 :                     n->collname = $3;
   14959        8874 :                     n->location = @2;
   14960        8874 :                     $$ = (Node *) n;
   14961             :                 }
   14962             :             | a_expr AT TIME ZONE a_expr            %prec AT
   14963             :                 {
   14964         408 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14965         408 :                                                list_make2($5, $1),
   14966             :                                                COERCE_SQL_SYNTAX,
   14967         408 :                                                @2);
   14968             :                 }
   14969             :             | a_expr AT LOCAL                       %prec AT
   14970             :                 {
   14971          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14972          42 :                                                list_make1($1),
   14973             :                                                COERCE_SQL_SYNTAX,
   14974             :                                                -1);
   14975             :                 }
   14976             :         /*
   14977             :          * These operators must be called out explicitly in order to make use
   14978             :          * of bison's automatic operator-precedence handling.  All other
   14979             :          * operator names are handled by the generic productions using "Op",
   14980             :          * below; and all those operators will have the same precedence.
   14981             :          *
   14982             :          * If you add more explicitly-known operators, be sure to add them
   14983             :          * also to b_expr and to the MathOp list below.
   14984             :          */
   14985             :             | '+' a_expr                    %prec UMINUS
   14986          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   14987             :             | '-' a_expr                    %prec UMINUS
   14988       27696 :                 { $$ = doNegate($2, @1); }
   14989             :             | a_expr '+' a_expr
   14990       14262 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   14991             :             | a_expr '-' a_expr
   14992        6226 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   14993             :             | a_expr '*' a_expr
   14994        6154 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   14995             :             | a_expr '/' a_expr
   14996        3382 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   14997             :             | a_expr '%' a_expr
   14998        2824 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   14999             :             | a_expr '^' a_expr
   15000         466 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15001             :             | a_expr '<' a_expr
   15002       23256 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15003             :             | a_expr '>' a_expr
   15004       33136 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15005             :             | a_expr '=' a_expr
   15006      379986 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15007             :             | a_expr LESS_EQUALS a_expr
   15008        4906 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15009             :             | a_expr GREATER_EQUALS a_expr
   15010        6898 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15011             :             | a_expr NOT_EQUALS a_expr
   15012       39146 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15013             : 
   15014             :             | a_expr qual_Op a_expr             %prec Op
   15015       57654 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15016             :             | qual_Op a_expr                    %prec Op
   15017         210 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15018             : 
   15019             :             | a_expr AND a_expr
   15020      220042 :                 { $$ = makeAndExpr($1, $3, @2); }
   15021             :             | a_expr OR a_expr
   15022       16598 :                 { $$ = makeOrExpr($1, $3, @2); }
   15023             :             | NOT a_expr
   15024       15084 :                 { $$ = makeNotExpr($2, @1); }
   15025             :             | NOT_LA a_expr                     %prec NOT
   15026           0 :                 { $$ = makeNotExpr($2, @1); }
   15027             : 
   15028             :             | a_expr LIKE a_expr
   15029             :                 {
   15030        1952 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15031        1952 :                                                    $1, $3, @2);
   15032             :                 }
   15033             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15034             :                 {
   15035          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15036          96 :                                                  list_make2($3, $5),
   15037             :                                                  COERCE_EXPLICIT_CALL,
   15038          96 :                                                  @2);
   15039          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15040          96 :                                                    $1, (Node *) n, @2);
   15041             :                 }
   15042             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15043             :                 {
   15044         198 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15045         198 :                                                    $1, $4, @2);
   15046             :                 }
   15047             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15048             :                 {
   15049          96 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15050          96 :                                                  list_make2($4, $6),
   15051             :                                                  COERCE_EXPLICIT_CALL,
   15052          96 :                                                  @2);
   15053          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15054          96 :                                                    $1, (Node *) n, @2);
   15055             :                 }
   15056             :             | a_expr ILIKE a_expr
   15057             :                 {
   15058         174 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15059         174 :                                                    $1, $3, @2);
   15060             :                 }
   15061             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15062             :                 {
   15063           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15064           0 :                                                  list_make2($3, $5),
   15065             :                                                  COERCE_EXPLICIT_CALL,
   15066           0 :                                                  @2);
   15067           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15068           0 :                                                    $1, (Node *) n, @2);
   15069             :                 }
   15070             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15071             :                 {
   15072          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15073          30 :                                                    $1, $4, @2);
   15074             :                 }
   15075             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15076             :                 {
   15077           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15078           0 :                                                  list_make2($4, $6),
   15079             :                                                  COERCE_EXPLICIT_CALL,
   15080           0 :                                                  @2);
   15081           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15082           0 :                                                    $1, (Node *) n, @2);
   15083             :                 }
   15084             : 
   15085             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15086             :                 {
   15087          40 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15088          40 :                                                  list_make1($4),
   15089             :                                                  COERCE_EXPLICIT_CALL,
   15090          40 :                                                  @2);
   15091          40 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15092          40 :                                                    $1, (Node *) n, @2);
   15093             :                 }
   15094             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15095             :                 {
   15096          30 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15097          30 :                                                  list_make2($4, $6),
   15098             :                                                  COERCE_EXPLICIT_CALL,
   15099          30 :                                                  @2);
   15100          30 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15101          30 :                                                    $1, (Node *) n, @2);
   15102             :                 }
   15103             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15104             :                 {
   15105           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15106           0 :                                                  list_make1($5),
   15107             :                                                  COERCE_EXPLICIT_CALL,
   15108           0 :                                                  @2);
   15109           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15110           0 :                                                    $1, (Node *) n, @2);
   15111             :                 }
   15112             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15113             :                 {
   15114           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15115           0 :                                                  list_make2($5, $7),
   15116             :                                                  COERCE_EXPLICIT_CALL,
   15117           0 :                                                  @2);
   15118           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15119           0 :                                                    $1, (Node *) n, @2);
   15120             :                 }
   15121             : 
   15122             :             /* NullTest clause
   15123             :              * Define SQL-style Null test clause.
   15124             :              * Allow two forms described in the standard:
   15125             :              *  a IS NULL
   15126             :              *  a IS NOT NULL
   15127             :              * Allow two SQL extensions
   15128             :              *  a ISNULL
   15129             :              *  a NOTNULL
   15130             :              */
   15131             :             | a_expr IS NULL_P                          %prec IS
   15132             :                 {
   15133        5064 :                     NullTest   *n = makeNode(NullTest);
   15134             : 
   15135        5064 :                     n->arg = (Expr *) $1;
   15136        5064 :                     n->nulltesttype = IS_NULL;
   15137        5064 :                     n->location = @2;
   15138        5064 :                     $$ = (Node *) n;
   15139             :                 }
   15140             :             | a_expr ISNULL
   15141             :                 {
   15142          96 :                     NullTest   *n = makeNode(NullTest);
   15143             : 
   15144          96 :                     n->arg = (Expr *) $1;
   15145          96 :                     n->nulltesttype = IS_NULL;
   15146          96 :                     n->location = @2;
   15147          96 :                     $$ = (Node *) n;
   15148             :                 }
   15149             :             | a_expr IS NOT NULL_P                      %prec IS
   15150             :                 {
   15151       12126 :                     NullTest   *n = makeNode(NullTest);
   15152             : 
   15153       12126 :                     n->arg = (Expr *) $1;
   15154       12126 :                     n->nulltesttype = IS_NOT_NULL;
   15155       12126 :                     n->location = @2;
   15156       12126 :                     $$ = (Node *) n;
   15157             :                 }
   15158             :             | a_expr NOTNULL
   15159             :                 {
   15160           6 :                     NullTest   *n = makeNode(NullTest);
   15161             : 
   15162           6 :                     n->arg = (Expr *) $1;
   15163           6 :                     n->nulltesttype = IS_NOT_NULL;
   15164           6 :                     n->location = @2;
   15165           6 :                     $$ = (Node *) n;
   15166             :                 }
   15167             :             | row OVERLAPS row
   15168             :                 {
   15169         876 :                     if (list_length($1) != 2)
   15170           0 :                         ereport(ERROR,
   15171             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15172             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15173             :                                  parser_errposition(@1)));
   15174         876 :                     if (list_length($3) != 2)
   15175           0 :                         ereport(ERROR,
   15176             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15177             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15178             :                                  parser_errposition(@3)));
   15179         876 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15180         876 :                                                list_concat($1, $3),
   15181             :                                                COERCE_SQL_SYNTAX,
   15182         876 :                                                @2);
   15183             :                 }
   15184             :             | a_expr IS TRUE_P                          %prec IS
   15185             :                 {
   15186         418 :                     BooleanTest *b = makeNode(BooleanTest);
   15187             : 
   15188         418 :                     b->arg = (Expr *) $1;
   15189         418 :                     b->booltesttype = IS_TRUE;
   15190         418 :                     b->location = @2;
   15191         418 :                     $$ = (Node *) b;
   15192             :                 }
   15193             :             | a_expr IS NOT TRUE_P                      %prec IS
   15194             :                 {
   15195         140 :                     BooleanTest *b = makeNode(BooleanTest);
   15196             : 
   15197         140 :                     b->arg = (Expr *) $1;
   15198         140 :                     b->booltesttype = IS_NOT_TRUE;
   15199         140 :                     b->location = @2;
   15200         140 :                     $$ = (Node *) b;
   15201             :                 }
   15202             :             | a_expr IS FALSE_P                         %prec IS
   15203             :                 {
   15204         136 :                     BooleanTest *b = makeNode(BooleanTest);
   15205             : 
   15206         136 :                     b->arg = (Expr *) $1;
   15207         136 :                     b->booltesttype = IS_FALSE;
   15208         136 :                     b->location = @2;
   15209         136 :                     $$ = (Node *) b;
   15210             :                 }
   15211             :             | a_expr IS NOT FALSE_P                     %prec IS
   15212             :                 {
   15213          92 :                     BooleanTest *b = makeNode(BooleanTest);
   15214             : 
   15215          92 :                     b->arg = (Expr *) $1;
   15216          92 :                     b->booltesttype = IS_NOT_FALSE;
   15217          92 :                     b->location = @2;
   15218          92 :                     $$ = (Node *) b;
   15219             :                 }
   15220             :             | a_expr IS UNKNOWN                         %prec IS
   15221             :                 {
   15222          52 :                     BooleanTest *b = makeNode(BooleanTest);
   15223             : 
   15224          52 :                     b->arg = (Expr *) $1;
   15225          52 :                     b->booltesttype = IS_UNKNOWN;
   15226          52 :                     b->location = @2;
   15227          52 :                     $$ = (Node *) b;
   15228             :                 }
   15229             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15230             :                 {
   15231          48 :                     BooleanTest *b = makeNode(BooleanTest);
   15232             : 
   15233          48 :                     b->arg = (Expr *) $1;
   15234          48 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15235          48 :                     b->location = @2;
   15236          48 :                     $$ = (Node *) b;
   15237             :                 }
   15238             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15239             :                 {
   15240        1056 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15241             :                 }
   15242             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15243             :                 {
   15244          68 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15245             :                 }
   15246             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15247             :                 {
   15248         466 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15249             :                                                    "BETWEEN",
   15250         466 :                                                    $1,
   15251         466 :                                                    (Node *) list_make2($4, $6),
   15252         466 :                                                    @2);
   15253             :                 }
   15254             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15255             :                 {
   15256          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15257             :                                                    "NOT BETWEEN",
   15258          12 :                                                    $1,
   15259          12 :                                                    (Node *) list_make2($5, $7),
   15260          12 :                                                    @2);
   15261             :                 }
   15262             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15263             :                 {
   15264          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15265             :                                                    "BETWEEN SYMMETRIC",
   15266          12 :                                                    $1,
   15267          12 :                                                    (Node *) list_make2($4, $6),
   15268          12 :                                                    @2);
   15269             :                 }
   15270             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15271             :                 {
   15272          12 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15273             :                                                    "NOT BETWEEN SYMMETRIC",
   15274          12 :                                                    $1,
   15275          12 :                                                    (Node *) list_make2($5, $7),
   15276          12 :                                                    @2);
   15277             :                 }
   15278             :             | a_expr IN_P in_expr
   15279             :                 {
   15280             :                     /* in_expr returns a SubLink or a list of a_exprs */
   15281       19912 :                     if (IsA($3, SubLink))
   15282             :                     {
   15283             :                         /* generate foo = ANY (subquery) */
   15284        2618 :                         SubLink    *n = (SubLink *) $3;
   15285             : 
   15286        2618 :                         n->subLinkType = ANY_SUBLINK;
   15287        2618 :                         n->subLinkId = 0;
   15288        2618 :                         n->testexpr = $1;
   15289        2618 :                         n->operName = NIL;       /* show it's IN not = ANY */
   15290        2618 :                         n->location = @2;
   15291        2618 :                         $$ = (Node *) n;
   15292             :                     }
   15293             :                     else
   15294             :                     {
   15295             :                         /* generate scalar IN expression */
   15296       17294 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
   15297             :                     }
   15298             :                 }
   15299             :             | a_expr NOT_LA IN_P in_expr                        %prec NOT_LA
   15300             :                 {
   15301             :                     /* in_expr returns a SubLink or a list of a_exprs */
   15302        5262 :                     if (IsA($4, SubLink))
   15303             :                     {
   15304             :                         /* generate NOT (foo = ANY (subquery)) */
   15305             :                         /* Make an = ANY node */
   15306         120 :                         SubLink    *n = (SubLink *) $4;
   15307             : 
   15308         120 :                         n->subLinkType = ANY_SUBLINK;
   15309         120 :                         n->subLinkId = 0;
   15310         120 :                         n->testexpr = $1;
   15311         120 :                         n->operName = NIL;       /* show it's IN not = ANY */
   15312         120 :                         n->location = @2;
   15313             :                         /* Stick a NOT on top; must have same parse location */
   15314         120 :                         $$ = makeNotExpr((Node *) n, @2);
   15315             :                     }
   15316             :                     else
   15317             :                     {
   15318             :                         /* generate scalar NOT IN expression */
   15319        5142 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
   15320             :                     }
   15321             :                 }
   15322             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15323             :                 {
   15324         168 :                     SubLink    *n = makeNode(SubLink);
   15325             : 
   15326         168 :                     n->subLinkType = $3;
   15327         168 :                     n->subLinkId = 0;
   15328         168 :                     n->testexpr = $1;
   15329         168 :                     n->operName = $2;
   15330         168 :                     n->subselect = $4;
   15331         168 :                     n->location = @2;
   15332         168 :                     $$ = (Node *) n;
   15333             :                 }
   15334             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15335             :                 {
   15336       16340 :                     if ($3 == ANY_SUBLINK)
   15337       16040 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15338             :                     else
   15339         300 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15340             :                 }
   15341             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15342             :                 {
   15343             :                     /* Not sure how to get rid of the parentheses
   15344             :                      * but there are lots of shift/reduce errors without them.
   15345             :                      *
   15346             :                      * Should be able to implement this by plopping the entire
   15347             :                      * select into a node, then transforming the target expressions
   15348             :                      * from whatever they are into count(*), and testing the
   15349             :                      * entire result equal to one.
   15350             :                      * But, will probably implement a separate node in the executor.
   15351             :                      */
   15352           0 :                     ereport(ERROR,
   15353             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15354             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15355             :                              parser_errposition(@1)));
   15356             :                 }
   15357             :             | a_expr IS DOCUMENT_P                  %prec IS
   15358             :                 {
   15359          18 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15360          18 :                                      list_make1($1), @2);
   15361             :                 }
   15362             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15363             :                 {
   15364          18 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15365          18 :                                                  list_make1($1), @2),
   15366          18 :                                      @2);
   15367             :                 }
   15368             :             | a_expr IS NORMALIZED                              %prec IS
   15369             :                 {
   15370          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15371          12 :                                                list_make1($1),
   15372             :                                                COERCE_SQL_SYNTAX,
   15373          12 :                                                @2);
   15374             :                 }
   15375             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15376             :                 {
   15377          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15378          36 :                                                list_make2($1, makeStringConst($3, @3)),
   15379             :                                                COERCE_SQL_SYNTAX,
   15380          36 :                                                @2);
   15381             :                 }
   15382             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15383             :                 {
   15384           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15385           0 :                                                            list_make1($1),
   15386             :                                                            COERCE_SQL_SYNTAX,
   15387           0 :                                                            @2),
   15388           0 :                                      @2);
   15389             :                 }
   15390             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15391             :                 {
   15392           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15393           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15394             :                                                            COERCE_SQL_SYNTAX,
   15395           0 :                                                            @2),
   15396           0 :                                      @2);
   15397             :                 }
   15398             :             | a_expr IS json_predicate_type_constraint
   15399             :                     json_key_uniqueness_constraint_opt      %prec IS
   15400             :                 {
   15401         304 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15402             : 
   15403         304 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   15404             :                 }
   15405             :             /*
   15406             :              * Required by SQL/JSON, but there are conflicts
   15407             :             | a_expr
   15408             :                 json_format_clause
   15409             :                 IS  json_predicate_type_constraint
   15410             :                     json_key_uniqueness_constraint_opt      %prec IS
   15411             :                 {
   15412             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, @1);
   15413             :                 }
   15414             :             */
   15415             :             | a_expr IS NOT
   15416             :                     json_predicate_type_constraint
   15417             :                     json_key_uniqueness_constraint_opt      %prec IS
   15418             :                 {
   15419          46 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15420             : 
   15421          46 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   15422             :                 }
   15423             :             /*
   15424             :              * Required by SQL/JSON, but there are conflicts
   15425             :             | a_expr
   15426             :                 json_format_clause
   15427             :                 IS NOT
   15428             :                     json_predicate_type_constraint
   15429             :                     json_key_uniqueness_constraint_opt      %prec IS
   15430             :                 {
   15431             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, @1), @1);
   15432             :                 }
   15433             :             */
   15434             :             | DEFAULT
   15435             :                 {
   15436             :                     /*
   15437             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15438             :                      * expressions", but for us, it's easier to allow it in
   15439             :                      * any a_expr and then throw error during parse analysis
   15440             :                      * if it's in an inappropriate context.  This way also
   15441             :                      * lets us say something smarter than "syntax error".
   15442             :                      */
   15443        1552 :                     SetToDefault *n = makeNode(SetToDefault);
   15444             : 
   15445             :                     /* parse analysis will fill in the rest */
   15446        1552 :                     n->location = @1;
   15447        1552 :                     $$ = (Node *) n;
   15448             :                 }
   15449             :         ;
   15450             : 
   15451             : /*
   15452             :  * Restricted expressions
   15453             :  *
   15454             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15455             :  *
   15456             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15457             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15458             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15459             :  */
   15460             : b_expr:     c_expr
   15461        3710 :                 { $$ = $1; }
   15462             :             | b_expr TYPECAST Typename
   15463         200 :                 { $$ = makeTypeCast($1, $3, @2); }
   15464             :             | '+' b_expr                    %prec UMINUS
   15465           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15466             :             | '-' b_expr                    %prec UMINUS
   15467          66 :                 { $$ = doNegate($2, @1); }
   15468             :             | b_expr '+' b_expr
   15469          36 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15470             :             | b_expr '-' b_expr
   15471          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15472             :             | b_expr '*' b_expr
   15473          12 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15474             :             | b_expr '/' b_expr
   15475           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15476             :             | b_expr '%' b_expr
   15477           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15478             :             | b_expr '^' b_expr
   15479           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15480             :             | b_expr '<' b_expr
   15481           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15482             :             | b_expr '>' b_expr
   15483           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15484             :             | b_expr '=' b_expr
   15485           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15486             :             | b_expr LESS_EQUALS b_expr
   15487           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15488             :             | b_expr GREATER_EQUALS b_expr
   15489           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15490             :             | b_expr NOT_EQUALS b_expr
   15491           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15492             :             | b_expr qual_Op b_expr             %prec Op
   15493          12 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15494             :             | qual_Op b_expr                    %prec Op
   15495           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15496             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15497             :                 {
   15498           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15499             :                 }
   15500             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15501             :                 {
   15502           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15503             :                 }
   15504             :             | b_expr IS DOCUMENT_P                  %prec IS
   15505             :                 {
   15506           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15507           0 :                                      list_make1($1), @2);
   15508             :                 }
   15509             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15510             :                 {
   15511           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15512           0 :                                                  list_make1($1), @2),
   15513           0 :                                      @2);
   15514             :                 }
   15515             :         ;
   15516             : 
   15517             : /*
   15518             :  * Productions that can be used in both a_expr and b_expr.
   15519             :  *
   15520             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15521             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15522             :  * inside parentheses, such as function arguments; that cannot introduce
   15523             :  * ambiguity to the b_expr syntax.
   15524             :  */
   15525     1706698 : c_expr:     columnref                               { $$ = $1; }
   15526     1281106 :             | AexprConst                            { $$ = $1; }
   15527             :             | PARAM opt_indirection
   15528             :                 {
   15529      145906 :                     ParamRef   *p = makeNode(ParamRef);
   15530             : 
   15531      145906 :                     p->number = $1;
   15532      145906 :                     p->location = @1;
   15533      145906 :                     if ($2)
   15534             :                     {
   15535        1198 :                         A_Indirection *n = makeNode(A_Indirection);
   15536             : 
   15537        1198 :                         n->arg = (Node *) p;
   15538        1198 :                         n->indirection = check_indirection($2, yyscanner);
   15539        1198 :                         $$ = (Node *) n;
   15540             :                     }
   15541             :                     else
   15542      144708 :                         $$ = (Node *) p;
   15543             :                 }
   15544             :             | '(' a_expr ')' opt_indirection
   15545             :                 {
   15546       88206 :                     if ($4)
   15547             :                     {
   15548       11146 :                         A_Indirection *n = makeNode(A_Indirection);
   15549             : 
   15550       11146 :                         n->arg = $2;
   15551       11146 :                         n->indirection = check_indirection($4, yyscanner);
   15552       11146 :                         $$ = (Node *) n;
   15553             :                     }
   15554             :                     else
   15555       77060 :                         $$ = $2;
   15556             :                 }
   15557             :             | case_expr
   15558       56832 :                 { $$ = $1; }
   15559             :             | func_expr
   15560      391602 :                 { $$ = $1; }
   15561             :             | select_with_parens            %prec UMINUS
   15562             :                 {
   15563       26632 :                     SubLink    *n = makeNode(SubLink);
   15564             : 
   15565       26632 :                     n->subLinkType = EXPR_SUBLINK;
   15566       26632 :                     n->subLinkId = 0;
   15567       26632 :                     n->testexpr = NULL;
   15568       26632 :                     n->operName = NIL;
   15569       26632 :                     n->subselect = $1;
   15570       26632 :                     n->location = @1;
   15571       26632 :                     $$ = (Node *) n;
   15572             :                 }
   15573             :             | select_with_parens indirection
   15574             :                 {
   15575             :                     /*
   15576             :                      * Because the select_with_parens nonterminal is designed
   15577             :                      * to "eat" as many levels of parens as possible, the
   15578             :                      * '(' a_expr ')' opt_indirection production above will
   15579             :                      * fail to match a sub-SELECT with indirection decoration;
   15580             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15581             :                      * as there are parens around it.  To support applying
   15582             :                      * subscripting or field selection to a sub-SELECT result,
   15583             :                      * we need this redundant-looking production.
   15584             :                      */
   15585          18 :                     SubLink    *n = makeNode(SubLink);
   15586          18 :                     A_Indirection *a = makeNode(A_Indirection);
   15587             : 
   15588          18 :                     n->subLinkType = EXPR_SUBLINK;
   15589          18 :                     n->subLinkId = 0;
   15590          18 :                     n->testexpr = NULL;
   15591          18 :                     n->operName = NIL;
   15592          18 :                     n->subselect = $1;
   15593          18 :                     n->location = @1;
   15594          18 :                     a->arg = (Node *) n;
   15595          18 :                     a->indirection = check_indirection($2, yyscanner);
   15596          18 :                     $$ = (Node *) a;
   15597             :                 }
   15598             :             | EXISTS select_with_parens
   15599             :                 {
   15600        5892 :                     SubLink    *n = makeNode(SubLink);
   15601             : 
   15602        5892 :                     n->subLinkType = EXISTS_SUBLINK;
   15603        5892 :                     n->subLinkId = 0;
   15604        5892 :                     n->testexpr = NULL;
   15605        5892 :                     n->operName = NIL;
   15606        5892 :                     n->subselect = $2;
   15607        5892 :                     n->location = @1;
   15608        5892 :                     $$ = (Node *) n;
   15609             :                 }
   15610             :             | ARRAY select_with_parens
   15611             :                 {
   15612        8224 :                     SubLink    *n = makeNode(SubLink);
   15613             : 
   15614        8224 :                     n->subLinkType = ARRAY_SUBLINK;
   15615        8224 :                     n->subLinkId = 0;
   15616        8224 :                     n->testexpr = NULL;
   15617        8224 :                     n->operName = NIL;
   15618        8224 :                     n->subselect = $2;
   15619        8224 :                     n->location = @1;
   15620        8224 :                     $$ = (Node *) n;
   15621             :                 }
   15622             :             | ARRAY array_expr
   15623             :                 {
   15624        7288 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15625             : 
   15626             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15627        7288 :                     n->location = @1;
   15628        7288 :                     $$ = (Node *) n;
   15629             :                 }
   15630             :             | explicit_row
   15631             :                 {
   15632        3900 :                     RowExpr    *r = makeNode(RowExpr);
   15633             : 
   15634        3900 :                     r->args = $1;
   15635        3900 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15636        3900 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15637        3900 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15638        3900 :                     r->location = @1;
   15639        3900 :                     $$ = (Node *) r;
   15640             :                 }
   15641             :             | implicit_row
   15642             :                 {
   15643        2438 :                     RowExpr    *r = makeNode(RowExpr);
   15644             : 
   15645        2438 :                     r->args = $1;
   15646        2438 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15647        2438 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15648        2438 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15649        2438 :                     r->location = @1;
   15650        2438 :                     $$ = (Node *) r;
   15651             :                 }
   15652             :             | GROUPING '(' expr_list ')'
   15653             :               {
   15654         362 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15655             : 
   15656         362 :                   g->args = $3;
   15657         362 :                   g->location = @1;
   15658         362 :                   $$ = (Node *) g;
   15659             :               }
   15660             :         ;
   15661             : 
   15662             : func_application: func_name '(' ')'
   15663             :                 {
   15664       45208 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15665             :                                                COERCE_EXPLICIT_CALL,
   15666       45208 :                                                @1);
   15667             :                 }
   15668             :             | func_name '(' func_arg_list opt_sort_clause ')'
   15669             :                 {
   15670      311558 :                     FuncCall   *n = makeFuncCall($1, $3,
   15671             :                                                  COERCE_EXPLICIT_CALL,
   15672      311558 :                                                  @1);
   15673             : 
   15674      311558 :                     n->agg_order = $4;
   15675      311558 :                     $$ = (Node *) n;
   15676             :                 }
   15677             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15678             :                 {
   15679         612 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15680             :                                                  COERCE_EXPLICIT_CALL,
   15681         612 :                                                  @1);
   15682             : 
   15683         612 :                     n->func_variadic = true;
   15684         612 :                     n->agg_order = $5;
   15685         612 :                     $$ = (Node *) n;
   15686             :                 }
   15687             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15688             :                 {
   15689         120 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15690             :                                                  COERCE_EXPLICIT_CALL,
   15691         120 :                                                  @1);
   15692             : 
   15693         120 :                     n->func_variadic = true;
   15694         120 :                     n->agg_order = $7;
   15695         120 :                     $$ = (Node *) n;
   15696             :                 }
   15697             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15698             :                 {
   15699           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15700             :                                                  COERCE_EXPLICIT_CALL,
   15701           0 :                                                  @1);
   15702             : 
   15703           0 :                     n->agg_order = $5;
   15704             :                     /* Ideally we'd mark the FuncCall node to indicate
   15705             :                      * "must be an aggregate", but there's no provision
   15706             :                      * for that in FuncCall at the moment.
   15707             :                      */
   15708           0 :                     $$ = (Node *) n;
   15709             :                 }
   15710             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15711             :                 {
   15712         538 :                     FuncCall   *n = makeFuncCall($1, $4,
   15713             :                                                  COERCE_EXPLICIT_CALL,
   15714         538 :                                                  @1);
   15715             : 
   15716         538 :                     n->agg_order = $5;
   15717         538 :                     n->agg_distinct = true;
   15718         538 :                     $$ = (Node *) n;
   15719             :                 }
   15720             :             | func_name '(' '*' ')'
   15721             :                 {
   15722             :                     /*
   15723             :                      * We consider AGGREGATE(*) to invoke a parameterless
   15724             :                      * aggregate.  This does the right thing for COUNT(*),
   15725             :                      * and there are no other aggregates in SQL that accept
   15726             :                      * '*' as parameter.
   15727             :                      *
   15728             :                      * The FuncCall node is also marked agg_star = true,
   15729             :                      * so that later processing can detect what the argument
   15730             :                      * really was.
   15731             :                      */
   15732       12388 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15733             :                                                  COERCE_EXPLICIT_CALL,
   15734       12388 :                                                  @1);
   15735             : 
   15736       12388 :                     n->agg_star = true;
   15737       12388 :                     $$ = (Node *) n;
   15738             :                 }
   15739             :         ;
   15740             : 
   15741             : 
   15742             : /*
   15743             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15744             :  * so that we have classifications for "everything that is a function call or
   15745             :  * looks like one".  This isn't very important, but it saves us having to
   15746             :  * document which variants are legal in places like "FROM function()" or the
   15747             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15748             :  * (Note that many of the special SQL functions wouldn't actually make any
   15749             :  * sense as functional index entries, but we ignore that consideration here.)
   15750             :  */
   15751             : func_expr: func_application within_group_clause filter_clause over_clause
   15752             :                 {
   15753      321608 :                     FuncCall   *n = (FuncCall *) $1;
   15754             : 
   15755             :                     /*
   15756             :                      * The order clause for WITHIN GROUP and the one for
   15757             :                      * plain-aggregate ORDER BY share a field, so we have to
   15758             :                      * check here that at most one is present.  We also check
   15759             :                      * for DISTINCT and VARIADIC here to give a better error
   15760             :                      * location.  Other consistency checks are deferred to
   15761             :                      * parse analysis.
   15762             :                      */
   15763      321608 :                     if ($2 != NIL)
   15764             :                     {
   15765         348 :                         if (n->agg_order != NIL)
   15766           6 :                             ereport(ERROR,
   15767             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15768             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15769             :                                      parser_errposition(@2)));
   15770         342 :                         if (n->agg_distinct)
   15771           0 :                             ereport(ERROR,
   15772             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15773             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15774             :                                      parser_errposition(@2)));
   15775         342 :                         if (n->func_variadic)
   15776           0 :                             ereport(ERROR,
   15777             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15778             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15779             :                                      parser_errposition(@2)));
   15780         342 :                         n->agg_order = $2;
   15781         342 :                         n->agg_within_group = true;
   15782             :                     }
   15783      321602 :                     n->agg_filter = $3;
   15784      321602 :                     n->over = $4;
   15785      321602 :                     $$ = (Node *) n;
   15786             :                 }
   15787             :             | json_aggregate_func filter_clause over_clause
   15788             :                 {
   15789         720 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15790         360 :                         ((JsonObjectAgg *) $1)->constructor :
   15791         156 :                         ((JsonArrayAgg *) $1)->constructor;
   15792             : 
   15793         360 :                     n->agg_filter = $2;
   15794         360 :                     n->over = $3;
   15795         360 :                     $$ = (Node *) $1;
   15796             :                 }
   15797             :             | func_expr_common_subexpr
   15798       69640 :                 { $$ = $1; }
   15799             :         ;
   15800             : 
   15801             : /*
   15802             :  * Like func_expr but does not accept WINDOW functions directly
   15803             :  * (but they can still be contained in arguments for functions etc).
   15804             :  * Use this when window expressions are not allowed, where needed to
   15805             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15806             :  */
   15807             : func_expr_windowless:
   15808       48196 :             func_application                        { $$ = $1; }
   15809         402 :             | func_expr_common_subexpr              { $$ = $1; }
   15810           0 :             | json_aggregate_func                   { $$ = $1; }
   15811             :         ;
   15812             : 
   15813             : /*
   15814             :  * Special expressions that are considered to be functions.
   15815             :  */
   15816             : func_expr_common_subexpr:
   15817             :             COLLATION FOR '(' a_expr ')'
   15818             :                 {
   15819          30 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15820          30 :                                                list_make1($4),
   15821             :                                                COERCE_SQL_SYNTAX,
   15822          30 :                                                @1);
   15823             :                 }
   15824             :             | CURRENT_DATE
   15825             :                 {
   15826         288 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   15827             :                 }
   15828             :             | CURRENT_TIME
   15829             :                 {
   15830          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   15831             :                 }
   15832             :             | CURRENT_TIME '(' Iconst ')'
   15833             :                 {
   15834          24 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   15835             :                 }
   15836             :             | CURRENT_TIMESTAMP
   15837             :                 {
   15838         288 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   15839             :                 }
   15840             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15841             :                 {
   15842         164 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   15843             :                 }
   15844             :             | LOCALTIME
   15845             :                 {
   15846          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   15847             :                 }
   15848             :             | LOCALTIME '(' Iconst ')'
   15849             :                 {
   15850          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   15851             :                 }
   15852             :             | LOCALTIMESTAMP
   15853             :                 {
   15854          36 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   15855             :                 }
   15856             :             | LOCALTIMESTAMP '(' Iconst ')'
   15857             :                 {
   15858          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   15859             :                 }
   15860             :             | CURRENT_ROLE
   15861             :                 {
   15862         116 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   15863             :                 }
   15864             :             | CURRENT_USER
   15865             :                 {
   15866        1062 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   15867             :                 }
   15868             :             | SESSION_USER
   15869             :                 {
   15870         620 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   15871             :                 }
   15872             :             | SYSTEM_USER
   15873             :                 {
   15874          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15875             :                                                NIL,
   15876             :                                                COERCE_SQL_SYNTAX,
   15877             :                                                @1);
   15878             :                 }
   15879             :             | USER
   15880             :                 {
   15881          24 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   15882             :                 }
   15883             :             | CURRENT_CATALOG
   15884             :                 {
   15885          52 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   15886             :                 }
   15887             :             | CURRENT_SCHEMA
   15888             :                 {
   15889          30 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   15890             :                 }
   15891             :             | CAST '(' a_expr AS Typename ')'
   15892       56042 :                 { $$ = makeTypeCast($3, $5, @1); }
   15893             :             | EXTRACT '(' extract_list ')'
   15894             :                 {
   15895        1342 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15896        1342 :                                                $3,
   15897             :                                                COERCE_SQL_SYNTAX,
   15898        1342 :                                                @1);
   15899             :                 }
   15900             :             | NORMALIZE '(' a_expr ')'
   15901             :                 {
   15902          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15903          18 :                                                list_make1($3),
   15904             :                                                COERCE_SQL_SYNTAX,
   15905          18 :                                                @1);
   15906             :                 }
   15907             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   15908             :                 {
   15909          42 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15910          42 :                                                list_make2($3, makeStringConst($5, @5)),
   15911             :                                                COERCE_SQL_SYNTAX,
   15912          42 :                                                @1);
   15913             :                 }
   15914             :             | OVERLAY '(' overlay_list ')'
   15915             :                 {
   15916          82 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   15917          82 :                                                $3,
   15918             :                                                COERCE_SQL_SYNTAX,
   15919          82 :                                                @1);
   15920             :                 }
   15921             :             | OVERLAY '(' func_arg_list_opt ')'
   15922             :                 {
   15923             :                     /*
   15924             :                      * allow functions named overlay() to be called without
   15925             :                      * special syntax
   15926             :                      */
   15927           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   15928           0 :                                                $3,
   15929             :                                                COERCE_EXPLICIT_CALL,
   15930           0 :                                                @1);
   15931             :                 }
   15932             :             | POSITION '(' position_list ')'
   15933             :                 {
   15934             :                     /*
   15935             :                      * position(A in B) is converted to position(B, A)
   15936             :                      *
   15937             :                      * We deliberately don't offer a "plain syntax" option
   15938             :                      * for position(), because the reversal of the arguments
   15939             :                      * creates too much risk of confusion.
   15940             :                      */
   15941         390 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   15942         390 :                                                $3,
   15943             :                                                COERCE_SQL_SYNTAX,
   15944         390 :                                                @1);
   15945             :                 }
   15946             :             | SUBSTRING '(' substr_list ')'
   15947             :                 {
   15948             :                     /* substring(A from B for C) is converted to
   15949             :                      * substring(A, B, C) - thomas 2000-11-28
   15950             :                      */
   15951         670 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   15952         670 :                                                $3,
   15953             :                                                COERCE_SQL_SYNTAX,
   15954         670 :                                                @1);
   15955             :                 }
   15956             :             | SUBSTRING '(' func_arg_list_opt ')'
   15957             :                 {
   15958             :                     /*
   15959             :                      * allow functions named substring() to be called without
   15960             :                      * special syntax
   15961             :                      */
   15962         198 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   15963         198 :                                                $3,
   15964             :                                                COERCE_EXPLICIT_CALL,
   15965         198 :                                                @1);
   15966             :                 }
   15967             :             | TREAT '(' a_expr AS Typename ')'
   15968             :                 {
   15969             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   15970             :                      * which is defined to be a subtype of the original expression.
   15971             :                      * In SQL99, this is intended for use with structured UDTs,
   15972             :                      * but let's make this a generally useful form allowing stronger
   15973             :                      * coercions than are handled by implicit casting.
   15974             :                      *
   15975             :                      * Convert SystemTypeName() to SystemFuncName() even though
   15976             :                      * at the moment they result in the same thing.
   15977             :                      */
   15978           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   15979           0 :                                                list_make1($3),
   15980             :                                                COERCE_EXPLICIT_CALL,
   15981           0 :                                                @1);
   15982             :                 }
   15983             :             | TRIM '(' BOTH trim_list ')'
   15984             :                 {
   15985             :                     /* various trim expressions are defined in SQL
   15986             :                      * - thomas 1997-07-19
   15987             :                      */
   15988          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15989          12 :                                                $4,
   15990             :                                                COERCE_SQL_SYNTAX,
   15991          12 :                                                @1);
   15992             :                 }
   15993             :             | TRIM '(' LEADING trim_list ')'
   15994             :                 {
   15995          24 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   15996          24 :                                                $4,
   15997             :                                                COERCE_SQL_SYNTAX,
   15998          24 :                                                @1);
   15999             :                 }
   16000             :             | TRIM '(' TRAILING trim_list ')'
   16001             :                 {
   16002         564 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   16003         564 :                                                $4,
   16004             :                                                COERCE_SQL_SYNTAX,
   16005         564 :                                                @1);
   16006             :                 }
   16007             :             | TRIM '(' trim_list ')'
   16008             :                 {
   16009          98 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16010          98 :                                                $3,
   16011             :                                                COERCE_SQL_SYNTAX,
   16012          98 :                                                @1);
   16013             :                 }
   16014             :             | NULLIF '(' a_expr ',' a_expr ')'
   16015             :                 {
   16016         376 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   16017             :                 }
   16018             :             | COALESCE '(' expr_list ')'
   16019             :                 {
   16020        3126 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   16021             : 
   16022        3126 :                     c->args = $3;
   16023        3126 :                     c->location = @1;
   16024        3126 :                     $$ = (Node *) c;
   16025             :                 }
   16026             :             | GREATEST '(' expr_list ')'
   16027             :                 {
   16028         140 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16029             : 
   16030         140 :                     v->args = $3;
   16031         140 :                     v->op = IS_GREATEST;
   16032         140 :                     v->location = @1;
   16033         140 :                     $$ = (Node *) v;
   16034             :                 }
   16035             :             | LEAST '(' expr_list ')'
   16036             :                 {
   16037         142 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16038             : 
   16039         142 :                     v->args = $3;
   16040         142 :                     v->op = IS_LEAST;
   16041         142 :                     v->location = @1;
   16042         142 :                     $$ = (Node *) v;
   16043             :                 }
   16044             :             | XMLCONCAT '(' expr_list ')'
   16045             :                 {
   16046          62 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16047             :                 }
   16048             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16049             :                 {
   16050           6 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16051             :                 }
   16052             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16053             :                 {
   16054          36 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16055             :                 }
   16056             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16057             :                 {
   16058         116 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16059             :                 }
   16060             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16061             :                 {
   16062          20 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16063             :                 }
   16064             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16065             :                 {
   16066             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16067             :                      * converted to xmlexists(A, B)*/
   16068          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16069          54 :                                                list_make2($3, $4),
   16070             :                                                COERCE_SQL_SYNTAX,
   16071          54 :                                                @1);
   16072             :                 }
   16073             :             | XMLFOREST '(' xml_attribute_list ')'
   16074             :                 {
   16075          32 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16076             :                 }
   16077             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16078             :                 {
   16079             :                     XmlExpr *x = (XmlExpr *)
   16080         140 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16081         140 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16082         140 :                                     @1);
   16083             : 
   16084         140 :                     x->xmloption = $3;
   16085         140 :                     $$ = (Node *) x;
   16086             :                 }
   16087             :             | XMLPI '(' NAME_P ColLabel ')'
   16088             :                 {
   16089          30 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16090             :                 }
   16091             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16092             :                 {
   16093          50 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16094             :                 }
   16095             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16096             :                 {
   16097          68 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16098          68 :                                      list_make3($3, $5, $6), @1);
   16099             :                 }
   16100             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16101             :                 {
   16102         218 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16103             : 
   16104         218 :                     n->xmloption = $3;
   16105         218 :                     n->expr = $4;
   16106         218 :                     n->typeName = $6;
   16107         218 :                     n->indent = $7;
   16108         218 :                     n->location = @1;
   16109         218 :                     $$ = (Node *) n;
   16110             :                 }
   16111             :             | JSON_OBJECT '(' func_arg_list ')'
   16112             :                 {
   16113             :                     /* Support for legacy (non-standard) json_object() */
   16114          90 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16115          90 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16116             :                 }
   16117             :             | JSON_OBJECT '(' json_name_and_value_list
   16118             :                 json_object_constructor_null_clause_opt
   16119             :                 json_key_uniqueness_constraint_opt
   16120             :                 json_returning_clause_opt ')'
   16121             :                 {
   16122         348 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16123             : 
   16124         348 :                     n->exprs = $3;
   16125         348 :                     n->absent_on_null = $4;
   16126         348 :                     n->unique = $5;
   16127         348 :                     n->output = (JsonOutput *) $6;
   16128         348 :                     n->location = @1;
   16129         348 :                     $$ = (Node *) n;
   16130             :                 }
   16131             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16132             :                 {
   16133          92 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16134             : 
   16135          92 :                     n->exprs = NULL;
   16136          92 :                     n->absent_on_null = false;
   16137          92 :                     n->unique = false;
   16138          92 :                     n->output = (JsonOutput *) $3;
   16139          92 :                     n->location = @1;
   16140          92 :                     $$ = (Node *) n;
   16141             :                 }
   16142             :             | JSON_ARRAY '('
   16143             :                 json_value_expr_list
   16144             :                 json_array_constructor_null_clause_opt
   16145             :                 json_returning_clause_opt
   16146             :             ')'
   16147             :                 {
   16148         108 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16149             : 
   16150         108 :                     n->exprs = $3;
   16151         108 :                     n->absent_on_null = $4;
   16152         108 :                     n->output = (JsonOutput *) $5;
   16153         108 :                     n->location = @1;
   16154         108 :                     $$ = (Node *) n;
   16155             :                 }
   16156             :             | JSON_ARRAY '('
   16157             :                 select_no_parens
   16158             :                 json_format_clause_opt
   16159             :                 /* json_array_constructor_null_clause_opt */
   16160             :                 json_returning_clause_opt
   16161             :             ')'
   16162             :                 {
   16163          54 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16164             : 
   16165          54 :                     n->query = $3;
   16166          54 :                     n->format = (JsonFormat *) $4;
   16167          54 :                     n->absent_on_null = true;    /* XXX */
   16168          54 :                     n->output = (JsonOutput *) $5;
   16169          54 :                     n->location = @1;
   16170          54 :                     $$ = (Node *) n;
   16171             :                 }
   16172             :             | JSON_ARRAY '('
   16173             :                 json_returning_clause_opt
   16174             :             ')'
   16175             :                 {
   16176          86 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16177             : 
   16178          86 :                     n->exprs = NIL;
   16179          86 :                     n->absent_on_null = true;
   16180          86 :                     n->output = (JsonOutput *) $3;
   16181          86 :                     n->location = @1;
   16182          86 :                     $$ = (Node *) n;
   16183             :                 }
   16184             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16185             :                 {
   16186         164 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16187             : 
   16188         164 :                     n->expr = (JsonValueExpr *) $3;
   16189         164 :                     n->unique_keys = $4;
   16190         164 :                     n->output = NULL;
   16191         164 :                     n->location = @1;
   16192         164 :                     $$ = (Node *) n;
   16193             :                 }
   16194             :             | JSON_SCALAR '(' a_expr ')'
   16195             :                 {
   16196         112 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16197             : 
   16198         112 :                     n->expr = (Expr *) $3;
   16199         112 :                     n->output = NULL;
   16200         112 :                     n->location = @1;
   16201         112 :                     $$ = (Node *) n;
   16202             :                 }
   16203             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16204             :                 {
   16205         108 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16206             : 
   16207         108 :                     n->expr = (JsonValueExpr *) $3;
   16208         108 :                     n->output = (JsonOutput *) $4;
   16209         108 :                     n->location = @1;
   16210         108 :                     $$ = (Node *) n;
   16211             :                 }
   16212             :             | MERGE_ACTION '(' ')'
   16213             :                 {
   16214         204 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16215             : 
   16216         204 :                     m->msftype = TEXTOID;
   16217         204 :                     m->location = @1;
   16218         204 :                     $$ = (Node *) m;
   16219             :                 }
   16220             :             | JSON_QUERY '('
   16221             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16222             :                 json_returning_clause_opt
   16223             :                 json_wrapper_behavior
   16224             :                 json_quotes_clause_opt
   16225             :                 json_behavior_clause_opt
   16226             :             ')'
   16227             :                 {
   16228         984 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16229             : 
   16230         984 :                     n->op = JSON_QUERY_OP;
   16231         984 :                     n->context_item = (JsonValueExpr *) $3;
   16232         984 :                     n->pathspec = $5;
   16233         984 :                     n->passing = $6;
   16234         984 :                     n->output = (JsonOutput *) $7;
   16235         984 :                     n->wrapper = $8;
   16236         984 :                     n->quotes = $9;
   16237         984 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16238         984 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16239         984 :                     n->location = @1;
   16240         984 :                     $$ = (Node *) n;
   16241             :                 }
   16242             :             | JSON_EXISTS '('
   16243             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16244             :                 json_on_error_clause_opt
   16245             :             ')'
   16246             :                 {
   16247         168 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16248             : 
   16249         168 :                     n->op = JSON_EXISTS_OP;
   16250         168 :                     n->context_item = (JsonValueExpr *) $3;
   16251         168 :                     n->pathspec = $5;
   16252         168 :                     n->passing = $6;
   16253         168 :                     n->output = NULL;
   16254         168 :                     n->on_error = (JsonBehavior *) $7;
   16255         168 :                     n->location = @1;
   16256         168 :                     $$ = (Node *) n;
   16257             :                 }
   16258             :             | JSON_VALUE '('
   16259             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16260             :                 json_returning_clause_opt
   16261             :                 json_behavior_clause_opt
   16262             :             ')'
   16263             :                 {
   16264         576 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16265             : 
   16266         576 :                     n->op = JSON_VALUE_OP;
   16267         576 :                     n->context_item = (JsonValueExpr *) $3;
   16268         576 :                     n->pathspec = $5;
   16269         576 :                     n->passing = $6;
   16270         576 :                     n->output = (JsonOutput *) $7;
   16271         576 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16272         576 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16273         576 :                     n->location = @1;
   16274         576 :                     $$ = (Node *) n;
   16275             :                 }
   16276             :             ;
   16277             : 
   16278             : 
   16279             : /*
   16280             :  * SQL/XML support
   16281             :  */
   16282             : xml_root_version: VERSION_P a_expr
   16283          24 :                 { $$ = $2; }
   16284             :             | VERSION_P NO VALUE_P
   16285          44 :                 { $$ = makeNullAConst(-1); }
   16286             :         ;
   16287             : 
   16288             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16289          26 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16290             :             | ',' STANDALONE_P NO
   16291          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16292             :             | ',' STANDALONE_P NO VALUE_P
   16293          12 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16294             :             | /*EMPTY*/
   16295          18 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16296             :         ;
   16297             : 
   16298          56 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   16299             :         ;
   16300             : 
   16301          88 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   16302         144 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   16303             :         ;
   16304             : 
   16305             : xml_attribute_el: a_expr AS ColLabel
   16306             :                 {
   16307         106 :                     $$ = makeNode(ResTarget);
   16308         106 :                     $$->name = $3;
   16309         106 :                     $$->indirection = NIL;
   16310         106 :                     $$->val = (Node *) $1;
   16311         106 :                     $$->location = @1;
   16312             :                 }
   16313             :             | a_expr
   16314             :                 {
   16315         126 :                     $$ = makeNode(ResTarget);
   16316         126 :                     $$->name = NULL;
   16317         126 :                     $$->indirection = NIL;
   16318         126 :                     $$->val = (Node *) $1;
   16319         126 :                     $$->location = @1;
   16320             :                 }
   16321             :         ;
   16322             : 
   16323         186 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16324         188 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16325             :         ;
   16326             : 
   16327         140 : xml_indent_option: INDENT                           { $$ = true; }
   16328          36 :             | NO INDENT                             { $$ = false; }
   16329          42 :             | /*EMPTY*/                             { $$ = false; }
   16330             :         ;
   16331             : 
   16332           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16333           2 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16334         138 :             | /*EMPTY*/                             { $$ = false; }
   16335             :         ;
   16336             : 
   16337             : /* We allow several variants for SQL and other compatibility. */
   16338             : xmlexists_argument:
   16339             :             PASSING c_expr
   16340             :                 {
   16341         226 :                     $$ = $2;
   16342             :                 }
   16343             :             | PASSING c_expr xml_passing_mech
   16344             :                 {
   16345           0 :                     $$ = $2;
   16346             :                 }
   16347             :             | PASSING xml_passing_mech c_expr
   16348             :                 {
   16349          42 :                     $$ = $3;
   16350             :                 }
   16351             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16352             :                 {
   16353           6 :                     $$ = $3;
   16354             :                 }
   16355             :         ;
   16356             : 
   16357             : xml_passing_mech:
   16358             :             BY REF_P
   16359             :             | BY VALUE_P
   16360             :         ;
   16361             : 
   16362             : 
   16363             : /*
   16364             :  * Aggregate decoration clauses
   16365             :  */
   16366             : within_group_clause:
   16367         348 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16368      321266 :             | /*EMPTY*/                             { $$ = NIL; }
   16369             :         ;
   16370             : 
   16371             : filter_clause:
   16372         836 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16373      321138 :             | /*EMPTY*/                             { $$ = NULL; }
   16374             :         ;
   16375             : 
   16376             : 
   16377             : /*
   16378             :  * Window Definitions
   16379             :  */
   16380             : window_clause:
   16381         540 :             WINDOW window_definition_list           { $$ = $2; }
   16382      497306 :             | /*EMPTY*/                             { $$ = NIL; }
   16383             :         ;
   16384             : 
   16385             : window_definition_list:
   16386         540 :             window_definition                       { $$ = list_make1($1); }
   16387             :             | window_definition_list ',' window_definition
   16388          12 :                                                     { $$ = lappend($1, $3); }
   16389             :         ;
   16390             : 
   16391             : window_definition:
   16392             :             ColId AS window_specification
   16393             :                 {
   16394         552 :                     WindowDef  *n = $3;
   16395             : 
   16396         552 :                     n->name = $1;
   16397         552 :                     $$ = n;
   16398             :                 }
   16399             :         ;
   16400             : 
   16401             : over_clause: OVER window_specification
   16402        2602 :                 { $$ = $2; }
   16403             :             | OVER ColId
   16404             :                 {
   16405         954 :                     WindowDef  *n = makeNode(WindowDef);
   16406             : 
   16407         954 :                     n->name = $2;
   16408         954 :                     n->refname = NULL;
   16409         954 :                     n->partitionClause = NIL;
   16410         954 :                     n->orderClause = NIL;
   16411         954 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16412         954 :                     n->startOffset = NULL;
   16413         954 :                     n->endOffset = NULL;
   16414         954 :                     n->location = @2;
   16415         954 :                     $$ = n;
   16416             :                 }
   16417             :             | /*EMPTY*/
   16418      318412 :                 { $$ = NULL; }
   16419             :         ;
   16420             : 
   16421             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16422             :                         opt_sort_clause opt_frame_clause ')'
   16423             :                 {
   16424        3154 :                     WindowDef  *n = makeNode(WindowDef);
   16425             : 
   16426        3154 :                     n->name = NULL;
   16427        3154 :                     n->refname = $2;
   16428        3154 :                     n->partitionClause = $3;
   16429        3154 :                     n->orderClause = $4;
   16430             :                     /* copy relevant fields of opt_frame_clause */
   16431        3154 :                     n->frameOptions = $5->frameOptions;
   16432        3154 :                     n->startOffset = $5->startOffset;
   16433        3154 :                     n->endOffset = $5->endOffset;
   16434        3154 :                     n->location = @1;
   16435        3154 :                     $$ = n;
   16436             :                 }
   16437             :         ;
   16438             : 
   16439             : /*
   16440             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16441             :  * of a window_specification, we want the assumption to be that there is
   16442             :  * no existing_window_name; but those keywords are unreserved and so could
   16443             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16444             :  * and giving the empty production here a slightly higher precedence, so
   16445             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16446             :  * These keywords are thus precluded from being an existing_window_name but
   16447             :  * are not reserved for any other purpose.
   16448             :  */
   16449          54 : opt_existing_window_name: ColId                     { $$ = $1; }
   16450        3106 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16451             :         ;
   16452             : 
   16453         910 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16454        2244 :             | /*EMPTY*/                             { $$ = NIL; }
   16455             :         ;
   16456             : 
   16457             : /*
   16458             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16459             :  * frameOptions, startOffset, and endOffset.
   16460             :  */
   16461             : opt_frame_clause:
   16462             :             RANGE frame_extent opt_window_exclusion_clause
   16463             :                 {
   16464         796 :                     WindowDef  *n = $2;
   16465             : 
   16466         796 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16467         796 :                     n->frameOptions |= $3;
   16468         796 :                     $$ = n;
   16469             :                 }
   16470             :             | ROWS frame_extent opt_window_exclusion_clause
   16471             :                 {
   16472         624 :                     WindowDef  *n = $2;
   16473             : 
   16474         624 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16475         624 :                     n->frameOptions |= $3;
   16476         624 :                     $$ = n;
   16477             :                 }
   16478             :             | GROUPS frame_extent opt_window_exclusion_clause
   16479             :                 {
   16480         204 :                     WindowDef  *n = $2;
   16481             : 
   16482         204 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16483         204 :                     n->frameOptions |= $3;
   16484         204 :                     $$ = n;
   16485             :                 }
   16486             :             | /*EMPTY*/
   16487             :                 {
   16488        1530 :                     WindowDef  *n = makeNode(WindowDef);
   16489             : 
   16490        1530 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16491        1530 :                     n->startOffset = NULL;
   16492        1530 :                     n->endOffset = NULL;
   16493        1530 :                     $$ = n;
   16494             :                 }
   16495             :         ;
   16496             : 
   16497             : frame_extent: frame_bound
   16498             :                 {
   16499          12 :                     WindowDef  *n = $1;
   16500             : 
   16501             :                     /* reject invalid cases */
   16502          12 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16503           0 :                         ereport(ERROR,
   16504             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16505             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16506             :                                  parser_errposition(@1)));
   16507          12 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16508           0 :                         ereport(ERROR,
   16509             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16510             :                                  errmsg("frame starting from following row cannot end with current row"),
   16511             :                                  parser_errposition(@1)));
   16512          12 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16513          12 :                     $$ = n;
   16514             :                 }
   16515             :             | BETWEEN frame_bound AND frame_bound
   16516             :                 {
   16517        1612 :                     WindowDef  *n1 = $2;
   16518        1612 :                     WindowDef  *n2 = $4;
   16519             : 
   16520             :                     /* form merged options */
   16521        1612 :                     int     frameOptions = n1->frameOptions;
   16522             :                     /* shift converts START_ options to END_ options */
   16523        1612 :                     frameOptions |= n2->frameOptions << 1;
   16524        1612 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16525             :                     /* reject invalid cases */
   16526        1612 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16527           0 :                         ereport(ERROR,
   16528             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16529             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16530             :                                  parser_errposition(@2)));
   16531        1612 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16532           0 :                         ereport(ERROR,
   16533             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16534             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16535             :                                  parser_errposition(@4)));
   16536        1612 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16537         460 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16538           0 :                         ereport(ERROR,
   16539             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16540             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16541             :                                  parser_errposition(@4)));
   16542        1612 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16543         168 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16544             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16545           0 :                         ereport(ERROR,
   16546             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16547             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16548             :                                  parser_errposition(@4)));
   16549        1612 :                     n1->frameOptions = frameOptions;
   16550        1612 :                     n1->endOffset = n2->startOffset;
   16551        1612 :                     $$ = n1;
   16552             :                 }
   16553             :         ;
   16554             : 
   16555             : /*
   16556             :  * This is used for both frame start and frame end, with output set up on
   16557             :  * the assumption it's frame start; the frame_extent productions must reject
   16558             :  * invalid cases.
   16559             :  */
   16560             : frame_bound:
   16561             :             UNBOUNDED PRECEDING
   16562             :                 {
   16563         198 :                     WindowDef  *n = makeNode(WindowDef);
   16564             : 
   16565         198 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16566         198 :                     n->startOffset = NULL;
   16567         198 :                     n->endOffset = NULL;
   16568         198 :                     $$ = n;
   16569             :                 }
   16570             :             | UNBOUNDED FOLLOWING
   16571             :                 {
   16572         376 :                     WindowDef  *n = makeNode(WindowDef);
   16573             : 
   16574         376 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16575         376 :                     n->startOffset = NULL;
   16576         376 :                     n->endOffset = NULL;
   16577         376 :                     $$ = n;
   16578             :                 }
   16579             :             | CURRENT_P ROW
   16580             :                 {
   16581         604 :                     WindowDef  *n = makeNode(WindowDef);
   16582             : 
   16583         604 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16584         604 :                     n->startOffset = NULL;
   16585         604 :                     n->endOffset = NULL;
   16586         604 :                     $$ = n;
   16587             :                 }
   16588             :             | a_expr PRECEDING
   16589             :                 {
   16590         906 :                     WindowDef  *n = makeNode(WindowDef);
   16591             : 
   16592         906 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16593         906 :                     n->startOffset = $1;
   16594         906 :                     n->endOffset = NULL;
   16595         906 :                     $$ = n;
   16596             :                 }
   16597             :             | a_expr FOLLOWING
   16598             :                 {
   16599        1152 :                     WindowDef  *n = makeNode(WindowDef);
   16600             : 
   16601        1152 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16602        1152 :                     n->startOffset = $1;
   16603        1152 :                     n->endOffset = NULL;
   16604        1152 :                     $$ = n;
   16605             :                 }
   16606             :         ;
   16607             : 
   16608             : opt_window_exclusion_clause:
   16609          84 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16610          96 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16611         150 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16612          18 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16613        1276 :             | /*EMPTY*/             { $$ = 0; }
   16614             :         ;
   16615             : 
   16616             : 
   16617             : /*
   16618             :  * Supporting nonterminals for expressions.
   16619             :  */
   16620             : 
   16621             : /* Explicit row production.
   16622             :  *
   16623             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16624             :  * without conflicting with the parenthesized a_expr production.  Without the
   16625             :  * ROW keyword, there must be more than one a_expr inside the parens.
   16626             :  */
   16627           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16628           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16629        1752 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16630             :         ;
   16631             : 
   16632        3870 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16633          30 :             | ROW '(' ')'                           { $$ = NIL; }
   16634             :         ;
   16635             : 
   16636        2438 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16637             :         ;
   16638             : 
   16639       16184 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16640           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16641         324 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16642             :         ;
   16643             : 
   16644       11050 : all_Op:     Op                                      { $$ = $1; }
   16645       27194 :             | MathOp                                { $$ = $1; }
   16646             :         ;
   16647             : 
   16648          40 : MathOp:      '+'                                    { $$ = "+"; }
   16649          64 :             | '-'                                   { $$ = "-"; }
   16650         118 :             | '*'                                   { $$ = "*"; }
   16651           0 :             | '/'                                   { $$ = "/"; }
   16652           8 :             | '%'                                   { $$ = "%"; }
   16653           0 :             | '^'                                   { $$ = "^"; }
   16654         752 :             | '<'                                    { $$ = "<"; }
   16655         648 :             | '>'                                    { $$ = ">"; }
   16656       23608 :             | '='                                   { $$ = "="; }
   16657         618 :             | LESS_EQUALS                           { $$ = "<="; }
   16658         610 :             | GREATER_EQUALS                        { $$ = ">="; }
   16659         728 :             | NOT_EQUALS                            { $$ = "<>"; }
   16660             :         ;
   16661             : 
   16662             : qual_Op:    Op
   16663       42614 :                     { $$ = list_make1(makeString($1)); }
   16664             :             | OPERATOR '(' any_operator ')'
   16665       15268 :                     { $$ = $3; }
   16666             :         ;
   16667             : 
   16668             : qual_all_Op:
   16669             :             all_Op
   16670        1416 :                     { $$ = list_make1(makeString($1)); }
   16671             :             | OPERATOR '(' any_operator ')'
   16672          34 :                     { $$ = $3; }
   16673             :         ;
   16674             : 
   16675             : subquery_Op:
   16676             :             all_Op
   16677       16202 :                     { $$ = list_make1(makeString($1)); }
   16678             :             | OPERATOR '(' any_operator ')'
   16679         274 :                     { $$ = $3; }
   16680             :             | LIKE
   16681          24 :                     { $$ = list_make1(makeString("~~")); }
   16682             :             | NOT_LA LIKE
   16683          12 :                     { $$ = list_make1(makeString("!~~")); }
   16684             :             | ILIKE
   16685          12 :                     { $$ = list_make1(makeString("~~*")); }
   16686             :             | NOT_LA ILIKE
   16687           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16688             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16689             :  * the regular expression is preprocessed by a function (similar_to_escape),
   16690             :  * and the ~ operator for posix regular expressions is used.
   16691             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16692             :  * this transformation is made on the fly by the parser upwards.
   16693             :  * however the SubLink structure which handles any/some/all stuff
   16694             :  * is not ready for such a thing.
   16695             :  */
   16696             :             ;
   16697             : 
   16698             : expr_list:  a_expr
   16699             :                 {
   16700      175420 :                     $$ = list_make1($1);
   16701             :                 }
   16702             :             | expr_list ',' a_expr
   16703             :                 {
   16704      161516 :                     $$ = lappend($1, $3);
   16705             :                 }
   16706             :         ;
   16707             : 
   16708             : /* function arguments can have names */
   16709             : func_arg_list:  func_arg_expr
   16710             :                 {
   16711      312504 :                     $$ = list_make1($1);
   16712             :                 }
   16713             :             | func_arg_list ',' func_arg_expr
   16714             :                 {
   16715      276972 :                     $$ = lappend($1, $3);
   16716             :                 }
   16717             :         ;
   16718             : 
   16719             : func_arg_expr:  a_expr
   16720             :                 {
   16721      543342 :                     $$ = $1;
   16722             :                 }
   16723             :             | param_name COLON_EQUALS a_expr
   16724             :                 {
   16725       45782 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16726             : 
   16727       45782 :                     na->name = $1;
   16728       45782 :                     na->arg = (Expr *) $3;
   16729       45782 :                     na->argnumber = -1;      /* until determined */
   16730       45782 :                     na->location = @1;
   16731       45782 :                     $$ = (Node *) na;
   16732             :                 }
   16733             :             | param_name EQUALS_GREATER a_expr
   16734             :                 {
   16735        1084 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16736             : 
   16737        1084 :                     na->name = $1;
   16738        1084 :                     na->arg = (Expr *) $3;
   16739        1084 :                     na->argnumber = -1;      /* until determined */
   16740        1084 :                     na->location = @1;
   16741        1084 :                     $$ = (Node *) na;
   16742             :                 }
   16743             :         ;
   16744             : 
   16745         198 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16746           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16747             :         ;
   16748             : 
   16749        2012 : type_list:  Typename                                { $$ = list_make1($1); }
   16750         598 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16751             :         ;
   16752             : 
   16753             : array_expr: '[' expr_list ']'
   16754             :                 {
   16755        7530 :                     $$ = makeAArrayExpr($2, @1);
   16756             :                 }
   16757             :             | '[' array_expr_list ']'
   16758             :                 {
   16759         406 :                     $$ = makeAArrayExpr($2, @1);
   16760             :                 }
   16761             :             | '[' ']'
   16762             :                 {
   16763          88 :                     $$ = makeAArrayExpr(NIL, @1);
   16764             :                 }
   16765             :         ;
   16766             : 
   16767         406 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16768         330 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16769             :         ;
   16770             : 
   16771             : 
   16772             : extract_list:
   16773             :             extract_arg FROM a_expr
   16774             :                 {
   16775        1342 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16776             :                 }
   16777             :         ;
   16778             : 
   16779             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16780             :  * - thomas 2001-04-12
   16781             :  */
   16782             : extract_arg:
   16783        1084 :             IDENT                                   { $$ = $1; }
   16784          72 :             | YEAR_P                                { $$ = "year"; }
   16785          42 :             | MONTH_P                               { $$ = "month"; }
   16786          54 :             | DAY_P                                 { $$ = "day"; }
   16787          30 :             | HOUR_P                                { $$ = "hour"; }
   16788          30 :             | MINUTE_P                              { $$ = "minute"; }
   16789          30 :             | SECOND_P                              { $$ = "second"; }
   16790           0 :             | Sconst                                { $$ = $1; }
   16791             :         ;
   16792             : 
   16793             : unicode_normal_form:
   16794          24 :             NFC                                     { $$ = "NFC"; }
   16795          18 :             | NFD                                   { $$ = "NFD"; }
   16796          18 :             | NFKC                                  { $$ = "NFKC"; }
   16797          18 :             | NFKD                                  { $$ = "NFKD"; }
   16798             :         ;
   16799             : 
   16800             : /* OVERLAY() arguments */
   16801             : overlay_list:
   16802             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16803             :                 {
   16804             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16805          34 :                     $$ = list_make4($1, $3, $5, $7);
   16806             :                 }
   16807             :             | a_expr PLACING a_expr FROM a_expr
   16808             :                 {
   16809             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16810          48 :                     $$ = list_make3($1, $3, $5);
   16811             :                 }
   16812             :         ;
   16813             : 
   16814             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16815             : position_list:
   16816         390 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16817             :         ;
   16818             : 
   16819             : /*
   16820             :  * SUBSTRING() arguments
   16821             :  *
   16822             :  * Note that SQL:1999 has both
   16823             :  *     text FROM int FOR int
   16824             :  * and
   16825             :  *     text FROM pattern FOR escape
   16826             :  *
   16827             :  * In the parser we map them both to a call to the substring() function and
   16828             :  * rely on type resolution to pick the right one.
   16829             :  *
   16830             :  * In SQL:2003, the second variant was changed to
   16831             :  *     text SIMILAR pattern ESCAPE escape
   16832             :  * We could in theory map that to a different function internally, but
   16833             :  * since we still support the SQL:1999 version, we don't.  However,
   16834             :  * ruleutils.c will reverse-list the call in the newer style.
   16835             :  */
   16836             : substr_list:
   16837             :             a_expr FROM a_expr FOR a_expr
   16838             :                 {
   16839         122 :                     $$ = list_make3($1, $3, $5);
   16840             :                 }
   16841             :             | a_expr FOR a_expr FROM a_expr
   16842             :                 {
   16843             :                     /* not legal per SQL, but might as well allow it */
   16844           0 :                     $$ = list_make3($1, $5, $3);
   16845             :                 }
   16846             :             | a_expr FROM a_expr
   16847             :                 {
   16848             :                     /*
   16849             :                      * Because we aren't restricting data types here, this
   16850             :                      * syntax can end up resolving to textregexsubstr().
   16851             :                      * We've historically allowed that to happen, so continue
   16852             :                      * to accept it.  However, ruleutils.c will reverse-list
   16853             :                      * such a call in regular function call syntax.
   16854             :                      */
   16855         340 :                     $$ = list_make2($1, $3);
   16856             :                 }
   16857             :             | a_expr FOR a_expr
   16858             :                 {
   16859             :                     /* not legal per SQL */
   16860             : 
   16861             :                     /*
   16862             :                      * Since there are no cases where this syntax allows
   16863             :                      * a textual FOR value, we forcibly cast the argument
   16864             :                      * to int4.  The possible matches in pg_proc are
   16865             :                      * substring(text,int4) and substring(text,text),
   16866             :                      * and we don't want the parser to choose the latter,
   16867             :                      * which it is likely to do if the second argument
   16868             :                      * is unknown or doesn't have an implicit cast to int4.
   16869             :                      */
   16870          36 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16871             :                                     makeTypeCast($3,
   16872             :                                                  SystemTypeName("int4"), -1));
   16873             :                 }
   16874             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16875             :                 {
   16876         172 :                     $$ = list_make3($1, $3, $5);
   16877             :                 }
   16878             :         ;
   16879             : 
   16880         588 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16881          24 :             | FROM expr_list                        { $$ = $2; }
   16882          86 :             | expr_list                             { $$ = $1; }
   16883             :         ;
   16884             : 
   16885             : in_expr:    select_with_parens
   16886             :                 {
   16887        2738 :                     SubLink    *n = makeNode(SubLink);
   16888             : 
   16889        2738 :                     n->subselect = $1;
   16890             :                     /* other fields will be filled later */
   16891        2738 :                     $$ = (Node *) n;
   16892             :                 }
   16893       22436 :             | '(' expr_list ')'                     { $$ = (Node *) $2; }
   16894             :         ;
   16895             : 
   16896             : /*
   16897             :  * Define SQL-style CASE clause.
   16898             :  * - Full specification
   16899             :  *  CASE WHEN a = b THEN c ... ELSE d END
   16900             :  * - Implicit argument
   16901             :  *  CASE a WHEN b THEN c ... ELSE d END
   16902             :  */
   16903             : case_expr:  CASE case_arg when_clause_list case_default END_P
   16904             :                 {
   16905       56832 :                     CaseExpr   *c = makeNode(CaseExpr);
   16906             : 
   16907       56832 :                     c->casetype = InvalidOid; /* not analyzed yet */
   16908       56832 :                     c->arg = (Expr *) $2;
   16909       56832 :                     c->args = $3;
   16910       56832 :                     c->defresult = (Expr *) $4;
   16911       56832 :                     c->location = @1;
   16912       56832 :                     $$ = (Node *) c;
   16913             :                 }
   16914             :         ;
   16915             : 
   16916             : when_clause_list:
   16917             :             /* There must be at least one */
   16918       56832 :             when_clause                             { $$ = list_make1($1); }
   16919       44134 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   16920             :         ;
   16921             : 
   16922             : when_clause:
   16923             :             WHEN a_expr THEN a_expr
   16924             :                 {
   16925      100966 :                     CaseWhen   *w = makeNode(CaseWhen);
   16926             : 
   16927      100966 :                     w->expr = (Expr *) $2;
   16928      100966 :                     w->result = (Expr *) $4;
   16929      100966 :                     w->location = @1;
   16930      100966 :                     $$ = (Node *) w;
   16931             :                 }
   16932             :         ;
   16933             : 
   16934             : case_default:
   16935       47760 :             ELSE a_expr                             { $$ = $2; }
   16936        9072 :             | /*EMPTY*/                             { $$ = NULL; }
   16937             :         ;
   16938             : 
   16939        6372 : case_arg:   a_expr                                  { $$ = $1; }
   16940       50460 :             | /*EMPTY*/                             { $$ = NULL; }
   16941             :         ;
   16942             : 
   16943             : columnref:  ColId
   16944             :                 {
   16945      697862 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   16946             :                 }
   16947             :             | ColId indirection
   16948             :                 {
   16949     1008836 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   16950             :                 }
   16951             :         ;
   16952             : 
   16953             : indirection_el:
   16954             :             '.' attr_name
   16955             :                 {
   16956     1370778 :                     $$ = (Node *) makeString($2);
   16957             :                 }
   16958             :             | '.' '*'
   16959             :                 {
   16960        6814 :                     $$ = (Node *) makeNode(A_Star);
   16961             :                 }
   16962             :             | '[' a_expr ']'
   16963             :                 {
   16964       12572 :                     A_Indices *ai = makeNode(A_Indices);
   16965             : 
   16966       12572 :                     ai->is_slice = false;
   16967       12572 :                     ai->lidx = NULL;
   16968       12572 :                     ai->uidx = $2;
   16969       12572 :                     $$ = (Node *) ai;
   16970             :                 }
   16971             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   16972             :                 {
   16973         570 :                     A_Indices *ai = makeNode(A_Indices);
   16974             : 
   16975         570 :                     ai->is_slice = true;
   16976         570 :                     ai->lidx = $2;
   16977         570 :                     ai->uidx = $4;
   16978         570 :                     $$ = (Node *) ai;
   16979             :                 }
   16980             :         ;
   16981             : 
   16982             : opt_slice_bound:
   16983         960 :             a_expr                                  { $$ = $1; }
   16984         180 :             | /*EMPTY*/                             { $$ = NULL; }
   16985             :         ;
   16986             : 
   16987             : indirection:
   16988     1371458 :             indirection_el                          { $$ = list_make1($1); }
   16989        3010 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   16990             :         ;
   16991             : 
   16992             : opt_indirection:
   16993      292184 :             /*EMPTY*/                               { $$ = NIL; }
   16994       16266 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   16995             :         ;
   16996             : 
   16997             : opt_asymmetric: ASYMMETRIC
   16998             :             | /*EMPTY*/
   16999             :         ;
   17000             : 
   17001             : /* SQL/JSON support */
   17002             : json_passing_clause_opt:
   17003         336 :             PASSING json_arguments                  { $$ = $2; }
   17004        1934 :             | /*EMPTY*/                             { $$ = NIL; }
   17005             :         ;
   17006             : 
   17007             : json_arguments:
   17008         336 :             json_argument                           { $$ = list_make1($1); }
   17009         126 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   17010             :         ;
   17011             : 
   17012             : json_argument:
   17013             :             json_value_expr AS ColLabel
   17014             :             {
   17015         462 :                 JsonArgument *n = makeNode(JsonArgument);
   17016             : 
   17017         462 :                 n->val = (JsonValueExpr *) $1;
   17018         462 :                 n->name = $3;
   17019         462 :                 $$ = (Node *) n;
   17020             :             }
   17021             :         ;
   17022             : 
   17023             : /* ARRAY is a noise word */
   17024             : json_wrapper_behavior:
   17025          42 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17026           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17027          78 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17028          12 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17029           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17030          12 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17031          36 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17032           6 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17033        1634 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17034             :         ;
   17035             : 
   17036             : json_behavior:
   17037             :             DEFAULT a_expr
   17038         384 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17039             :             | json_behavior_type
   17040         702 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17041             :         ;
   17042             : 
   17043             : json_behavior_type:
   17044         492 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17045          30 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17046          30 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17047          12 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17048          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17049          30 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17050          72 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17051             :             /* non-standard, for Oracle compatibility only */
   17052          24 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17053             :         ;
   17054             : 
   17055             : json_behavior_clause_opt:
   17056             :             json_behavior ON EMPTY_P
   17057         174 :                 { $$ = list_make2($1, NULL); }
   17058             :             | json_behavior ON ERROR_P
   17059         552 :                 { $$ = list_make2(NULL, $1); }
   17060             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17061         102 :                 { $$ = list_make2($1, $4); }
   17062             :             | /* EMPTY */
   17063        1568 :                 { $$ = list_make2(NULL, NULL); }
   17064             :         ;
   17065             : 
   17066             : json_on_error_clause_opt:
   17067             :             json_behavior ON ERROR_P
   17068         150 :                 { $$ = $1; }
   17069             :             | /* EMPTY */
   17070         686 :                 { $$ = NULL; }
   17071             :         ;
   17072             : 
   17073             : json_value_expr:
   17074             :             a_expr json_format_clause_opt
   17075             :             {
   17076             :                 /* formatted_expr will be set during parse-analysis. */
   17077        4202 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17078        4202 :                                                 castNode(JsonFormat, $2));
   17079             :             }
   17080             :         ;
   17081             : 
   17082             : json_format_clause:
   17083             :             FORMAT_LA JSON ENCODING name
   17084             :                 {
   17085             :                     int     encoding;
   17086             : 
   17087         100 :                     if (!pg_strcasecmp($4, "utf8"))
   17088          64 :                         encoding = JS_ENC_UTF8;
   17089          36 :                     else if (!pg_strcasecmp($4, "utf16"))
   17090          12 :                         encoding = JS_ENC_UTF16;
   17091          24 :                     else if (!pg_strcasecmp($4, "utf32"))
   17092          12 :                         encoding = JS_ENC_UTF32;
   17093             :                     else
   17094          12 :                         ereport(ERROR,
   17095             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17096             :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17097             :                                  parser_errposition(@4)));
   17098             : 
   17099          88 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17100             :                 }
   17101             :             | FORMAT_LA JSON
   17102             :                 {
   17103         412 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17104             :                 }
   17105             :         ;
   17106             : 
   17107             : json_format_clause_opt:
   17108             :             json_format_clause
   17109             :                 {
   17110         392 :                     $$ = $1;
   17111             :                 }
   17112             :             | /* EMPTY */
   17113             :                 {
   17114        5308 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17115             :                 }
   17116             :         ;
   17117             : 
   17118             : json_quotes_clause_opt:
   17119          12 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17120          90 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17121          12 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17122         168 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17123        1538 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17124             :         ;
   17125             : 
   17126             : json_returning_clause_opt:
   17127             :             RETURNING Typename json_format_clause_opt
   17128             :                 {
   17129        1444 :                     JsonOutput *n = makeNode(JsonOutput);
   17130             : 
   17131        1444 :                     n->typeName = $2;
   17132        1444 :                     n->returning = makeNode(JsonReturning);
   17133        1444 :                     n->returning->format = (JsonFormat *) $3;
   17134        1444 :                     $$ = (Node *) n;
   17135             :                 }
   17136        1272 :             | /* EMPTY */                           { $$ = NULL; }
   17137             :         ;
   17138             : 
   17139             : /*
   17140             :  * We must assign the only-JSON production a precedence less than IDENT in
   17141             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17142             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17143             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17144             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17145             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17146             :  * really related to this syntax, but it's a convenient choice because it
   17147             :  * already has a precedence less than IDENT for other reasons.
   17148             :  */
   17149             : json_predicate_type_constraint:
   17150         202 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17151          28 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17152          40 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17153          40 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17154          40 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17155             :         ;
   17156             : 
   17157             : /*
   17158             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17159             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17160             :  * This prevents reducing them when the next token is KEYS.
   17161             :  */
   17162             : json_key_uniqueness_constraint_opt:
   17163         108 :             WITH UNIQUE KEYS                            { $$ = true; }
   17164         100 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17165          44 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17166          16 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17167         798 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17168             :         ;
   17169             : 
   17170             : json_name_and_value_list:
   17171             :             json_name_and_value
   17172         348 :                 { $$ = list_make1($1); }
   17173             :             | json_name_and_value_list ',' json_name_and_value
   17174         256 :                 { $$ = lappend($1, $3); }
   17175             :         ;
   17176             : 
   17177             : json_name_and_value:
   17178             : /* Supporting this syntax seems to require major surgery
   17179             :             KEY c_expr VALUE_P json_value_expr
   17180             :                 { $$ = makeJsonKeyValue($2, $4); }
   17181             :             |
   17182             : */
   17183             :             c_expr VALUE_P json_value_expr
   17184          24 :                 { $$ = makeJsonKeyValue($1, $3); }
   17185             :             |
   17186             :             a_expr ':' json_value_expr
   17187         784 :                 { $$ = makeJsonKeyValue($1, $3); }
   17188             :         ;
   17189             : 
   17190             : /* empty means false for objects, true for arrays */
   17191             : json_object_constructor_null_clause_opt:
   17192          30 :             NULL_P ON NULL_P                    { $$ = false; }
   17193         110 :             | ABSENT ON NULL_P                  { $$ = true; }
   17194         412 :             | /* EMPTY */                       { $$ = false; }
   17195             :         ;
   17196             : 
   17197             : json_array_constructor_null_clause_opt:
   17198          60 :             NULL_P ON NULL_P                        { $$ = false; }
   17199          36 :             | ABSENT ON NULL_P                      { $$ = true; }
   17200         168 :             | /* EMPTY */                           { $$ = true; }
   17201             :         ;
   17202             : 
   17203             : json_value_expr_list:
   17204         108 :             json_value_expr                             { $$ = list_make1($1); }
   17205         126 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17206             :         ;
   17207             : 
   17208             : json_aggregate_func:
   17209             :             JSON_OBJECTAGG '('
   17210             :                 json_name_and_value
   17211             :                 json_object_constructor_null_clause_opt
   17212             :                 json_key_uniqueness_constraint_opt
   17213             :                 json_returning_clause_opt
   17214             :             ')'
   17215             :                 {
   17216         204 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17217             : 
   17218         204 :                     n->arg = (JsonKeyValue *) $3;
   17219         204 :                     n->absent_on_null = $4;
   17220         204 :                     n->unique = $5;
   17221         204 :                     n->constructor = makeNode(JsonAggConstructor);
   17222         204 :                     n->constructor->output = (JsonOutput *) $6;
   17223         204 :                     n->constructor->agg_order = NULL;
   17224         204 :                     n->constructor->location = @1;
   17225         204 :                     $$ = (Node *) n;
   17226             :                 }
   17227             :             | JSON_ARRAYAGG '('
   17228             :                 json_value_expr
   17229             :                 json_array_aggregate_order_by_clause_opt
   17230             :                 json_array_constructor_null_clause_opt
   17231             :                 json_returning_clause_opt
   17232             :             ')'
   17233             :                 {
   17234         156 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17235             : 
   17236         156 :                     n->arg = (JsonValueExpr *) $3;
   17237         156 :                     n->absent_on_null = $5;
   17238         156 :                     n->constructor = makeNode(JsonAggConstructor);
   17239         156 :                     n->constructor->agg_order = $4;
   17240         156 :                     n->constructor->output = (JsonOutput *) $6;
   17241         156 :                     n->constructor->location = @1;
   17242         156 :                     $$ = (Node *) n;
   17243             :                 }
   17244             :         ;
   17245             : 
   17246             : json_array_aggregate_order_by_clause_opt:
   17247          18 :             ORDER BY sortby_list                    { $$ = $3; }
   17248         138 :             | /* EMPTY */                           { $$ = NIL; }
   17249             :         ;
   17250             : 
   17251             : /*****************************************************************************
   17252             :  *
   17253             :  *  target list for SELECT
   17254             :  *
   17255             :  *****************************************************************************/
   17256             : 
   17257      493972 : opt_target_list: target_list                        { $$ = $1; }
   17258         408 :             | /* EMPTY */                           { $$ = NIL; }
   17259             :         ;
   17260             : 
   17261             : target_list:
   17262      500612 :             target_el                               { $$ = list_make1($1); }
   17263      631776 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17264             :         ;
   17265             : 
   17266             : target_el:  a_expr AS ColLabel
   17267             :                 {
   17268      208188 :                     $$ = makeNode(ResTarget);
   17269      208188 :                     $$->name = $3;
   17270      208188 :                     $$->indirection = NIL;
   17271      208188 :                     $$->val = (Node *) $1;
   17272      208188 :                     $$->location = @1;
   17273             :                 }
   17274             :             | a_expr BareColLabel
   17275             :                 {
   17276        3488 :                     $$ = makeNode(ResTarget);
   17277        3488 :                     $$->name = $2;
   17278        3488 :                     $$->indirection = NIL;
   17279        3488 :                     $$->val = (Node *) $1;
   17280        3488 :                     $$->location = @1;
   17281             :                 }
   17282             :             | a_expr
   17283             :                 {
   17284      865716 :                     $$ = makeNode(ResTarget);
   17285      865716 :                     $$->name = NULL;
   17286      865716 :                     $$->indirection = NIL;
   17287      865716 :                     $$->val = (Node *) $1;
   17288      865716 :                     $$->location = @1;
   17289             :                 }
   17290             :             | '*'
   17291             :                 {
   17292       54996 :                     ColumnRef  *n = makeNode(ColumnRef);
   17293             : 
   17294       54996 :                     n->fields = list_make1(makeNode(A_Star));
   17295       54996 :                     n->location = @1;
   17296             : 
   17297       54996 :                     $$ = makeNode(ResTarget);
   17298       54996 :                     $$->name = NULL;
   17299       54996 :                     $$->indirection = NIL;
   17300       54996 :                     $$->val = (Node *) n;
   17301       54996 :                     $$->location = @1;
   17302             :                 }
   17303             :         ;
   17304             : 
   17305             : 
   17306             : /*****************************************************************************
   17307             :  *
   17308             :  *  Names and constants
   17309             :  *
   17310             :  *****************************************************************************/
   17311             : 
   17312             : qualified_name_list:
   17313       16012 :             qualified_name                          { $$ = list_make1($1); }
   17314         434 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17315             :         ;
   17316             : 
   17317             : /*
   17318             :  * The production for a qualified relation name has to exactly match the
   17319             :  * production for a qualified func_name, because in a FROM clause we cannot
   17320             :  * tell which we are parsing until we see what comes after it ('(' for a
   17321             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17322             :  * which may contain subscripts, and reject that case in the C code.
   17323             :  */
   17324             : qualified_name:
   17325             :             ColId
   17326             :                 {
   17327      406588 :                     $$ = makeRangeVar(NULL, $1, @1);
   17328             :                 }
   17329             :             | ColId indirection
   17330             :                 {
   17331      238858 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17332             :                 }
   17333             :         ;
   17334             : 
   17335             : name_list:  name
   17336       26676 :                     { $$ = list_make1(makeString($1)); }
   17337             :             | name_list ',' name
   17338       55756 :                     { $$ = lappend($1, makeString($3)); }
   17339             :         ;
   17340             : 
   17341             : 
   17342      177324 : name:       ColId                                   { $$ = $1; };
   17343             : 
   17344     1486370 : attr_name:  ColLabel                                { $$ = $1; };
   17345             : 
   17346          60 : file_name:  Sconst                                  { $$ = $1; };
   17347             : 
   17348             : /*
   17349             :  * The production for a qualified func_name has to exactly match the
   17350             :  * production for a qualified columnref, because we cannot tell which we
   17351             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17352             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17353             :  * may contain subscripts, and reject that case in the C code.  (If we
   17354             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17355             :  */
   17356             : func_name:  type_function_name
   17357      298882 :                     { $$ = list_make1(makeString($1)); }
   17358             :             | ColId indirection
   17359             :                     {
   17360      123686 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17361             :                                              yyscanner);
   17362             :                     }
   17363             :         ;
   17364             : 
   17365             : 
   17366             : /*
   17367             :  * Constants
   17368             :  */
   17369             : AexprConst: Iconst
   17370             :                 {
   17371      438422 :                     $$ = makeIntConst($1, @1);
   17372             :                 }
   17373             :             | FCONST
   17374             :                 {
   17375       11350 :                     $$ = makeFloatConst($1, @1);
   17376             :                 }
   17377             :             | Sconst
   17378             :                 {
   17379      690756 :                     $$ = makeStringConst($1, @1);
   17380             :                 }
   17381             :             | BCONST
   17382             :                 {
   17383         754 :                     $$ = makeBitStringConst($1, @1);
   17384             :                 }
   17385             :             | XCONST
   17386             :                 {
   17387             :                     /* This is a bit constant per SQL99:
   17388             :                      * Without Feature F511, "BIT data type",
   17389             :                      * a <general literal> shall not be a
   17390             :                      * <bit string literal> or a <hex string literal>.
   17391             :                      */
   17392        3302 :                     $$ = makeBitStringConst($1, @1);
   17393             :                 }
   17394             :             | func_name Sconst
   17395             :                 {
   17396             :                     /* generic type 'literal' syntax */
   17397        9840 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17398             : 
   17399        9840 :                     t->location = @1;
   17400        9840 :                     $$ = makeStringConstCast($2, @2, t);
   17401             :                 }
   17402             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17403             :                 {
   17404             :                     /* generic syntax with a type modifier */
   17405           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17406             :                     ListCell   *lc;
   17407             : 
   17408             :                     /*
   17409             :                      * We must use func_arg_list and opt_sort_clause in the
   17410             :                      * production to avoid reduce/reduce conflicts, but we
   17411             :                      * don't actually wish to allow NamedArgExpr in this
   17412             :                      * context, nor ORDER BY.
   17413             :                      */
   17414           0 :                     foreach(lc, $3)
   17415             :                     {
   17416           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17417             : 
   17418           0 :                         if (IsA(arg, NamedArgExpr))
   17419           0 :                             ereport(ERROR,
   17420             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17421             :                                      errmsg("type modifier cannot have parameter name"),
   17422             :                                      parser_errposition(arg->location)));
   17423             :                     }
   17424           0 :                     if ($4 != NIL)
   17425           0 :                             ereport(ERROR,
   17426             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17427             :                                      errmsg("type modifier cannot have ORDER BY"),
   17428             :                                      parser_errposition(@4)));
   17429             : 
   17430           0 :                     t->typmods = $3;
   17431           0 :                     t->location = @1;
   17432           0 :                     $$ = makeStringConstCast($6, @6, t);
   17433             :                 }
   17434             :             | ConstTypename Sconst
   17435             :                 {
   17436        3114 :                     $$ = makeStringConstCast($2, @2, $1);
   17437             :                 }
   17438             :             | ConstInterval Sconst opt_interval
   17439             :                 {
   17440        3298 :                     TypeName   *t = $1;
   17441             : 
   17442        3298 :                     t->typmods = $3;
   17443        3298 :                     $$ = makeStringConstCast($2, @2, t);
   17444             :                 }
   17445             :             | ConstInterval '(' Iconst ')' Sconst
   17446             :                 {
   17447          12 :                     TypeName   *t = $1;
   17448             : 
   17449          12 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17450             :                                             makeIntConst($3, @3));
   17451          12 :                     $$ = makeStringConstCast($5, @5, t);
   17452             :                 }
   17453             :             | TRUE_P
   17454             :                 {
   17455       23520 :                     $$ = makeBoolAConst(true, @1);
   17456             :                 }
   17457             :             | FALSE_P
   17458             :                 {
   17459       33988 :                     $$ = makeBoolAConst(false, @1);
   17460             :                 }
   17461             :             | NULL_P
   17462             :                 {
   17463       62882 :                     $$ = makeNullAConst(@1);
   17464             :                 }
   17465             :         ;
   17466             : 
   17467      462806 : Iconst:     ICONST                                  { $$ = $1; };
   17468      760596 : Sconst:     SCONST                                  { $$ = $1; };
   17469             : 
   17470       16438 : SignedIconst: Iconst                                { $$ = $1; }
   17471           0 :             | '+' Iconst                            { $$ = + $2; }
   17472         272 :             | '-' Iconst                            { $$ = - $2; }
   17473             :         ;
   17474             : 
   17475             : /* Role specifications */
   17476             : RoleId:     RoleSpec
   17477             :                 {
   17478        1884 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17479             : 
   17480        1884 :                     switch (spc->roletype)
   17481             :                     {
   17482        1874 :                         case ROLESPEC_CSTRING:
   17483        1874 :                             $$ = spc->rolename;
   17484        1874 :                             break;
   17485           4 :                         case ROLESPEC_PUBLIC:
   17486           4 :                             ereport(ERROR,
   17487             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17488             :                                      errmsg("role name \"%s\" is reserved",
   17489             :                                             "public"),
   17490             :                                      parser_errposition(@1)));
   17491             :                             break;
   17492           2 :                         case ROLESPEC_SESSION_USER:
   17493           2 :                             ereport(ERROR,
   17494             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17495             :                                      errmsg("%s cannot be used as a role name here",
   17496             :                                             "SESSION_USER"),
   17497             :                                      parser_errposition(@1)));
   17498             :                             break;
   17499           2 :                         case ROLESPEC_CURRENT_USER:
   17500           2 :                             ereport(ERROR,
   17501             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17502             :                                      errmsg("%s cannot be used as a role name here",
   17503             :                                             "CURRENT_USER"),
   17504             :                                      parser_errposition(@1)));
   17505             :                             break;
   17506           2 :                         case ROLESPEC_CURRENT_ROLE:
   17507           2 :                             ereport(ERROR,
   17508             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17509             :                                      errmsg("%s cannot be used as a role name here",
   17510             :                                             "CURRENT_ROLE"),
   17511             :                                      parser_errposition(@1)));
   17512             :                             break;
   17513             :                     }
   17514        1874 :                 }
   17515             :             ;
   17516             : 
   17517             : RoleSpec:   NonReservedWord
   17518             :                 {
   17519             :                     /*
   17520             :                      * "public" and "none" are not keywords, but they must
   17521             :                      * be treated specially here.
   17522             :                      */
   17523             :                     RoleSpec   *n;
   17524             : 
   17525       29628 :                     if (strcmp($1, "public") == 0)
   17526             :                     {
   17527       15758 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17528       15758 :                         n->roletype = ROLESPEC_PUBLIC;
   17529             :                     }
   17530       13870 :                     else if (strcmp($1, "none") == 0)
   17531             :                     {
   17532          26 :                         ereport(ERROR,
   17533             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17534             :                                  errmsg("role name \"%s\" is reserved",
   17535             :                                         "none"),
   17536             :                                  parser_errposition(@1)));
   17537             :                     }
   17538             :                     else
   17539             :                     {
   17540       13844 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17541       13844 :                         n->rolename = pstrdup($1);
   17542             :                     }
   17543       29602 :                     $$ = n;
   17544             :                 }
   17545             :             | CURRENT_ROLE
   17546             :                 {
   17547         130 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17548             :                 }
   17549             :             | CURRENT_USER
   17550             :                 {
   17551         228 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17552             :                 }
   17553             :             | SESSION_USER
   17554             :                 {
   17555          36 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17556             :                 }
   17557             :         ;
   17558             : 
   17559             : role_list:  RoleSpec
   17560        3252 :                 { $$ = list_make1($1); }
   17561             :             | role_list ',' RoleSpec
   17562         270 :                 { $$ = lappend($1, $3); }
   17563             :         ;
   17564             : 
   17565             : 
   17566             : /*****************************************************************************
   17567             :  *
   17568             :  * PL/pgSQL extensions
   17569             :  *
   17570             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17571             :  * historically it can include just about anything that can follow SELECT.
   17572             :  * Therefore the returned struct is a SelectStmt.
   17573             :  *****************************************************************************/
   17574             : 
   17575             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17576             :             from_clause where_clause
   17577             :             group_clause having_clause window_clause
   17578             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17579             :                 {
   17580       40284 :                     SelectStmt *n = makeNode(SelectStmt);
   17581             : 
   17582       40284 :                     n->distinctClause = $1;
   17583       40284 :                     n->targetList = $2;
   17584       40284 :                     n->fromClause = $3;
   17585       40284 :                     n->whereClause = $4;
   17586       40284 :                     n->groupClause = ($5)->list;
   17587       40284 :                     n->groupDistinct = ($5)->distinct;
   17588       40284 :                     n->havingClause = $6;
   17589       40284 :                     n->windowClause = $7;
   17590       40284 :                     n->sortClause = $8;
   17591       40284 :                     if ($9)
   17592             :                     {
   17593           4 :                         n->limitOffset = $9->limitOffset;
   17594           4 :                         n->limitCount = $9->limitCount;
   17595           4 :                         if (!n->sortClause &&
   17596           4 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17597           0 :                             ereport(ERROR,
   17598             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17599             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17600             :                                      parser_errposition($9->optionLoc)));
   17601           4 :                         n->limitOption = $9->limitOption;
   17602             :                     }
   17603       40284 :                     n->lockingClause = $10;
   17604       40284 :                     $$ = (Node *) n;
   17605             :                 }
   17606             :         ;
   17607             : 
   17608             : /*
   17609             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17610             :  */
   17611             : 
   17612             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17613             :                 {
   17614        7032 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17615             : 
   17616        7032 :                     n->name = $1;
   17617        7032 :                     n->indirection = check_indirection($2, yyscanner);
   17618             :                     /* nnames will be filled by calling production */
   17619        7032 :                     n->val = (SelectStmt *) $4;
   17620        7032 :                     n->location = @1;
   17621        7032 :                     $$ = (Node *) n;
   17622             :                 }
   17623             :         ;
   17624             : 
   17625        7008 : plassign_target: ColId                          { $$ = $1; }
   17626          24 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17627             :         ;
   17628             : 
   17629             : plassign_equals: COLON_EQUALS
   17630             :             | '='
   17631             :         ;
   17632             : 
   17633             : 
   17634             : /*
   17635             :  * Name classification hierarchy.
   17636             :  *
   17637             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   17638             :  * no known keyword.  In most cases, we can accept certain keywords as
   17639             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   17640             :  * as possible to minimize the impact of "reserved words" on programmers.
   17641             :  * So, we divide names into several possible classes.  The classification
   17642             :  * is chosen in part to make keywords acceptable as names wherever possible.
   17643             :  */
   17644             : 
   17645             : /* Column identifier --- names that can be column, table, etc names.
   17646             :  */
   17647     3218118 : ColId:      IDENT                                   { $$ = $1; }
   17648       55084 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17649        5582 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17650             :         ;
   17651             : 
   17652             : /* Type/function identifier --- names that can be type or function names.
   17653             :  */
   17654      678258 : type_function_name: IDENT                           { $$ = $1; }
   17655       71442 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17656          66 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17657             :         ;
   17658             : 
   17659             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   17660             :  */
   17661       77520 : NonReservedWord:    IDENT                           { $$ = $1; }
   17662       28756 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17663         178 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17664        5144 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17665             :         ;
   17666             : 
   17667             : /* Column label --- allowed labels in "AS" clauses.
   17668             :  * This presently includes *all* Postgres keywords.
   17669             :  */
   17670     1678904 : ColLabel:   IDENT                                   { $$ = $1; }
   17671       37866 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   17672         284 :             | col_name_keyword                      { $$ = pstrdup($1); }
   17673        1780 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   17674        7452 :             | reserved_keyword                      { $$ = pstrdup($1); }
   17675             :         ;
   17676             : 
   17677             : /* Bare column label --- names that can be column labels without writing "AS".
   17678             :  * This classification is orthogonal to the other keyword categories.
   17679             :  */
   17680        3482 : BareColLabel:   IDENT                               { $$ = $1; }
   17681           6 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   17682             :         ;
   17683             : 
   17684             : 
   17685             : /*
   17686             :  * Keyword category lists.  Generally, every keyword present in
   17687             :  * the Postgres grammar should appear in exactly one of these lists.
   17688             :  *
   17689             :  * Put a new keyword into the first list that it can go into without causing
   17690             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17691             :  * categories of keywords.
   17692             :  *
   17693             :  * Make sure that each keyword's category in kwlist.h matches where
   17694             :  * it is listed here.  (Someday we may be able to generate these lists and
   17695             :  * kwlist.h's table from one source of truth.)
   17696             :  */
   17697             : 
   17698             : /* "Unreserved" keywords --- available for use as any kind of name.
   17699             :  */
   17700             : unreserved_keyword:
   17701             :               ABORT_P
   17702             :             | ABSENT
   17703             :             | ABSOLUTE_P
   17704             :             | ACCESS
   17705             :             | ACTION
   17706             :             | ADD_P
   17707             :             | ADMIN
   17708             :             | AFTER
   17709             :             | AGGREGATE
   17710             :             | ALSO
   17711             :             | ALTER
   17712             :             | ALWAYS
   17713             :             | ASENSITIVE
   17714             :             | ASSERTION
   17715             :             | ASSIGNMENT
   17716             :             | AT
   17717             :             | ATOMIC
   17718             :             | ATTACH
   17719             :             | ATTRIBUTE
   17720             :             | BACKWARD
   17721             :             | BEFORE
   17722             :             | BEGIN_P
   17723             :             | BREADTH
   17724             :             | BY
   17725             :             | CACHE
   17726             :             | CALL
   17727             :             | CALLED
   17728             :             | CASCADE
   17729             :             | CASCADED
   17730             :             | CATALOG_P
   17731             :             | CHAIN
   17732             :             | CHARACTERISTICS
   17733             :             | CHECKPOINT
   17734             :             | CLASS
   17735             :             | CLOSE
   17736             :             | CLUSTER
   17737             :             | COLUMNS
   17738             :             | COMMENT
   17739             :             | COMMENTS
   17740             :             | COMMIT
   17741             :             | COMMITTED
   17742             :             | COMPRESSION
   17743             :             | CONDITIONAL
   17744             :             | CONFIGURATION
   17745             :             | CONFLICT
   17746             :             | CONNECTION
   17747             :             | CONSTRAINTS
   17748             :             | CONTENT_P
   17749             :             | CONTINUE_P
   17750             :             | CONVERSION_P
   17751             :             | COPY
   17752             :             | COST
   17753             :             | CSV
   17754             :             | CUBE
   17755             :             | CURRENT_P
   17756             :             | CURSOR
   17757             :             | CYCLE
   17758             :             | DATA_P
   17759             :             | DATABASE
   17760             :             | DAY_P
   17761             :             | DEALLOCATE
   17762             :             | DECLARE
   17763             :             | DEFAULTS
   17764             :             | DEFERRED
   17765             :             | DEFINER
   17766             :             | DELETE_P
   17767             :             | DELIMITER
   17768             :             | DELIMITERS
   17769             :             | DEPENDS
   17770             :             | DEPTH
   17771             :             | DETACH
   17772             :             | DICTIONARY
   17773             :             | DISABLE_P
   17774             :             | DISCARD
   17775             :             | DOCUMENT_P
   17776             :             | DOMAIN_P
   17777             :             | DOUBLE_P
   17778             :             | DROP
   17779             :             | EACH
   17780             :             | EMPTY_P
   17781             :             | ENABLE_P
   17782             :             | ENCODING
   17783             :             | ENCRYPTED
   17784             :             | ENFORCED
   17785             :             | ENUM_P
   17786             :             | ERROR_P
   17787             :             | ESCAPE
   17788             :             | EVENT
   17789             :             | EXCLUDE
   17790             :             | EXCLUDING
   17791             :             | EXCLUSIVE
   17792             :             | EXECUTE
   17793             :             | EXPLAIN
   17794             :             | EXPRESSION
   17795             :             | EXTENSION
   17796             :             | EXTERNAL
   17797             :             | FAMILY
   17798             :             | FILTER
   17799             :             | FINALIZE
   17800             :             | FIRST_P
   17801             :             | FOLLOWING
   17802             :             | FORCE
   17803             :             | FORMAT
   17804             :             | FORWARD
   17805             :             | FUNCTION
   17806             :             | FUNCTIONS
   17807             :             | GENERATED
   17808             :             | GLOBAL
   17809             :             | GRANTED
   17810             :             | GROUPS
   17811             :             | HANDLER
   17812             :             | HEADER_P
   17813             :             | HOLD
   17814             :             | HOUR_P
   17815             :             | IDENTITY_P
   17816             :             | IF_P
   17817             :             | IMMEDIATE
   17818             :             | IMMUTABLE
   17819             :             | IMPLICIT_P
   17820             :             | IMPORT_P
   17821             :             | INCLUDE
   17822             :             | INCLUDING
   17823             :             | INCREMENT
   17824             :             | INDENT
   17825             :             | INDEX
   17826             :             | INDEXES
   17827             :             | INHERIT
   17828             :             | INHERITS
   17829             :             | INLINE_P
   17830             :             | INPUT_P
   17831             :             | INSENSITIVE
   17832             :             | INSERT
   17833             :             | INSTEAD
   17834             :             | INVOKER
   17835             :             | ISOLATION
   17836             :             | KEEP
   17837             :             | KEY
   17838             :             | KEYS
   17839             :             | LABEL
   17840             :             | LANGUAGE
   17841             :             | LARGE_P
   17842             :             | LAST_P
   17843             :             | LEAKPROOF
   17844             :             | LEVEL
   17845             :             | LISTEN
   17846             :             | LOAD
   17847             :             | LOCAL
   17848             :             | LOCATION
   17849             :             | LOCK_P
   17850             :             | LOCKED
   17851             :             | LOGGED
   17852             :             | MAPPING
   17853             :             | MATCH
   17854             :             | MATCHED
   17855             :             | MATERIALIZED
   17856             :             | MAXVALUE
   17857             :             | MERGE
   17858             :             | METHOD
   17859             :             | MINUTE_P
   17860             :             | MINVALUE
   17861             :             | MODE
   17862             :             | MONTH_P
   17863             :             | MOVE
   17864             :             | NAME_P
   17865             :             | NAMES
   17866             :             | NESTED
   17867             :             | NEW
   17868             :             | NEXT
   17869             :             | NFC
   17870             :             | NFD
   17871             :             | NFKC
   17872             :             | NFKD
   17873             :             | NO
   17874             :             | NORMALIZED
   17875             :             | NOTHING
   17876             :             | NOTIFY
   17877             :             | NOWAIT
   17878             :             | NULLS_P
   17879             :             | OBJECT_P
   17880             :             | OF
   17881             :             | OFF
   17882             :             | OIDS
   17883             :             | OLD
   17884             :             | OMIT
   17885             :             | OPERATOR
   17886             :             | OPTION
   17887             :             | OPTIONS
   17888             :             | ORDINALITY
   17889             :             | OTHERS
   17890             :             | OVER
   17891             :             | OVERRIDING
   17892             :             | OWNED
   17893             :             | OWNER
   17894             :             | PARALLEL
   17895             :             | PARAMETER
   17896             :             | PARSER
   17897             :             | PARTIAL
   17898             :             | PARTITION
   17899             :             | PASSING
   17900             :             | PASSWORD
   17901             :             | PATH
   17902             :             | PERIOD
   17903             :             | PLAN
   17904             :             | PLANS
   17905             :             | POLICY
   17906             :             | PRECEDING
   17907             :             | PREPARE
   17908             :             | PREPARED
   17909             :             | PRESERVE
   17910             :             | PRIOR
   17911             :             | PRIVILEGES
   17912             :             | PROCEDURAL
   17913             :             | PROCEDURE
   17914             :             | PROCEDURES
   17915             :             | PROGRAM
   17916             :             | PUBLICATION
   17917             :             | QUOTE
   17918             :             | QUOTES
   17919             :             | RANGE
   17920             :             | READ
   17921             :             | REASSIGN
   17922             :             | RECURSIVE
   17923             :             | REF_P
   17924             :             | REFERENCING
   17925             :             | REFRESH
   17926             :             | REINDEX
   17927             :             | RELATIVE_P
   17928             :             | RELEASE
   17929             :             | RENAME
   17930             :             | REPEATABLE
   17931             :             | REPLACE
   17932             :             | REPLICA
   17933             :             | RESET
   17934             :             | RESTART
   17935             :             | RESTRICT
   17936             :             | RETURN
   17937             :             | RETURNS
   17938             :             | REVOKE
   17939             :             | ROLE
   17940             :             | ROLLBACK
   17941             :             | ROLLUP
   17942             :             | ROUTINE
   17943             :             | ROUTINES
   17944             :             | ROWS
   17945             :             | RULE
   17946             :             | SAVEPOINT
   17947             :             | SCALAR
   17948             :             | SCHEMA
   17949             :             | SCHEMAS
   17950             :             | SCROLL
   17951             :             | SEARCH
   17952             :             | SECOND_P
   17953             :             | SECURITY
   17954             :             | SEQUENCE
   17955             :             | SEQUENCES
   17956             :             | SERIALIZABLE
   17957             :             | SERVER
   17958             :             | SESSION
   17959             :             | SET
   17960             :             | SETS
   17961             :             | SHARE
   17962             :             | SHOW
   17963             :             | SIMPLE
   17964             :             | SKIP
   17965             :             | SNAPSHOT
   17966             :             | SOURCE
   17967             :             | SQL_P
   17968             :             | STABLE
   17969             :             | STANDALONE_P
   17970             :             | START
   17971             :             | STATEMENT
   17972             :             | STATISTICS
   17973             :             | STDIN
   17974             :             | STDOUT
   17975             :             | STORAGE
   17976             :             | STORED
   17977             :             | STRICT_P
   17978             :             | STRING_P
   17979             :             | STRIP_P
   17980             :             | SUBSCRIPTION
   17981             :             | SUPPORT
   17982             :             | SYSID
   17983             :             | SYSTEM_P
   17984             :             | TABLES
   17985             :             | TABLESPACE
   17986             :             | TARGET
   17987             :             | TEMP
   17988             :             | TEMPLATE
   17989             :             | TEMPORARY
   17990             :             | TEXT_P
   17991             :             | TIES
   17992             :             | TRANSACTION
   17993             :             | TRANSFORM
   17994             :             | TRIGGER
   17995             :             | TRUNCATE
   17996             :             | TRUSTED
   17997             :             | TYPE_P
   17998             :             | TYPES_P
   17999             :             | UESCAPE
   18000             :             | UNBOUNDED
   18001             :             | UNCOMMITTED
   18002             :             | UNCONDITIONAL
   18003             :             | UNENCRYPTED
   18004             :             | UNKNOWN
   18005             :             | UNLISTEN
   18006             :             | UNLOGGED
   18007             :             | UNTIL
   18008             :             | UPDATE
   18009             :             | VACUUM
   18010             :             | VALID
   18011             :             | VALIDATE
   18012             :             | VALIDATOR
   18013             :             | VALUE_P
   18014             :             | VARYING
   18015             :             | VERSION_P
   18016             :             | VIEW
   18017             :             | VIEWS
   18018             :             | VIRTUAL
   18019             :             | VOLATILE
   18020             :             | WHITESPACE_P
   18021             :             | WITHIN
   18022             :             | WITHOUT
   18023             :             | WORK
   18024             :             | WRAPPER
   18025             :             | WRITE
   18026             :             | XML_P
   18027             :             | YEAR_P
   18028             :             | YES_P
   18029             :             | ZONE
   18030             :         ;
   18031             : 
   18032             : /* Column identifier --- keywords that can be column, table, etc names.
   18033             :  *
   18034             :  * Many of these keywords will in fact be recognized as type or function
   18035             :  * names too; but they have special productions for the purpose, and so
   18036             :  * can't be treated as "generic" type or function names.
   18037             :  *
   18038             :  * The type names appearing here are not usable as function names
   18039             :  * because they can be followed by '(' in typename productions, which
   18040             :  * looks too much like a function call for an LR(1) parser.
   18041             :  */
   18042             : col_name_keyword:
   18043             :               BETWEEN
   18044             :             | BIGINT
   18045             :             | BIT
   18046             :             | BOOLEAN_P
   18047             :             | CHAR_P
   18048             :             | CHARACTER
   18049             :             | COALESCE
   18050             :             | DEC
   18051             :             | DECIMAL_P
   18052             :             | EXISTS
   18053             :             | EXTRACT
   18054             :             | FLOAT_P
   18055             :             | GREATEST
   18056             :             | GROUPING
   18057             :             | INOUT
   18058             :             | INT_P
   18059             :             | INTEGER
   18060             :             | INTERVAL
   18061             :             | JSON
   18062             :             | JSON_ARRAY
   18063             :             | JSON_ARRAYAGG
   18064             :             | JSON_EXISTS
   18065             :             | JSON_OBJECT
   18066             :             | JSON_OBJECTAGG
   18067             :             | JSON_QUERY
   18068             :             | JSON_SCALAR
   18069             :             | JSON_SERIALIZE
   18070             :             | JSON_TABLE
   18071             :             | JSON_VALUE
   18072             :             | LEAST
   18073             :             | MERGE_ACTION
   18074             :             | NATIONAL
   18075             :             | NCHAR
   18076             :             | NONE
   18077             :             | NORMALIZE
   18078             :             | NULLIF
   18079             :             | NUMERIC
   18080             :             | OUT_P
   18081             :             | OVERLAY
   18082             :             | POSITION
   18083             :             | PRECISION
   18084             :             | REAL
   18085             :             | ROW
   18086             :             | SETOF
   18087             :             | SMALLINT
   18088             :             | SUBSTRING
   18089             :             | TIME
   18090             :             | TIMESTAMP
   18091             :             | TREAT
   18092             :             | TRIM
   18093             :             | VALUES
   18094             :             | VARCHAR
   18095             :             | XMLATTRIBUTES
   18096             :             | XMLCONCAT
   18097             :             | XMLELEMENT
   18098             :             | XMLEXISTS
   18099             :             | XMLFOREST
   18100             :             | XMLNAMESPACES
   18101             :             | XMLPARSE
   18102             :             | XMLPI
   18103             :             | XMLROOT
   18104             :             | XMLSERIALIZE
   18105             :             | XMLTABLE
   18106             :         ;
   18107             : 
   18108             : /* Type/function identifier --- keywords that can be type or function names.
   18109             :  *
   18110             :  * Most of these are keywords that are used as operators in expressions;
   18111             :  * in general such keywords can't be column names because they would be
   18112             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18113             :  *
   18114             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18115             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18116             :  * - thomas 2000-11-28
   18117             :  */
   18118             : type_func_name_keyword:
   18119             :               AUTHORIZATION
   18120             :             | BINARY
   18121             :             | COLLATION
   18122             :             | CONCURRENTLY
   18123             :             | CROSS
   18124             :             | CURRENT_SCHEMA
   18125             :             | FREEZE
   18126             :             | FULL
   18127             :             | ILIKE
   18128             :             | INNER_P
   18129             :             | IS
   18130             :             | ISNULL
   18131             :             | JOIN
   18132             :             | LEFT
   18133             :             | LIKE
   18134             :             | NATURAL
   18135             :             | NOTNULL
   18136             :             | OUTER_P
   18137             :             | OVERLAPS
   18138             :             | RIGHT
   18139             :             | SIMILAR
   18140             :             | TABLESAMPLE
   18141             :             | VERBOSE
   18142             :         ;
   18143             : 
   18144             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18145             :  *
   18146             :  * Keywords appear here if they could not be distinguished from variable,
   18147             :  * type, or function names in some contexts.  Don't put things here unless
   18148             :  * forced to.
   18149             :  */
   18150             : reserved_keyword:
   18151             :               ALL
   18152             :             | ANALYSE
   18153             :             | ANALYZE
   18154             :             | AND
   18155             :             | ANY
   18156             :             | ARRAY
   18157             :             | AS
   18158             :             | ASC
   18159             :             | ASYMMETRIC
   18160             :             | BOTH
   18161             :             | CASE
   18162             :             | CAST
   18163             :             | CHECK
   18164             :             | COLLATE
   18165             :             | COLUMN
   18166             :             | CONSTRAINT
   18167             :             | CREATE
   18168             :             | CURRENT_CATALOG
   18169             :             | CURRENT_DATE
   18170             :             | CURRENT_ROLE
   18171             :             | CURRENT_TIME
   18172             :             | CURRENT_TIMESTAMP
   18173             :             | CURRENT_USER
   18174             :             | DEFAULT
   18175             :             | DEFERRABLE
   18176             :             | DESC
   18177             :             | DISTINCT
   18178             :             | DO
   18179             :             | ELSE
   18180             :             | END_P
   18181             :             | EXCEPT
   18182             :             | FALSE_P
   18183             :             | FETCH
   18184             :             | FOR
   18185             :             | FOREIGN
   18186             :             | FROM
   18187             :             | GRANT
   18188             :             | GROUP_P
   18189             :             | HAVING
   18190             :             | IN_P
   18191             :             | INITIALLY
   18192             :             | INTERSECT
   18193             :             | INTO
   18194             :             | LATERAL_P
   18195             :             | LEADING
   18196             :             | LIMIT
   18197             :             | LOCALTIME
   18198             :             | LOCALTIMESTAMP
   18199             :             | NOT
   18200             :             | NULL_P
   18201             :             | OFFSET
   18202             :             | ON
   18203             :             | ONLY
   18204             :             | OR
   18205             :             | ORDER
   18206             :             | PLACING
   18207             :             | PRIMARY
   18208             :             | REFERENCES
   18209             :             | RETURNING
   18210             :             | SELECT
   18211             :             | SESSION_USER
   18212             :             | SOME
   18213             :             | SYMMETRIC
   18214             :             | SYSTEM_USER
   18215             :             | TABLE
   18216             :             | THEN
   18217             :             | TO
   18218             :             | TRAILING
   18219             :             | TRUE_P
   18220             :             | UNION
   18221             :             | UNIQUE
   18222             :             | USER
   18223             :             | USING
   18224             :             | VARIADIC
   18225             :             | WHEN
   18226             :             | WHERE
   18227             :             | WINDOW
   18228             :             | WITH
   18229             :         ;
   18230             : 
   18231             : /*
   18232             :  * While all keywords can be used as column labels when preceded by AS,
   18233             :  * not all of them can be used as a "bare" column label without AS.
   18234             :  * Those that can be used as a bare label must be listed here,
   18235             :  * in addition to appearing in one of the category lists above.
   18236             :  *
   18237             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18238             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18239             :  */
   18240             : bare_label_keyword:
   18241             :               ABORT_P
   18242             :             | ABSENT
   18243             :             | ABSOLUTE_P
   18244             :             | ACCESS
   18245             :             | ACTION
   18246             :             | ADD_P
   18247             :             | ADMIN
   18248             :             | AFTER
   18249             :             | AGGREGATE
   18250             :             | ALL
   18251             :             | ALSO
   18252             :             | ALTER
   18253             :             | ALWAYS
   18254             :             | ANALYSE
   18255             :             | ANALYZE
   18256             :             | AND
   18257             :             | ANY
   18258             :             | ASC
   18259             :             | ASENSITIVE
   18260             :             | ASSERTION
   18261             :             | ASSIGNMENT
   18262             :             | ASYMMETRIC
   18263             :             | AT
   18264             :             | ATOMIC
   18265             :             | ATTACH
   18266             :             | ATTRIBUTE
   18267             :             | AUTHORIZATION
   18268             :             | BACKWARD
   18269             :             | BEFORE
   18270             :             | BEGIN_P
   18271             :             | BETWEEN
   18272             :             | BIGINT
   18273             :             | BINARY
   18274             :             | BIT
   18275             :             | BOOLEAN_P
   18276             :             | BOTH
   18277             :             | BREADTH
   18278             :             | BY
   18279             :             | CACHE
   18280             :             | CALL
   18281             :             | CALLED
   18282             :             | CASCADE
   18283             :             | CASCADED
   18284             :             | CASE
   18285             :             | CAST
   18286             :             | CATALOG_P
   18287             :             | CHAIN
   18288             :             | CHARACTERISTICS
   18289             :             | CHECK
   18290             :             | CHECKPOINT
   18291             :             | CLASS
   18292             :             | CLOSE
   18293             :             | CLUSTER
   18294             :             | COALESCE
   18295             :             | COLLATE
   18296             :             | COLLATION
   18297             :             | COLUMN
   18298             :             | COLUMNS
   18299             :             | COMMENT
   18300             :             | COMMENTS
   18301             :             | COMMIT
   18302             :             | COMMITTED
   18303             :             | COMPRESSION
   18304             :             | CONCURRENTLY
   18305             :             | CONDITIONAL
   18306             :             | CONFIGURATION
   18307             :             | CONFLICT
   18308             :             | CONNECTION
   18309             :             | CONSTRAINT
   18310             :             | CONSTRAINTS
   18311             :             | CONTENT_P
   18312             :             | CONTINUE_P
   18313             :             | CONVERSION_P
   18314             :             | COPY
   18315             :             | COST
   18316             :             | CROSS
   18317             :             | CSV
   18318             :             | CUBE
   18319             :             | CURRENT_P
   18320             :             | CURRENT_CATALOG
   18321             :             | CURRENT_DATE
   18322             :             | CURRENT_ROLE
   18323             :             | CURRENT_SCHEMA
   18324             :             | CURRENT_TIME
   18325             :             | CURRENT_TIMESTAMP
   18326             :             | CURRENT_USER
   18327             :             | CURSOR
   18328             :             | CYCLE
   18329             :             | DATA_P
   18330             :             | DATABASE
   18331             :             | DEALLOCATE
   18332             :             | DEC
   18333             :             | DECIMAL_P
   18334             :             | DECLARE
   18335             :             | DEFAULT
   18336             :             | DEFAULTS
   18337             :             | DEFERRABLE
   18338             :             | DEFERRED
   18339             :             | DEFINER
   18340             :             | DELETE_P
   18341             :             | DELIMITER
   18342             :             | DELIMITERS
   18343             :             | DEPENDS
   18344             :             | DEPTH
   18345             :             | DESC
   18346             :             | DETACH
   18347             :             | DICTIONARY
   18348             :             | DISABLE_P
   18349             :             | DISCARD
   18350             :             | DISTINCT
   18351             :             | DO
   18352             :             | DOCUMENT_P
   18353             :             | DOMAIN_P
   18354             :             | DOUBLE_P
   18355             :             | DROP
   18356             :             | EACH
   18357             :             | ELSE
   18358             :             | EMPTY_P
   18359             :             | ENABLE_P
   18360             :             | ENCODING
   18361             :             | ENCRYPTED
   18362             :             | END_P
   18363             :             | ENFORCED
   18364             :             | ENUM_P
   18365             :             | ERROR_P
   18366             :             | ESCAPE
   18367             :             | EVENT
   18368             :             | EXCLUDE
   18369             :             | EXCLUDING
   18370             :             | EXCLUSIVE
   18371             :             | EXECUTE
   18372             :             | EXISTS
   18373             :             | EXPLAIN
   18374             :             | EXPRESSION
   18375             :             | EXTENSION
   18376             :             | EXTERNAL
   18377             :             | EXTRACT
   18378             :             | FALSE_P
   18379             :             | FAMILY
   18380             :             | FINALIZE
   18381             :             | FIRST_P
   18382             :             | FLOAT_P
   18383             :             | FOLLOWING
   18384             :             | FORCE
   18385             :             | FOREIGN
   18386             :             | FORMAT
   18387             :             | FORWARD
   18388             :             | FREEZE
   18389             :             | FULL
   18390             :             | FUNCTION
   18391             :             | FUNCTIONS
   18392             :             | GENERATED
   18393             :             | GLOBAL
   18394             :             | GRANTED
   18395             :             | GREATEST
   18396             :             | GROUPING
   18397             :             | GROUPS
   18398             :             | HANDLER
   18399             :             | HEADER_P
   18400             :             | HOLD
   18401             :             | IDENTITY_P
   18402             :             | IF_P
   18403             :             | ILIKE
   18404             :             | IMMEDIATE
   18405             :             | IMMUTABLE
   18406             :             | IMPLICIT_P
   18407             :             | IMPORT_P
   18408             :             | IN_P
   18409             :             | INCLUDE
   18410             :             | INCLUDING
   18411             :             | INCREMENT
   18412             :             | INDENT
   18413             :             | INDEX
   18414             :             | INDEXES
   18415             :             | INHERIT
   18416             :             | INHERITS
   18417             :             | INITIALLY
   18418             :             | INLINE_P
   18419             :             | INNER_P
   18420             :             | INOUT
   18421             :             | INPUT_P
   18422             :             | INSENSITIVE
   18423             :             | INSERT
   18424             :             | INSTEAD
   18425             :             | INT_P
   18426             :             | INTEGER
   18427             :             | INTERVAL
   18428             :             | INVOKER
   18429             :             | IS
   18430             :             | ISOLATION
   18431             :             | JOIN
   18432             :             | JSON
   18433             :             | JSON_ARRAY
   18434             :             | JSON_ARRAYAGG
   18435             :             | JSON_EXISTS
   18436             :             | JSON_OBJECT
   18437             :             | JSON_OBJECTAGG
   18438             :             | JSON_QUERY
   18439             :             | JSON_SCALAR
   18440             :             | JSON_SERIALIZE
   18441             :             | JSON_TABLE
   18442             :             | JSON_VALUE
   18443             :             | KEEP
   18444             :             | KEY
   18445             :             | KEYS
   18446             :             | LABEL
   18447             :             | LANGUAGE
   18448             :             | LARGE_P
   18449             :             | LAST_P
   18450             :             | LATERAL_P
   18451             :             | LEADING
   18452             :             | LEAKPROOF
   18453             :             | LEAST
   18454             :             | LEFT
   18455             :             | LEVEL
   18456             :             | LIKE
   18457             :             | LISTEN
   18458             :             | LOAD
   18459             :             | LOCAL
   18460             :             | LOCALTIME
   18461             :             | LOCALTIMESTAMP
   18462             :             | LOCATION
   18463             :             | LOCK_P
   18464             :             | LOCKED
   18465             :             | LOGGED
   18466             :             | MAPPING
   18467             :             | MATCH
   18468             :             | MATCHED
   18469             :             | MATERIALIZED
   18470             :             | MAXVALUE
   18471             :             | MERGE
   18472             :             | MERGE_ACTION
   18473             :             | METHOD
   18474             :             | MINVALUE
   18475             :             | MODE
   18476             :             | MOVE
   18477             :             | NAME_P
   18478             :             | NAMES
   18479             :             | NATIONAL
   18480             :             | NATURAL
   18481             :             | NCHAR
   18482             :             | NESTED
   18483             :             | NEW
   18484             :             | NEXT
   18485             :             | NFC
   18486             :             | NFD
   18487             :             | NFKC
   18488             :             | NFKD
   18489             :             | NO
   18490             :             | NONE
   18491             :             | NORMALIZE
   18492             :             | NORMALIZED
   18493             :             | NOT
   18494             :             | NOTHING
   18495             :             | NOTIFY
   18496             :             | NOWAIT
   18497             :             | NULL_P
   18498             :             | NULLIF
   18499             :             | NULLS_P
   18500             :             | NUMERIC
   18501             :             | OBJECT_P
   18502             :             | OF
   18503             :             | OFF
   18504             :             | OIDS
   18505             :             | OLD
   18506             :             | OMIT
   18507             :             | ONLY
   18508             :             | OPERATOR
   18509             :             | OPTION
   18510             :             | OPTIONS
   18511             :             | OR
   18512             :             | ORDINALITY
   18513             :             | OTHERS
   18514             :             | OUT_P
   18515             :             | OUTER_P
   18516             :             | OVERLAY
   18517             :             | OVERRIDING
   18518             :             | OWNED
   18519             :             | OWNER
   18520             :             | PARALLEL
   18521             :             | PARAMETER
   18522             :             | PARSER
   18523             :             | PARTIAL
   18524             :             | PARTITION
   18525             :             | PASSING
   18526             :             | PASSWORD
   18527             :             | PATH
   18528             :             | PERIOD
   18529             :             | PLACING
   18530             :             | PLAN
   18531             :             | PLANS
   18532             :             | POLICY
   18533             :             | POSITION
   18534             :             | PRECEDING
   18535             :             | PREPARE
   18536             :             | PREPARED
   18537             :             | PRESERVE
   18538             :             | PRIMARY
   18539             :             | PRIOR
   18540             :             | PRIVILEGES
   18541             :             | PROCEDURAL
   18542             :             | PROCEDURE
   18543             :             | PROCEDURES
   18544             :             | PROGRAM
   18545             :             | PUBLICATION
   18546             :             | QUOTE
   18547             :             | QUOTES
   18548             :             | RANGE
   18549             :             | READ
   18550             :             | REAL
   18551             :             | REASSIGN
   18552             :             | RECURSIVE
   18553             :             | REF_P
   18554             :             | REFERENCES
   18555             :             | REFERENCING
   18556             :             | REFRESH
   18557             :             | REINDEX
   18558             :             | RELATIVE_P
   18559             :             | RELEASE
   18560             :             | RENAME
   18561             :             | REPEATABLE
   18562             :             | REPLACE
   18563             :             | REPLICA
   18564             :             | RESET
   18565             :             | RESTART
   18566             :             | RESTRICT
   18567             :             | RETURN
   18568             :             | RETURNS
   18569             :             | REVOKE
   18570             :             | RIGHT
   18571             :             | ROLE
   18572             :             | ROLLBACK
   18573             :             | ROLLUP
   18574             :             | ROUTINE
   18575             :             | ROUTINES
   18576             :             | ROW
   18577             :             | ROWS
   18578             :             | RULE
   18579             :             | SAVEPOINT
   18580             :             | SCALAR
   18581             :             | SCHEMA
   18582             :             | SCHEMAS
   18583             :             | SCROLL
   18584             :             | SEARCH
   18585             :             | SECURITY
   18586             :             | SELECT
   18587             :             | SEQUENCE
   18588             :             | SEQUENCES
   18589             :             | SERIALIZABLE
   18590             :             | SERVER
   18591             :             | SESSION
   18592             :             | SESSION_USER
   18593             :             | SET
   18594             :             | SETOF
   18595             :             | SETS
   18596             :             | SHARE
   18597             :             | SHOW
   18598             :             | SIMILAR
   18599             :             | SIMPLE
   18600             :             | SKIP
   18601             :             | SMALLINT
   18602             :             | SNAPSHOT
   18603             :             | SOME
   18604             :             | SOURCE
   18605             :             | SQL_P
   18606             :             | STABLE
   18607             :             | STANDALONE_P
   18608             :             | START
   18609             :             | STATEMENT
   18610             :             | STATISTICS
   18611             :             | STDIN
   18612             :             | STDOUT
   18613             :             | STORAGE
   18614             :             | STORED
   18615             :             | STRICT_P
   18616             :             | STRING_P
   18617             :             | STRIP_P
   18618             :             | SUBSCRIPTION
   18619             :             | SUBSTRING
   18620             :             | SUPPORT
   18621             :             | SYMMETRIC
   18622             :             | SYSID
   18623             :             | SYSTEM_P
   18624             :             | SYSTEM_USER
   18625             :             | TABLE
   18626             :             | TABLES
   18627             :             | TABLESAMPLE
   18628             :             | TABLESPACE
   18629             :             | TARGET
   18630             :             | TEMP
   18631             :             | TEMPLATE
   18632             :             | TEMPORARY
   18633             :             | TEXT_P
   18634             :             | THEN
   18635             :             | TIES
   18636             :             | TIME
   18637             :             | TIMESTAMP
   18638             :             | TRAILING
   18639             :             | TRANSACTION
   18640             :             | TRANSFORM
   18641             :             | TREAT
   18642             :             | TRIGGER
   18643             :             | TRIM
   18644             :             | TRUE_P
   18645             :             | TRUNCATE
   18646             :             | TRUSTED
   18647             :             | TYPE_P
   18648             :             | TYPES_P
   18649             :             | UESCAPE
   18650             :             | UNBOUNDED
   18651             :             | UNCOMMITTED
   18652             :             | UNCONDITIONAL
   18653             :             | UNENCRYPTED
   18654             :             | UNIQUE
   18655             :             | UNKNOWN
   18656             :             | UNLISTEN
   18657             :             | UNLOGGED
   18658             :             | UNTIL
   18659             :             | UPDATE
   18660             :             | USER
   18661             :             | USING
   18662             :             | VACUUM
   18663             :             | VALID
   18664             :             | VALIDATE
   18665             :             | VALIDATOR
   18666             :             | VALUE_P
   18667             :             | VALUES
   18668             :             | VARCHAR
   18669             :             | VARIADIC
   18670             :             | VERBOSE
   18671             :             | VERSION_P
   18672             :             | VIEW
   18673             :             | VIEWS
   18674             :             | VIRTUAL
   18675             :             | VOLATILE
   18676             :             | WHEN
   18677             :             | WHITESPACE_P
   18678             :             | WORK
   18679             :             | WRAPPER
   18680             :             | WRITE
   18681             :             | XML_P
   18682             :             | XMLATTRIBUTES
   18683             :             | XMLCONCAT
   18684             :             | XMLELEMENT
   18685             :             | XMLEXISTS
   18686             :             | XMLFOREST
   18687             :             | XMLNAMESPACES
   18688             :             | XMLPARSE
   18689             :             | XMLPI
   18690             :             | XMLROOT
   18691             :             | XMLSERIALIZE
   18692             :             | XMLTABLE
   18693             :             | YES_P
   18694             :             | ZONE
   18695             :         ;
   18696             : 
   18697             : %%
   18698             : 
   18699             : /*
   18700             :  * The signature of this function is required by bison.  However, we
   18701             :  * ignore the passed yylloc and instead use the last token position
   18702             :  * available from the scanner.
   18703             :  */
   18704             : static void
   18705         696 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   18706             : {
   18707         696 :     parser_yyerror(msg);
   18708             : }
   18709             : 
   18710             : static RawStmt *
   18711      842290 : makeRawStmt(Node *stmt, int stmt_location)
   18712             : {
   18713      842290 :     RawStmt    *rs = makeNode(RawStmt);
   18714             : 
   18715      842290 :     rs->stmt = stmt;
   18716      842290 :     rs->stmt_location = stmt_location;
   18717      842290 :     rs->stmt_len = 0;            /* might get changed later */
   18718      842290 :     return rs;
   18719             : }
   18720             : 
   18721             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   18722             : static void
   18723      599920 : updateRawStmtEnd(RawStmt *rs, int end_location)
   18724             : {
   18725             :     /*
   18726             :      * If we already set the length, don't change it.  This is for situations
   18727             :      * like "select foo ;; select bar" where the same statement will be last
   18728             :      * in the string for more than one semicolon.
   18729             :      */
   18730      599920 :     if (rs->stmt_len > 0)
   18731         552 :         return;
   18732             : 
   18733             :     /* OK, update length of RawStmt */
   18734      599368 :     rs->stmt_len = end_location - rs->stmt_location;
   18735             : }
   18736             : 
   18737             : /*
   18738             :  * Adjust a PreparableStmt to reflect that it doesn't run to the end of the
   18739             :  * string.
   18740             :  */
   18741             : static void
   18742         462 : updatePreparableStmtEnd(Node *n, int end_location)
   18743             : {
   18744         462 :     if (IsA(n, SelectStmt))
   18745             :     {
   18746         274 :         SelectStmt *stmt = (SelectStmt *) n;
   18747             : 
   18748         274 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18749             :     }
   18750         188 :     else if (IsA(n, InsertStmt))
   18751             :     {
   18752          62 :         InsertStmt *stmt = (InsertStmt *) n;
   18753             : 
   18754          62 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18755             :     }
   18756         126 :     else if (IsA(n, UpdateStmt))
   18757             :     {
   18758          56 :         UpdateStmt *stmt = (UpdateStmt *) n;
   18759             : 
   18760          56 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18761             :     }
   18762          70 :     else if (IsA(n, DeleteStmt))
   18763             :     {
   18764          54 :         DeleteStmt *stmt = (DeleteStmt *) n;
   18765             : 
   18766          54 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18767             :     }
   18768          16 :     else if (IsA(n, MergeStmt))
   18769             :     {
   18770          16 :         MergeStmt  *stmt = (MergeStmt *) n;
   18771             : 
   18772          16 :         stmt->stmt_len = end_location - stmt->stmt_location;
   18773             :     }
   18774             :     else
   18775           0 :         elog(ERROR, "unexpected node type %d", (int) n->type);
   18776         462 : }
   18777             : 
   18778             : static Node *
   18779     1706712 : makeColumnRef(char *colname, List *indirection,
   18780             :               int location, core_yyscan_t yyscanner)
   18781             : {
   18782             :     /*
   18783             :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   18784             :      * any subscripting in the specified indirection list.  However, any field
   18785             :      * selection at the start of the indirection list must be transposed into
   18786             :      * the "fields" part of the ColumnRef node.
   18787             :      */
   18788     1706712 :     ColumnRef  *c = makeNode(ColumnRef);
   18789     1706712 :     int         nfields = 0;
   18790             :     ListCell   *l;
   18791             : 
   18792     1706712 :     c->location = location;
   18793     2708694 :     foreach(l, indirection)
   18794             :     {
   18795     1011572 :         if (IsA(lfirst(l), A_Indices))
   18796             :         {
   18797        9590 :             A_Indirection *i = makeNode(A_Indirection);
   18798             : 
   18799        9590 :             if (nfields == 0)
   18800             :             {
   18801             :                 /* easy case - all indirection goes to A_Indirection */
   18802        6940 :                 c->fields = list_make1(makeString(colname));
   18803        6940 :                 i->indirection = check_indirection(indirection, yyscanner);
   18804             :             }
   18805             :             else
   18806             :             {
   18807             :                 /* got to split the list in two */
   18808        2650 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18809             :                                                                   nfields),
   18810             :                                                    yyscanner);
   18811        2650 :                 indirection = list_truncate(indirection, nfields);
   18812        2650 :                 c->fields = lcons(makeString(colname), indirection);
   18813             :             }
   18814        9590 :             i->arg = (Node *) c;
   18815        9590 :             return (Node *) i;
   18816             :         }
   18817     1001982 :         else if (IsA(lfirst(l), A_Star))
   18818             :         {
   18819             :             /* We only allow '*' at the end of a ColumnRef */
   18820        5454 :             if (lnext(indirection, l) != NULL)
   18821           0 :                 parser_yyerror("improper use of \"*\"");
   18822             :         }
   18823     1001982 :         nfields++;
   18824             :     }
   18825             :     /* No subscripting, so all indirection gets added to field list */
   18826     1697122 :     c->fields = lcons(makeString(colname), indirection);
   18827     1697122 :     return (Node *) c;
   18828             : }
   18829             : 
   18830             : static Node *
   18831      293992 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18832             : {
   18833      293992 :     TypeCast   *n = makeNode(TypeCast);
   18834             : 
   18835      293992 :     n->arg = arg;
   18836      293992 :     n->typeName = typename;
   18837      293992 :     n->location = location;
   18838      293992 :     return (Node *) n;
   18839             : }
   18840             : 
   18841             : static Node *
   18842       16264 : makeStringConstCast(char *str, int location, TypeName *typename)
   18843             : {
   18844       16264 :     Node       *s = makeStringConst(str, location);
   18845             : 
   18846       16264 :     return makeTypeCast(s, typename, -1);
   18847             : }
   18848             : 
   18849             : static Node *
   18850      447814 : makeIntConst(int val, int location)
   18851             : {
   18852      447814 :     A_Const    *n = makeNode(A_Const);
   18853             : 
   18854      447814 :     n->val.ival.type = T_Integer;
   18855      447814 :     n->val.ival.ival = val;
   18856      447814 :     n->location = location;
   18857             : 
   18858      447814 :     return (Node *) n;
   18859             : }
   18860             : 
   18861             : static Node *
   18862       11568 : makeFloatConst(char *str, int location)
   18863             : {
   18864       11568 :     A_Const    *n = makeNode(A_Const);
   18865             : 
   18866       11568 :     n->val.fval.type = T_Float;
   18867       11568 :     n->val.fval.fval = str;
   18868       11568 :     n->location = location;
   18869             : 
   18870       11568 :     return (Node *) n;
   18871             : }
   18872             : 
   18873             : static Node *
   18874       57768 : makeBoolAConst(bool state, int location)
   18875             : {
   18876       57768 :     A_Const    *n = makeNode(A_Const);
   18877             : 
   18878       57768 :     n->val.boolval.type = T_Boolean;
   18879       57768 :     n->val.boolval.boolval = state;
   18880       57768 :     n->location = location;
   18881             : 
   18882       57768 :     return (Node *) n;
   18883             : }
   18884             : 
   18885             : static Node *
   18886        4056 : makeBitStringConst(char *str, int location)
   18887             : {
   18888        4056 :     A_Const    *n = makeNode(A_Const);
   18889             : 
   18890        4056 :     n->val.bsval.type = T_BitString;
   18891        4056 :     n->val.bsval.bsval = str;
   18892        4056 :     n->location = location;
   18893             : 
   18894        4056 :     return (Node *) n;
   18895             : }
   18896             : 
   18897             : static Node *
   18898       62928 : makeNullAConst(int location)
   18899             : {
   18900       62928 :     A_Const    *n = makeNode(A_Const);
   18901             : 
   18902       62928 :     n->isnull = true;
   18903       62928 :     n->location = location;
   18904             : 
   18905       62928 :     return (Node *) n;
   18906             : }
   18907             : 
   18908             : static Node *
   18909        5078 : makeAConst(Node *v, int location)
   18910             : {
   18911             :     Node       *n;
   18912             : 
   18913        5078 :     switch (v->type)
   18914             :     {
   18915         218 :         case T_Float:
   18916         218 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18917         218 :             break;
   18918             : 
   18919        4860 :         case T_Integer:
   18920        4860 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18921        4860 :             break;
   18922             : 
   18923           0 :         default:
   18924             :             /* currently not used */
   18925             :             Assert(false);
   18926           0 :             n = NULL;
   18927             :     }
   18928             : 
   18929        5078 :     return n;
   18930             : }
   18931             : 
   18932             : /* makeRoleSpec
   18933             :  * Create a RoleSpec with the given type
   18934             :  */
   18935             : static RoleSpec *
   18936       30594 : makeRoleSpec(RoleSpecType type, int location)
   18937             : {
   18938       30594 :     RoleSpec   *spec = makeNode(RoleSpec);
   18939             : 
   18940       30594 :     spec->roletype = type;
   18941       30594 :     spec->location = location;
   18942             : 
   18943       30594 :     return spec;
   18944             : }
   18945             : 
   18946             : /* check_qualified_name --- check the result of qualified_name production
   18947             :  *
   18948             :  * It's easiest to let the grammar production for qualified_name allow
   18949             :  * subscripts and '*', which we then must reject here.
   18950             :  */
   18951             : static void
   18952      238890 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   18953             : {
   18954             :     ListCell   *i;
   18955             : 
   18956      477780 :     foreach(i, names)
   18957             :     {
   18958      238890 :         if (!IsA(lfirst(i), String))
   18959           0 :             parser_yyerror("syntax error");
   18960             :     }
   18961      238890 : }
   18962             : 
   18963             : /* check_func_name --- check the result of func_name production
   18964             :  *
   18965             :  * It's easiest to let the grammar production for func_name allow subscripts
   18966             :  * and '*', which we then must reject here.
   18967             :  */
   18968             : static List *
   18969      123714 : check_func_name(List *names, core_yyscan_t yyscanner)
   18970             : {
   18971             :     ListCell   *i;
   18972             : 
   18973      371142 :     foreach(i, names)
   18974             :     {
   18975      247428 :         if (!IsA(lfirst(i), String))
   18976           0 :             parser_yyerror("syntax error");
   18977             :     }
   18978      123714 :     return names;
   18979             : }
   18980             : 
   18981             : /* check_indirection --- check the result of indirection production
   18982             :  *
   18983             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   18984             :  * in the grammar, so do it here.
   18985             :  */
   18986             : static List *
   18987       80024 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   18988             : {
   18989             :     ListCell   *l;
   18990             : 
   18991      106172 :     foreach(l, indirection)
   18992             :     {
   18993       26148 :         if (IsA(lfirst(l), A_Star))
   18994             :         {
   18995        1360 :             if (lnext(indirection, l) != NULL)
   18996           0 :                 parser_yyerror("improper use of \"*\"");
   18997             :         }
   18998             :     }
   18999       80024 :     return indirection;
   19000             : }
   19001             : 
   19002             : /* extractArgTypes()
   19003             :  * Given a list of FunctionParameter nodes, extract a list of just the
   19004             :  * argument types (TypeNames) for input parameters only.  This is what
   19005             :  * is needed to look up an existing function, which is what is wanted by
   19006             :  * the productions that use this call.
   19007             :  */
   19008             : static List *
   19009       14792 : extractArgTypes(List *parameters)
   19010             : {
   19011       14792 :     List       *result = NIL;
   19012             :     ListCell   *i;
   19013             : 
   19014       32454 :     foreach(i, parameters)
   19015             :     {
   19016       17662 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   19017             : 
   19018       17662 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   19019       17506 :             result = lappend(result, p->argType);
   19020             :     }
   19021       14792 :     return result;
   19022             : }
   19023             : 
   19024             : /* extractAggrArgTypes()
   19025             :  * As above, but work from the output of the aggr_args production.
   19026             :  */
   19027             : static List *
   19028         362 : extractAggrArgTypes(List *aggrargs)
   19029             : {
   19030             :     Assert(list_length(aggrargs) == 2);
   19031         362 :     return extractArgTypes((List *) linitial(aggrargs));
   19032             : }
   19033             : 
   19034             : /* makeOrderedSetArgs()
   19035             :  * Build the result of the aggr_args production (which see the comments for).
   19036             :  * This handles only the case where both given lists are nonempty, so that
   19037             :  * we have to deal with multiple VARIADIC arguments.
   19038             :  */
   19039             : static List *
   19040          32 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19041             :                    core_yyscan_t yyscanner)
   19042             : {
   19043          32 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19044             :     Integer    *ndirectargs;
   19045             : 
   19046             :     /* No restriction unless last direct arg is VARIADIC */
   19047          32 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19048             :     {
   19049          16 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19050             : 
   19051             :         /*
   19052             :          * We ignore the names, though the aggr_arg production allows them; it
   19053             :          * doesn't allow default values, so those need not be checked.
   19054             :          */
   19055          16 :         if (list_length(orderedargs) != 1 ||
   19056          16 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19057          16 :             !equal(lastd->argType, firsto->argType))
   19058           0 :             ereport(ERROR,
   19059             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19060             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19061             :                      parser_errposition(firsto->location)));
   19062             : 
   19063             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19064          16 :         orderedargs = NIL;
   19065             :     }
   19066             : 
   19067             :     /* don't merge into the next line, as list_concat changes directargs */
   19068          32 :     ndirectargs = makeInteger(list_length(directargs));
   19069             : 
   19070          32 :     return list_make2(list_concat(directargs, orderedargs),
   19071             :                       ndirectargs);
   19072             : }
   19073             : 
   19074             : /* insertSelectOptions()
   19075             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19076             :  *
   19077             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19078             :  */
   19079             : static void
   19080       76404 : insertSelectOptions(SelectStmt *stmt,
   19081             :                     List *sortClause, List *lockingClause,
   19082             :                     SelectLimit *limitClause,
   19083             :                     WithClause *withClause,
   19084             :                     core_yyscan_t yyscanner)
   19085             : {
   19086             :     Assert(IsA(stmt, SelectStmt));
   19087             : 
   19088             :     /*
   19089             :      * Tests here are to reject constructs like
   19090             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19091             :      */
   19092       76404 :     if (sortClause)
   19093             :     {
   19094       67196 :         if (stmt->sortClause)
   19095           0 :             ereport(ERROR,
   19096             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19097             :                      errmsg("multiple ORDER BY clauses not allowed"),
   19098             :                      parser_errposition(exprLocation((Node *) sortClause))));
   19099       67196 :         stmt->sortClause = sortClause;
   19100             :     }
   19101             :     /* We can handle multiple locking clauses, though */
   19102       76404 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19103       76404 :     if (limitClause && limitClause->limitOffset)
   19104             :     {
   19105         826 :         if (stmt->limitOffset)
   19106           0 :             ereport(ERROR,
   19107             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19108             :                      errmsg("multiple OFFSET clauses not allowed"),
   19109             :                      parser_errposition(limitClause->offsetLoc)));
   19110         826 :         stmt->limitOffset = limitClause->limitOffset;
   19111             :     }
   19112       76404 :     if (limitClause && limitClause->limitCount)
   19113             :     {
   19114        4638 :         if (stmt->limitCount)
   19115           0 :             ereport(ERROR,
   19116             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19117             :                      errmsg("multiple LIMIT clauses not allowed"),
   19118             :                      parser_errposition(limitClause->countLoc)));
   19119        4638 :         stmt->limitCount = limitClause->limitCount;
   19120             :     }
   19121       76404 :     if (limitClause)
   19122             :     {
   19123             :         /* If there was a conflict, we must have detected it above */
   19124             :         Assert(!stmt->limitOption);
   19125        5070 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19126           6 :             ereport(ERROR,
   19127             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19128             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19129             :                      parser_errposition(limitClause->optionLoc)));
   19130        5064 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19131             :         {
   19132             :             ListCell   *lc;
   19133             : 
   19134           6 :             foreach(lc, stmt->lockingClause)
   19135             :             {
   19136           6 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19137             : 
   19138           6 :                 if (lock->waitPolicy == LockWaitSkip)
   19139           6 :                     ereport(ERROR,
   19140             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19141             :                              errmsg("%s and %s options cannot be used together",
   19142             :                                     "SKIP LOCKED", "WITH TIES"),
   19143             :                              parser_errposition(limitClause->optionLoc)));
   19144             :             }
   19145             :         }
   19146        5058 :         stmt->limitOption = limitClause->limitOption;
   19147             :     }
   19148       76392 :     if (withClause)
   19149             :     {
   19150        2766 :         if (stmt->withClause)
   19151           0 :             ereport(ERROR,
   19152             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19153             :                      errmsg("multiple WITH clauses not allowed"),
   19154             :                      parser_errposition(exprLocation((Node *) withClause))));
   19155        2766 :         stmt->withClause = withClause;
   19156             : 
   19157             :         /* Update SelectStmt's location to the start of the WITH clause */
   19158        2766 :         stmt->stmt_location = withClause->location;
   19159             :     }
   19160       76392 : }
   19161             : 
   19162             : static Node *
   19163       16008 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg, int location)
   19164             : {
   19165       16008 :     SelectStmt *n = makeNode(SelectStmt);
   19166             : 
   19167       16008 :     n->op = op;
   19168       16008 :     n->all = all;
   19169       16008 :     n->larg = (SelectStmt *) larg;
   19170       16008 :     n->rarg = (SelectStmt *) rarg;
   19171       16008 :     n->stmt_location = location;
   19172       16008 :     return (Node *) n;
   19173             : }
   19174             : 
   19175             : /* SystemFuncName()
   19176             :  * Build a properly-qualified reference to a built-in function.
   19177             :  */
   19178             : List *
   19179       18036 : SystemFuncName(char *name)
   19180             : {
   19181       18036 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19182             : }
   19183             : 
   19184             : /* SystemTypeName()
   19185             :  * Build a properly-qualified reference to a built-in type.
   19186             :  *
   19187             :  * typmod is defaulted, but may be changed afterwards by caller.
   19188             :  * Likewise for the location.
   19189             :  */
   19190             : TypeName *
   19191      116312 : SystemTypeName(char *name)
   19192             : {
   19193      116312 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19194             :                                                makeString(name)));
   19195             : }
   19196             : 
   19197             : /* doNegate()
   19198             :  * Handle negation of a numeric constant.
   19199             :  *
   19200             :  * Formerly, we did this here because the optimizer couldn't cope with
   19201             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19202             :  * and a unary minus operator applied to a constant didn't qualify.
   19203             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19204             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19205             :  * there's still a good reason for doing this here, which is that we can
   19206             :  * postpone committing to a particular internal representation for simple
   19207             :  * negative constants.  It's better to leave "-123.456" in string form
   19208             :  * until we know what the desired type is.
   19209             :  */
   19210             : static Node *
   19211       27762 : doNegate(Node *n, int location)
   19212             : {
   19213       27762 :     if (IsA(n, A_Const))
   19214             :     {
   19215       26776 :         A_Const    *con = (A_Const *) n;
   19216             : 
   19217             :         /* report the constant's location as that of the '-' sign */
   19218       26776 :         con->location = location;
   19219             : 
   19220       26776 :         if (IsA(&con->val, Integer))
   19221             :         {
   19222       25818 :             con->val.ival.ival = -con->val.ival.ival;
   19223       25818 :             return n;
   19224             :         }
   19225         958 :         if (IsA(&con->val, Float))
   19226             :         {
   19227         958 :             doNegateFloat(&con->val.fval);
   19228         958 :             return n;
   19229             :         }
   19230             :     }
   19231             : 
   19232         986 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19233             : }
   19234             : 
   19235             : static void
   19236         978 : doNegateFloat(Float *v)
   19237             : {
   19238         978 :     char       *oldval = v->fval;
   19239             : 
   19240         978 :     if (*oldval == '+')
   19241           0 :         oldval++;
   19242         978 :     if (*oldval == '-')
   19243           0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19244             :     else
   19245         978 :         v->fval = psprintf("-%s", oldval);
   19246         978 : }
   19247             : 
   19248             : static Node *
   19249      220042 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19250             : {
   19251             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19252      220042 :     if (IsA(lexpr, BoolExpr))
   19253             :     {
   19254      102258 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19255             : 
   19256      102258 :         if (blexpr->boolop == AND_EXPR)
   19257             :         {
   19258       99808 :             blexpr->args = lappend(blexpr->args, rexpr);
   19259       99808 :             return (Node *) blexpr;
   19260             :         }
   19261             :     }
   19262      120234 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19263             : }
   19264             : 
   19265             : static Node *
   19266       16598 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19267             : {
   19268             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19269       16598 :     if (IsA(lexpr, BoolExpr))
   19270             :     {
   19271        6902 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19272             : 
   19273        6902 :         if (blexpr->boolop == OR_EXPR)
   19274             :         {
   19275        3924 :             blexpr->args = lappend(blexpr->args, rexpr);
   19276        3924 :             return (Node *) blexpr;
   19277             :         }
   19278             :     }
   19279       12674 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19280             : }
   19281             : 
   19282             : static Node *
   19283       15268 : makeNotExpr(Node *expr, int location)
   19284             : {
   19285       15268 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19286             : }
   19287             : 
   19288             : static Node *
   19289        8024 : makeAArrayExpr(List *elements, int location)
   19290             : {
   19291        8024 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19292             : 
   19293        8024 :     n->elements = elements;
   19294        8024 :     n->location = location;
   19295        8024 :     return (Node *) n;
   19296             : }
   19297             : 
   19298             : static Node *
   19299        2800 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19300             : {
   19301        2800 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19302             : 
   19303        2800 :     svf->op = op;
   19304             :     /* svf->type will be filled during parse analysis */
   19305        2800 :     svf->typmod = typmod;
   19306        2800 :     svf->location = location;
   19307        2800 :     return (Node *) svf;
   19308             : }
   19309             : 
   19310             : static Node *
   19311         596 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19312             :             int location)
   19313             : {
   19314         596 :     XmlExpr    *x = makeNode(XmlExpr);
   19315             : 
   19316         596 :     x->op = op;
   19317         596 :     x->name = name;
   19318             : 
   19319             :     /*
   19320             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19321             :      * expression and name lists in transformXmlExpr().
   19322             :      */
   19323         596 :     x->named_args = named_args;
   19324         596 :     x->arg_names = NIL;
   19325         596 :     x->args = args;
   19326             :     /* xmloption, if relevant, must be filled in by caller */
   19327             :     /* type and typmod will be filled in during parse analysis */
   19328         596 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19329         596 :     x->location = location;
   19330         596 :     return (Node *) x;
   19331             : }
   19332             : 
   19333             : /*
   19334             :  * Merge the input and output parameters of a table function.
   19335             :  */
   19336             : static List *
   19337         188 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19338             : {
   19339             :     ListCell   *lc;
   19340             : 
   19341             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19342         382 :     foreach(lc, func_args)
   19343             :     {
   19344         194 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19345             : 
   19346         194 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19347           0 :             p->mode != FUNC_PARAM_IN &&
   19348           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19349           0 :             ereport(ERROR,
   19350             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19351             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19352             :                      parser_errposition(p->location)));
   19353             :     }
   19354             : 
   19355         188 :     return list_concat(func_args, columns);
   19356             : }
   19357             : 
   19358             : /*
   19359             :  * Determine return type of a TABLE function.  A single result column
   19360             :  * returns setof that column's type; otherwise return setof record.
   19361             :  */
   19362             : static TypeName *
   19363         188 : TableFuncTypeName(List *columns)
   19364             : {
   19365             :     TypeName   *result;
   19366             : 
   19367         188 :     if (list_length(columns) == 1)
   19368             :     {
   19369          62 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19370             : 
   19371          62 :         result = copyObject(p->argType);
   19372             :     }
   19373             :     else
   19374         126 :         result = SystemTypeName("record");
   19375             : 
   19376         188 :     result->setof = true;
   19377             : 
   19378         188 :     return result;
   19379             : }
   19380             : 
   19381             : /*
   19382             :  * Convert a list of (dotted) names to a RangeVar (like
   19383             :  * makeRangeVarFromNameList, but with position support).  The
   19384             :  * "AnyName" refers to the any_name production in the grammar.
   19385             :  */
   19386             : static RangeVar *
   19387        4732 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19388             : {
   19389        4732 :     RangeVar   *r = makeNode(RangeVar);
   19390             : 
   19391        4732 :     switch (list_length(names))
   19392             :     {
   19393        4642 :         case 1:
   19394        4642 :             r->catalogname = NULL;
   19395        4642 :             r->schemaname = NULL;
   19396        4642 :             r->relname = strVal(linitial(names));
   19397        4642 :             break;
   19398          90 :         case 2:
   19399          90 :             r->catalogname = NULL;
   19400          90 :             r->schemaname = strVal(linitial(names));
   19401          90 :             r->relname = strVal(lsecond(names));
   19402          90 :             break;
   19403           0 :         case 3:
   19404           0 :             r->catalogname = strVal(linitial(names));
   19405           0 :             r->schemaname = strVal(lsecond(names));
   19406           0 :             r->relname = strVal(lthird(names));
   19407           0 :             break;
   19408           0 :         default:
   19409           0 :             ereport(ERROR,
   19410             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19411             :                      errmsg("improper qualified name (too many dotted names): %s",
   19412             :                             NameListToString(names)),
   19413             :                      parser_errposition(position)));
   19414             :             break;
   19415             :     }
   19416             : 
   19417        4732 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19418        4732 :     r->location = position;
   19419             : 
   19420        4732 :     return r;
   19421             : }
   19422             : 
   19423             : /*
   19424             :  * Convert a relation_name with name and namelist to a RangeVar using
   19425             :  * makeRangeVar.
   19426             :  */
   19427             : static RangeVar *
   19428      238890 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19429             :                               core_yyscan_t yyscanner)
   19430             : {
   19431             :     RangeVar   *r;
   19432             : 
   19433      238890 :     check_qualified_name(namelist, yyscanner);
   19434      238890 :     r = makeRangeVar(NULL, NULL, location);
   19435             : 
   19436      238890 :     switch (list_length(namelist))
   19437             :     {
   19438      238890 :         case 1:
   19439      238890 :             r->catalogname = NULL;
   19440      238890 :             r->schemaname = name;
   19441      238890 :             r->relname = strVal(linitial(namelist));
   19442      238890 :             break;
   19443           0 :         case 2:
   19444           0 :             r->catalogname = name;
   19445           0 :             r->schemaname = strVal(linitial(namelist));
   19446           0 :             r->relname = strVal(lsecond(namelist));
   19447           0 :             break;
   19448           0 :         default:
   19449           0 :             ereport(ERROR,
   19450             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19451             :                     errmsg("improper qualified name (too many dotted names): %s",
   19452             :                            NameListToString(lcons(makeString(name), namelist))),
   19453             :                     parser_errposition(location));
   19454             :             break;
   19455             :     }
   19456             : 
   19457      238890 :     return r;
   19458             : }
   19459             : 
   19460             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19461             : static void
   19462       67924 : SplitColQualList(List *qualList,
   19463             :                  List **constraintList, CollateClause **collClause,
   19464             :                  core_yyscan_t yyscanner)
   19465             : {
   19466             :     ListCell   *cell;
   19467             : 
   19468       67924 :     *collClause = NULL;
   19469       87350 :     foreach(cell, qualList)
   19470             :     {
   19471       19426 :         Node       *n = (Node *) lfirst(cell);
   19472             : 
   19473       19426 :         if (IsA(n, Constraint))
   19474             :         {
   19475             :             /* keep it in list */
   19476       18684 :             continue;
   19477             :         }
   19478         742 :         if (IsA(n, CollateClause))
   19479             :         {
   19480         742 :             CollateClause *c = (CollateClause *) n;
   19481             : 
   19482         742 :             if (*collClause)
   19483           0 :                 ereport(ERROR,
   19484             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19485             :                          errmsg("multiple COLLATE clauses not allowed"),
   19486             :                          parser_errposition(c->location)));
   19487         742 :             *collClause = c;
   19488             :         }
   19489             :         else
   19490           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19491             :         /* remove non-Constraint nodes from qualList */
   19492         742 :         qualList = foreach_delete_current(qualList, cell);
   19493             :     }
   19494       67924 :     *constraintList = qualList;
   19495       67924 : }
   19496             : 
   19497             : /*
   19498             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19499             :  * in the output command node.  Pass NULL for any flags the particular
   19500             :  * command doesn't support.
   19501             :  */
   19502             : static void
   19503       16290 : processCASbits(int cas_bits, int location, const char *constrType,
   19504             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19505             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19506             : {
   19507             :     /* defaults */
   19508       16290 :     if (deferrable)
   19509       14500 :         *deferrable = false;
   19510       16290 :     if (initdeferred)
   19511       14500 :         *initdeferred = false;
   19512       16290 :     if (not_valid)
   19513        3134 :         *not_valid = false;
   19514       16290 :     if (is_enforced)
   19515        1200 :         *is_enforced = true;
   19516             : 
   19517       16290 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19518             :     {
   19519         224 :         if (deferrable)
   19520         224 :             *deferrable = true;
   19521             :         else
   19522           0 :             ereport(ERROR,
   19523             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19524             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19525             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19526             :                             constrType),
   19527             :                      parser_errposition(location)));
   19528             :     }
   19529             : 
   19530       16290 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19531             :     {
   19532         140 :         if (initdeferred)
   19533         140 :             *initdeferred = true;
   19534             :         else
   19535           0 :             ereport(ERROR,
   19536             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19537             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19538             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19539             :                             constrType),
   19540             :                      parser_errposition(location)));
   19541             :     }
   19542             : 
   19543       16290 :     if (cas_bits & CAS_NOT_VALID)
   19544             :     {
   19545         548 :         if (not_valid)
   19546         542 :             *not_valid = true;
   19547             :         else
   19548           6 :             ereport(ERROR,
   19549             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19550             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19551             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19552             :                             constrType),
   19553             :                      parser_errposition(location)));
   19554             :     }
   19555             : 
   19556       16284 :     if (cas_bits & CAS_NO_INHERIT)
   19557             :     {
   19558         220 :         if (no_inherit)
   19559         220 :             *no_inherit = true;
   19560             :         else
   19561           0 :             ereport(ERROR,
   19562             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19563             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19564             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19565             :                             constrType),
   19566             :                      parser_errposition(location)));
   19567             :     }
   19568             : 
   19569       16284 :     if (cas_bits & CAS_NOT_ENFORCED)
   19570             :     {
   19571          84 :         if (is_enforced)
   19572          72 :             *is_enforced = false;
   19573             :         else
   19574          12 :             ereport(ERROR,
   19575             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19576             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19577             :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19578             :                             constrType),
   19579             :                      parser_errposition(location)));
   19580             : 
   19581             :         /*
   19582             :          * NB: The validated status is irrelevant when the constraint is set to
   19583             :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19584             :          * This ensures that if the constraint is later changed to ENFORCED, it
   19585             :          * will automatically be in the correct NOT VALIDATED state.
   19586             :          */
   19587          72 :         if (not_valid)
   19588          72 :             *not_valid = true;
   19589             :     }
   19590             : 
   19591       16272 :     if (cas_bits & CAS_ENFORCED)
   19592             :     {
   19593          42 :         if (is_enforced)
   19594          30 :             *is_enforced = true;
   19595             :         else
   19596          12 :             ereport(ERROR,
   19597             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19598             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19599             :                      errmsg("%s constraints cannot be marked ENFORCED",
   19600             :                             constrType),
   19601             :                      parser_errposition(location)));
   19602             :     }
   19603       16260 : }
   19604             : 
   19605             : /*
   19606             :  * Parse a user-supplied partition strategy string into parse node
   19607             :  * PartitionStrategy representation, or die trying.
   19608             :  */
   19609             : static PartitionStrategy
   19610        4928 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19611             : {
   19612        4928 :     if (pg_strcasecmp(strategy, "list") == 0)
   19613        2506 :         return PARTITION_STRATEGY_LIST;
   19614        2422 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19615        2176 :         return PARTITION_STRATEGY_RANGE;
   19616         246 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19617         240 :         return PARTITION_STRATEGY_HASH;
   19618             : 
   19619           6 :     ereport(ERROR,
   19620             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19621             :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19622             :              parser_errposition(location)));
   19623             :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19624             : 
   19625             : }
   19626             : 
   19627             : /*
   19628             :  * Process pubobjspec_list to check for errors in any of the objects and
   19629             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   19630             :  */
   19631             : static void
   19632        1584 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   19633             : {
   19634             :     ListCell   *cell;
   19635             :     PublicationObjSpec *pubobj;
   19636        1584 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   19637             : 
   19638        1584 :     if (!pubobjspec_list)
   19639           0 :         return;
   19640             : 
   19641        1584 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   19642        1584 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19643          12 :         ereport(ERROR,
   19644             :                 errcode(ERRCODE_SYNTAX_ERROR),
   19645             :                 errmsg("invalid publication object list"),
   19646             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   19647             :                 parser_errposition(pubobj->location));
   19648             : 
   19649        3342 :     foreach(cell, pubobjspec_list)
   19650             :     {
   19651        1794 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   19652             : 
   19653        1794 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   19654         172 :             pubobj->pubobjtype = prevobjtype;
   19655             : 
   19656        1794 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   19657             :         {
   19658             :             /* relation name or pubtable must be set for this type of object */
   19659        1390 :             if (!pubobj->name && !pubobj->pubtable)
   19660           6 :                 ereport(ERROR,
   19661             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19662             :                         errmsg("invalid table name"),
   19663             :                         parser_errposition(pubobj->location));
   19664             : 
   19665        1384 :             if (pubobj->name)
   19666             :             {
   19667             :                 /* convert it to PublicationTable */
   19668          56 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   19669             : 
   19670          56 :                 pubtable->relation =
   19671          56 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   19672          56 :                 pubobj->pubtable = pubtable;
   19673          56 :                 pubobj->name = NULL;
   19674             :             }
   19675             :         }
   19676         404 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   19677          24 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   19678             :         {
   19679             :             /* WHERE clause is not allowed on a schema object */
   19680         404 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   19681           6 :                 ereport(ERROR,
   19682             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19683             :                         errmsg("WHERE clause not allowed for schema"),
   19684             :                         parser_errposition(pubobj->location));
   19685             : 
   19686             :             /* Column list is not allowed on a schema object */
   19687         398 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   19688           6 :                 ereport(ERROR,
   19689             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19690             :                         errmsg("column specification not allowed for schema"),
   19691             :                         parser_errposition(pubobj->location));
   19692             : 
   19693             :             /*
   19694             :              * We can distinguish between the different type of schema objects
   19695             :              * based on whether name and pubtable is set.
   19696             :              */
   19697         392 :             if (pubobj->name)
   19698         362 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   19699          30 :             else if (!pubobj->name && !pubobj->pubtable)
   19700          24 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   19701             :             else
   19702           6 :                 ereport(ERROR,
   19703             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19704             :                         errmsg("invalid schema name"),
   19705             :                         parser_errposition(pubobj->location));
   19706             :         }
   19707             : 
   19708        1770 :         prevobjtype = pubobj->pubobjtype;
   19709             :     }
   19710             : }
   19711             : 
   19712             : /*----------
   19713             :  * Recursive view transformation
   19714             :  *
   19715             :  * Convert
   19716             :  *
   19717             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   19718             :  *
   19719             :  * to
   19720             :  *
   19721             :  *     CREATE VIEW relname (aliases) AS
   19722             :  *         WITH RECURSIVE relname (aliases) AS (query)
   19723             :  *         SELECT aliases FROM relname
   19724             :  *
   19725             :  * Actually, just the WITH ... part, which is then inserted into the original
   19726             :  * view definition as the query.
   19727             :  * ----------
   19728             :  */
   19729             : static Node *
   19730          14 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   19731             : {
   19732          14 :     SelectStmt *s = makeNode(SelectStmt);
   19733          14 :     WithClause *w = makeNode(WithClause);
   19734          14 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   19735          14 :     List       *tl = NIL;
   19736             :     ListCell   *lc;
   19737             : 
   19738             :     /* create common table expression */
   19739          14 :     cte->ctename = relname;
   19740          14 :     cte->aliascolnames = aliases;
   19741          14 :     cte->ctematerialized = CTEMaterializeDefault;
   19742          14 :     cte->ctequery = query;
   19743          14 :     cte->location = -1;
   19744             : 
   19745             :     /* create WITH clause and attach CTE */
   19746          14 :     w->recursive = true;
   19747          14 :     w->ctes = list_make1(cte);
   19748          14 :     w->location = -1;
   19749             : 
   19750             :     /*
   19751             :      * create target list for the new SELECT from the alias list of the
   19752             :      * recursive view specification
   19753             :      */
   19754          28 :     foreach(lc, aliases)
   19755             :     {
   19756          14 :         ResTarget  *rt = makeNode(ResTarget);
   19757             : 
   19758          14 :         rt->name = NULL;
   19759          14 :         rt->indirection = NIL;
   19760          14 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   19761          14 :         rt->location = -1;
   19762             : 
   19763          14 :         tl = lappend(tl, rt);
   19764             :     }
   19765             : 
   19766             :     /*
   19767             :      * create new SELECT combining WITH clause, target list, and fake FROM
   19768             :      * clause
   19769             :      */
   19770          14 :     s->withClause = w;
   19771          14 :     s->targetList = tl;
   19772          14 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   19773             : 
   19774          14 :     return (Node *) s;
   19775             : }
   19776             : 
   19777             : /* parser_init()
   19778             :  * Initialize to parse one query string
   19779             :  */
   19780             : void
   19781      800972 : parser_init(base_yy_extra_type *yyext)
   19782             : {
   19783      800972 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   19784      800972 : }

Generated by: LCOV version 1.14