LCOV - differential code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Coverage Total Hit UNC LBC UIC UBC GBC GIC GNC CBC EUB ECB DUB DCB
Current: Differential Code Coverage HEAD vs 15 Lines: 89.5 % 7120 6375 7 274 408 56 268 3590 210 2307 418 3730 3 64
Current Date: 2023-04-08 15:15:32 Functions: 100.0 % 41 41 40 1 40 1
Baseline: 15
Baseline Date: 2023-04-08 15:09:40
Legend: Lines: hit not hit

           TLA  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-2023, PostgreSQL Global Development Group
      10                 :  * Portions Copyright (c) 1994, Regents of the University of California
      11                 :  *
      12                 :  *
      13                 :  * IDENTIFICATION
      14                 :  *    src/backend/parser/gram.y
      15                 :  *
      16                 :  * HISTORY
      17                 :  *    AUTHOR            DATE            MAJOR EVENT
      18                 :  *    Andrew Yu         Sept, 1994      POSTQUEL to SQL conversion
      19                 :  *    Andrew Yu         Oct, 1994       lispy code conversion
      20                 :  *
      21                 :  * NOTES
      22                 :  *    CAPITALS are used to represent terminal symbols.
      23                 :  *    non-capitals are used to represent non-terminals.
      24                 :  *
      25                 :  *    In general, nothing in this file should initiate database accesses
      26                 :  *    nor depend on changeable state (such as SET variables).  If you do
      27                 :  *    database accesses, your code will fail when we have aborted the
      28                 :  *    current transaction and are just parsing commands to find the next
      29                 :  *    ROLLBACK or COMMIT.  If you make use of SET variables, then you
      30                 :  *    will do the wrong thing in multi-query strings like this:
      31                 :  *          SET constraint_exclusion TO off; SELECT * FROM foo;
      32                 :  *    because the entire string is parsed by gram.y before the SET gets
      33                 :  *    executed.  Anything that depends on the database or changeable state
      34                 :  *    should be handled during parse analysis so that it happens at the
      35                 :  *    right time not the wrong time.
      36                 :  *
      37                 :  * WARNINGS
      38                 :  *    If you use a list, make sure the datum is a node so that the printing
      39                 :  *    routines work.
      40                 :  *
      41                 :  *    Sometimes we assign constants to makeStrings. Make sure we don't free
      42                 :  *    those.
      43                 :  *
      44                 :  *-------------------------------------------------------------------------
      45                 :  */
      46                 : #include "postgres.h"
      47                 : 
      48                 : #include <ctype.h>
      49                 : #include <limits.h>
      50                 : 
      51                 : #include "access/tableam.h"
      52                 : #include "catalog/index.h"
      53                 : #include "catalog/namespace.h"
      54                 : #include "catalog/pg_am.h"
      55                 : #include "catalog/pg_trigger.h"
      56                 : #include "commands/defrem.h"
      57                 : #include "commands/trigger.h"
      58                 : #include "gramparse.h"
      59                 : #include "nodes/makefuncs.h"
      60                 : #include "nodes/nodeFuncs.h"
      61                 : #include "parser/parser.h"
      62                 : #include "storage/lmgr.h"
      63                 : #include "utils/date.h"
      64                 : #include "utils/datetime.h"
      65                 : #include "utils/numeric.h"
      66                 : #include "utils/xml.h"
      67                 : 
      68                 : 
      69                 : /*
      70                 :  * Location tracking support --- simpler than bison's default, since we only
      71                 :  * want to track the start position not the end position of each nonterminal.
      72                 :  */
      73                 : #define YYLLOC_DEFAULT(Current, Rhs, N) \
      74                 :     do { \
      75                 :         if ((N) > 0) \
      76                 :             (Current) = (Rhs)[1]; \
      77                 :         else \
      78                 :             (Current) = (-1); \
      79                 :     } while (0)
      80                 : 
      81                 : /*
      82                 :  * The above macro assigns -1 (unknown) as the parse location of any
      83                 :  * nonterminal that was reduced from an empty rule, or whose leftmost
      84                 :  * component was reduced from an empty rule.  This is problematic
      85                 :  * for nonterminals defined like
      86                 :  *      OptFooList: / * EMPTY * / { ... } | OptFooList Foo { ... } ;
      87                 :  * because we'll set -1 as the location during the first reduction and then
      88                 :  * copy it during each subsequent reduction, leaving us with -1 for the
      89                 :  * location even when the list is not empty.  To fix that, do this in the
      90                 :  * action for the nonempty rule(s):
      91                 :  *      if (@$ < 0) @$ = @2;
      92                 :  * (Although we have many nonterminals that follow this pattern, we only
      93                 :  * bother with fixing @$ like this when the nonterminal's parse location
      94                 :  * is actually referenced in some rule.)
      95                 :  *
      96                 :  * A cleaner answer would be to make YYLLOC_DEFAULT scan all the Rhs
      97                 :  * locations until it's found one that's not -1.  Then we'd get a correct
      98                 :  * location for any nonterminal that isn't entirely empty.  But this way
      99                 :  * would add overhead to every rule reduction, and so far there's not been
     100                 :  * a compelling reason to pay that overhead.
     101                 :  */
     102                 : 
     103                 : /*
     104                 :  * Bison doesn't allocate anything that needs to live across parser calls,
     105                 :  * so we can easily have it use palloc instead of malloc.  This prevents
     106                 :  * memory leaks if we error out during parsing.
     107                 :  */
     108                 : #define YYMALLOC palloc
     109                 : #define YYFREE   pfree
     110                 : 
     111                 : /* Private struct for the result of privilege_target production */
     112                 : typedef struct PrivTarget
     113                 : {
     114                 :     GrantTargetType targtype;
     115                 :     ObjectType  objtype;
     116                 :     List       *objs;
     117                 : } PrivTarget;
     118                 : 
     119                 : /* Private struct for the result of import_qualification production */
     120                 : typedef struct ImportQual
     121                 : {
     122                 :     ImportForeignSchemaType type;
     123                 :     List       *table_names;
     124                 : } ImportQual;
     125                 : 
     126                 : /* Private struct for the result of opt_select_limit production */
     127                 : typedef struct SelectLimit
     128                 : {
     129                 :     Node       *limitOffset;
     130                 :     Node       *limitCount;
     131                 :     LimitOption limitOption;
     132                 : } SelectLimit;
     133                 : 
     134                 : /* Private struct for the result of group_clause production */
     135                 : typedef struct GroupClause
     136                 : {
     137                 :     bool        distinct;
     138                 :     List       *list;
     139                 : } GroupClause;
     140                 : 
     141                 : /* Private structs for the result of key_actions and key_action productions */
     142                 : typedef struct KeyAction
     143                 : {
     144                 :     char        action;
     145                 :     List       *cols;
     146                 : } KeyAction;
     147                 : 
     148                 : typedef struct KeyActions
     149                 : {
     150                 :     KeyAction *updateAction;
     151                 :     KeyAction *deleteAction;
     152                 : } KeyActions;
     153                 : 
     154                 : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
     155                 : #define CAS_NOT_DEFERRABLE          0x01
     156                 : #define CAS_DEFERRABLE              0x02
     157                 : #define CAS_INITIALLY_IMMEDIATE     0x04
     158                 : #define CAS_INITIALLY_DEFERRED      0x08
     159                 : #define CAS_NOT_VALID               0x10
     160                 : #define CAS_NO_INHERIT              0x20
     161                 : 
     162                 : 
     163                 : #define parser_yyerror(msg)  scanner_yyerror(msg, yyscanner)
     164                 : #define parser_errposition(pos)  scanner_errposition(pos, yyscanner)
     165                 : 
     166                 : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
     167                 :                          const char *msg);
     168                 : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
     169                 : static void updateRawStmtEnd(RawStmt *rs, int end_location);
     170                 : static Node *makeColumnRef(char *colname, List *indirection,
     171                 :                            int location, core_yyscan_t yyscanner);
     172                 : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
     173                 : static Node *makeStringConst(char *str, int location);
     174                 : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
     175                 : static Node *makeIntConst(int val, int location);
     176                 : static Node *makeFloatConst(char *str, int location);
     177                 : static Node *makeBoolAConst(bool state, int location);
     178                 : static Node *makeBitStringConst(char *str, int location);
     179                 : static Node *makeNullAConst(int location);
     180                 : static Node *makeAConst(Node *v, int location);
     181                 : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
     182                 : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
     183                 : static List *check_func_name(List *names, core_yyscan_t yyscanner);
     184                 : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
     185                 : static List *extractArgTypes(List *parameters);
     186                 : static List *extractAggrArgTypes(List *aggrargs);
     187                 : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
     188                 :                                 core_yyscan_t yyscanner);
     189                 : static void insertSelectOptions(SelectStmt *stmt,
     190                 :                                 List *sortClause, List *lockingClause,
     191                 :                                 SelectLimit *limitClause,
     192                 :                                 WithClause *withClause,
     193                 :                                 core_yyscan_t yyscanner);
     194                 : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
     195                 : static Node *doNegate(Node *n, int location);
     196                 : static void doNegateFloat(Float *v);
     197                 : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
     198                 : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
     199                 : static Node *makeNotExpr(Node *expr, int location);
     200                 : static Node *makeAArrayExpr(List *elements, int location);
     201                 : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
     202                 :                          List *args, int location);
     203                 : static List *mergeTableFuncParameters(List *func_args, List *columns);
     204                 : static TypeName *TableFuncTypeName(List *columns);
     205                 : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
     206                 : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
     207                 :                                                core_yyscan_t yyscanner);
     208                 : static void SplitColQualList(List *qualList,
     209                 :                              List **constraintList, CollateClause **collClause,
     210                 :                              core_yyscan_t yyscanner);
     211                 : static void processCASbits(int cas_bits, int location, const char *constrType,
     212                 :                bool *deferrable, bool *initdeferred, bool *not_valid,
     213                 :                bool *no_inherit, core_yyscan_t yyscanner);
     214                 : static PartitionStrategy parsePartitionStrategy(char *strategy);
     215                 : static void preprocess_pubobj_list(List *pubobjspec_list,
     216                 :                                    core_yyscan_t yyscanner);
     217                 : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     218                 : 
     219                 : %}
     220                 : 
     221                 : %pure-parser
     222                 : %expect 0
     223                 : %name-prefix="base_yy"
     224                 : %locations
     225                 : 
     226                 : %parse-param {core_yyscan_t yyscanner}
     227                 : %lex-param   {core_yyscan_t yyscanner}
     228                 : 
     229                 : %union
     230                 : {
     231                 :     core_YYSTYPE core_yystype;
     232                 :     /* these fields must match core_YYSTYPE: */
     233                 :     int         ival;
     234                 :     char       *str;
     235                 :     const char *keyword;
     236                 : 
     237                 :     char        chr;
     238                 :     bool        boolean;
     239                 :     JoinType    jtype;
     240                 :     DropBehavior dbehavior;
     241                 :     OnCommitAction oncommit;
     242                 :     List       *list;
     243                 :     Node       *node;
     244                 :     ObjectType  objtype;
     245                 :     TypeName   *typnam;
     246                 :     FunctionParameter *fun_param;
     247                 :     FunctionParameterMode fun_param_mode;
     248                 :     ObjectWithArgs *objwithargs;
     249                 :     DefElem    *defelt;
     250                 :     SortBy     *sortby;
     251                 :     WindowDef  *windef;
     252                 :     JoinExpr   *jexpr;
     253                 :     IndexElem  *ielem;
     254                 :     StatsElem  *selem;
     255                 :     Alias      *alias;
     256                 :     RangeVar   *range;
     257                 :     IntoClause *into;
     258                 :     WithClause *with;
     259                 :     InferClause *infer;
     260                 :     OnConflictClause *onconflict;
     261                 :     A_Indices  *aind;
     262                 :     ResTarget  *target;
     263                 :     struct PrivTarget *privtarget;
     264                 :     AccessPriv *accesspriv;
     265                 :     struct ImportQual *importqual;
     266                 :     InsertStmt *istmt;
     267                 :     VariableSetStmt *vsetstmt;
     268                 :     PartitionElem *partelem;
     269                 :     PartitionSpec *partspec;
     270                 :     PartitionBoundSpec *partboundspec;
     271                 :     RoleSpec   *rolespec;
     272                 :     PublicationObjSpec *publicationobjectspec;
     273                 :     struct SelectLimit *selectlimit;
     274                 :     SetQuantifier setquantifier;
     275                 :     struct GroupClause *groupclause;
     276                 :     MergeWhenClause *mergewhen;
     277                 :     struct KeyActions *keyactions;
     278                 :     struct KeyAction *keyaction;
     279                 : }
     280                 : 
     281                 : %type <node>  stmt toplevel_stmt schema_stmt routine_body_stmt
     282                 :         AlterEventTrigStmt AlterCollationStmt
     283                 :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     284                 :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     285                 :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     286                 :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     287                 :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
     288                 :         AlterCompositeTypeStmt AlterUserMappingStmt
     289                 :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     290                 :         AlterDefaultPrivilegesStmt DefACLAction
     291                 :         AnalyzeStmt CallStmt ClosePortalStmt ClusterStmt CommentStmt
     292                 :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     293                 :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     294                 :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     295                 :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     296                 :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     297                 :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     298                 :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     299                 :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     300                 :         DropOpClassStmt DropOpFamilyStmt DropStmt
     301                 :         DropCastStmt DropRoleStmt
     302                 :         DropdbStmt DropTableSpaceStmt
     303                 :         DropTransformStmt
     304                 :         DropUserMappingStmt ExplainStmt FetchStmt
     305                 :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     306                 :         ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
     307                 :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     308                 :         RemoveFuncStmt RemoveOperStmt RenameStmt ReturnStmt RevokeStmt RevokeRoleStmt
     309                 :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     310                 :         SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
     311                 :         UnlistenStmt UpdateStmt VacuumStmt
     312                 :         VariableResetStmt VariableSetStmt VariableShowStmt
     313                 :         ViewStmt CheckPointStmt CreateConversionStmt
     314                 :         DeallocateStmt PrepareStmt ExecuteStmt
     315                 :         DropOwnedStmt ReassignOwnedStmt
     316                 :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     317                 :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     318                 :         CreatePublicationStmt AlterPublicationStmt
     319                 :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     320                 : 
     321                 : %type <node>  select_no_parens select_with_parens select_clause
     322                 :                 simple_select values_clause
     323                 :                 PLpgSQL_Expr PLAssignStmt
     324                 : 
     325                 : %type <str>           opt_single_name
     326                 : %type <list>      opt_qualified_name
     327                 : %type <boolean>       opt_concurrently
     328                 : %type <dbehavior> opt_drop_behavior
     329                 : 
     330                 : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     331                 : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     332                 : 
     333                 : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     334                 :        replica_identity partition_cmd index_partition_cmd
     335                 : %type <list>  alter_table_cmds alter_type_cmds
     336                 : %type <list>    alter_identity_column_option_list
     337                 : %type <defelt>  alter_identity_column_option
     338                 : 
     339                 : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     340                 :                 transaction_mode_list
     341                 :                 create_extension_opt_list alter_extension_opt_list
     342                 : %type <defelt>    createdb_opt_item copy_opt_item
     343                 :                 transaction_mode_item
     344                 :                 create_extension_opt_item alter_extension_opt_item
     345                 : 
     346                 : %type <ival>  opt_lock lock_type cast_context
     347                 : %type <str>       utility_option_name
     348                 : %type <defelt>    utility_option_elem
     349                 : %type <list>  utility_option_list
     350                 : %type <node>  utility_option_arg
     351                 : %type <defelt>    drop_option
     352                 : %type <boolean>   opt_or_replace opt_no
     353                 :                 opt_grant_grant_option
     354                 :                 opt_nowait opt_if_exists opt_with_data
     355                 :                 opt_transaction_chain
     356                 : %type <list>  grant_role_opt_list
     357                 : %type <defelt>    grant_role_opt
     358                 : %type <node>  grant_role_opt_value
     359                 : %type <ival>  opt_nowait_or_skip
     360                 : 
     361                 : %type <list>  OptRoleList AlterOptRoleList
     362                 : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     363                 : 
     364                 : %type <str>       opt_type
     365                 : %type <str>       foreign_server_version opt_foreign_server_version
     366                 : %type <str>       opt_in_database
     367                 : 
     368                 : %type <str>       parameter_name
     369                 : %type <list>  OptSchemaEltList parameter_name_list
     370                 : 
     371                 : %type <chr>       am_type
     372                 : 
     373                 : %type <boolean> TriggerForSpec TriggerForType
     374                 : %type <ival>  TriggerActionTime
     375                 : %type <list>  TriggerEvents TriggerOneEvent
     376                 : %type <node>  TriggerFuncArg
     377                 : %type <node>  TriggerWhen
     378                 : %type <str>       TransitionRelName
     379                 : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     380                 : %type <node>  TriggerTransition
     381                 : 
     382                 : %type <list>  event_trigger_when_list event_trigger_value_list
     383                 : %type <defelt>    event_trigger_when_item
     384                 : %type <chr>       enable_trigger
     385                 : 
     386                 : %type <str>       copy_file_name
     387                 :                 access_method_clause attr_name
     388                 :                 table_access_method_clause name cursor_name file_name
     389                 :                 cluster_index_specification
     390                 : 
     391                 : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     392                 :                 opt_inline_handler opt_validator validator_clause
     393                 :                 opt_collate
     394                 : 
     395                 : %type <range> qualified_name insert_target OptConstrFromTable
     396                 : 
     397                 : %type <str>       all_Op MathOp
     398                 : 
     399                 : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     400                 : %type <boolean> RowSecurityDefaultPermissive
     401                 : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     402                 : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     403                 : 
     404                 : %type <str>       iso_level opt_encoding
     405                 : %type <rolespec> grantee
     406                 : %type <list>  grantee_list
     407                 : %type <accesspriv> privilege
     408                 : %type <list>  privileges privilege_list
     409                 : %type <privtarget> privilege_target
     410                 : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     411                 : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     412                 : %type <ival>  defacl_privilege_target
     413                 : %type <defelt>    DefACLOption
     414                 : %type <list>  DefACLOptionList
     415                 : %type <ival>  import_qualification_type
     416                 : %type <importqual> import_qualification
     417                 : %type <node>  vacuum_relation
     418                 : %type <selectlimit> opt_select_limit select_limit limit_clause
     419                 : 
     420                 : %type <list>  parse_toplevel stmtmulti routine_body_stmt_list
     421                 :                 OptTableElementList TableElementList OptInherit definition
     422                 :                 OptTypedTableElementList TypedTableElementList
     423                 :                 reloptions opt_reloptions
     424                 :                 OptWith opt_definition func_args func_args_list
     425                 :                 func_args_with_defaults func_args_with_defaults_list
     426                 :                 aggr_args aggr_args_list
     427                 :                 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
     428                 :                 old_aggr_definition old_aggr_list
     429                 :                 oper_argtypes RuleActionList RuleActionMulti
     430                 :                 opt_column_list columnList opt_name_list
     431                 :                 sort_clause opt_sort_clause sortby_list index_params
     432                 :                 stats_params
     433                 :                 opt_include opt_c_include index_including_params
     434                 :                 name_list role_list from_clause from_list opt_array_bounds
     435                 :                 qualified_name_list any_name any_name_list type_name_list
     436                 :                 any_operator expr_list attrs
     437                 :                 distinct_clause opt_distinct_clause
     438                 :                 target_list opt_target_list insert_column_list set_target_list
     439                 :                 merge_values_clause
     440                 :                 set_clause_list set_clause
     441                 :                 def_list operator_def_list indirection opt_indirection
     442                 :                 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
     443                 :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     444                 :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     445                 :                 prep_type_clause
     446                 :                 execute_param_clause using_clause returning_clause
     447                 :                 opt_enum_val_list enum_val_list table_func_column_list
     448                 :                 create_generic_options alter_generic_options
     449                 :                 relation_expr_list dostmt_opt_list
     450                 :                 transform_element_list transform_type_list
     451                 :                 TriggerTransitions TriggerReferencing
     452                 :                 vacuum_relation_list opt_vacuum_relation_list
     453                 :                 drop_option_list pub_obj_list
     454                 : 
     455                 : %type <node>  opt_routine_body
     456                 : %type <groupclause> group_clause
     457                 : %type <list>  group_by_list
     458                 : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     459                 : %type <node>  grouping_sets_clause
     460                 : 
     461                 : %type <list>  opt_fdw_options fdw_options
     462                 : %type <defelt>    fdw_option
     463                 : 
     464                 : %type <range> OptTempTableName
     465                 : %type <into>  into_clause create_as_target create_mv_target
     466                 : 
     467                 : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     468                 : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     469                 : %type <fun_param_mode> arg_class
     470                 : %type <typnam>    func_return func_type
     471                 : 
     472                 : %type <boolean>  opt_trusted opt_restart_seqs
     473                 : %type <ival>   OptTemp
     474                 : %type <ival>   OptNoLog
     475                 : %type <oncommit> OnCommitOption
     476                 : 
     477                 : %type <ival>  for_locking_strength
     478                 : %type <node>  for_locking_item
     479                 : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     480                 : %type <list>  locked_rels_list
     481                 : %type <setquantifier> set_quantifier
     482                 : 
     483                 : %type <node>  join_qual
     484                 : %type <jtype> join_type
     485                 : 
     486                 : %type <list>  extract_list overlay_list position_list
     487                 : %type <list>  substr_list trim_list
     488                 : %type <list>  opt_interval interval_second
     489                 : %type <str>       unicode_normal_form
     490                 : 
     491                 : %type <boolean> opt_instead
     492                 : %type <boolean> opt_unique opt_verbose opt_full
     493                 : %type <boolean> opt_freeze opt_analyze opt_default opt_recheck
     494                 : %type <defelt>    opt_binary copy_delimiter
     495                 : 
     496                 : %type <boolean> copy_from opt_program
     497                 : 
     498                 : %type <ival>  event cursor_options opt_hold opt_set_data
     499                 : %type <objtype>   object_type_any_name object_type_name object_type_name_on_any_name
     500                 :                 drop_type_name
     501                 : 
     502                 : %type <node>  fetch_args select_limit_value
     503                 :                 offset_clause select_offset_value
     504                 :                 select_fetch_first_value I_or_F_const
     505                 : %type <ival>  row_or_rows first_or_next
     506                 : 
     507                 : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     508                 : %type <defelt>    SeqOptElem
     509                 : 
     510                 : %type <istmt> insert_rest
     511                 : %type <infer> opt_conf_expr
     512                 : %type <onconflict> opt_on_conflict
     513                 : %type <mergewhen> merge_insert merge_update merge_delete
     514                 : 
     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 TableFuncElement
     522                 : %type <node>  columnDef columnOptions
     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>  rowsfrom_item rowsfrom_list opt_col_def_list
     529                 : %type <boolean> opt_ordinality
     530                 : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     531                 : %type <list>  func_arg_list func_arg_list_opt
     532                 : %type <node>  func_arg_expr
     533                 : %type <list>  row explicit_row implicit_row type_list array_expr_list
     534                 : %type <node>  case_expr case_arg when_clause case_default
     535                 : %type <list>  when_clause_list
     536                 : %type <node>  opt_search_clause opt_cycle_clause
     537                 : %type <ival>  sub_type opt_materialized
     538                 : %type <node>  NumericOnly
     539                 : %type <list>  NumericOnly_list
     540                 : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
     541                 : %type <list>  func_alias_clause
     542                 : %type <sortby>    sortby
     543                 : %type <ielem> index_elem index_elem_options
     544                 : %type <selem> stats_param
     545                 : %type <node>  table_ref
     546                 : %type <jexpr> joined_table
     547                 : %type <range> relation_expr
     548                 : %type <range> extended_relation_expr
     549                 : %type <range> relation_expr_opt_alias
     550                 : %type <node>  tablesample_clause opt_repeatable_clause
     551                 : %type <target>    target_el set_target insert_column_item
     552                 : 
     553                 : %type <str>       generic_option_name
     554                 : %type <node>  generic_option_arg
     555                 : %type <defelt>    generic_option_elem alter_generic_option_elem
     556                 : %type <list>  generic_option_list alter_generic_option_list
     557                 : 
     558                 : %type <ival>  reindex_target_relation reindex_target_all
     559                 : %type <list>  opt_reindex_option_list
     560                 : 
     561                 : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     562                 : %type <defelt>    copy_generic_opt_elem
     563                 : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     564                 : %type <list>  copy_options
     565                 : 
     566                 : %type <typnam>    Typename SimpleTypename ConstTypename
     567                 :                 GenericType Numeric opt_float
     568                 :                 Character ConstCharacter
     569                 :                 CharacterWithLength CharacterWithoutLength
     570                 :                 ConstDatetime ConstInterval
     571                 :                 Bit ConstBit BitWithLength BitWithoutLength
     572                 : %type <str>       character
     573                 : %type <str>       extract_arg
     574                 : %type <boolean> opt_varying opt_timezone opt_no_inherit
     575                 : 
     576                 : %type <ival>  Iconst SignedIconst
     577                 : %type <str>       Sconst comment_text notify_payload
     578                 : %type <str>       RoleId opt_boolean_or_string
     579                 : %type <list>  var_list
     580                 : %type <str>       ColId ColLabel BareColLabel
     581                 : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     582                 : %type <str>       var_name type_function_name param_name
     583                 : %type <str>       createdb_opt_name plassign_target
     584                 : %type <node>  var_value zone_value
     585                 : %type <rolespec> auth_ident RoleSpec opt_granted_by
     586                 : %type <publicationobjectspec> PublicationObjSpec
     587                 : 
     588                 : %type <keyword> unreserved_keyword type_func_name_keyword
     589                 : %type <keyword> col_name_keyword reserved_keyword
     590                 : %type <keyword> bare_label_keyword
     591                 : 
     592                 : %type <node>  TableConstraint TableLikeClause
     593                 : %type <ival>  TableLikeOptionList TableLikeOption
     594                 : %type <str>       column_compression opt_column_compression column_storage opt_column_storage
     595                 : %type <list>  ColQualList
     596                 : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     597                 : %type <ival>  key_match
     598                 : %type <keyaction> key_delete key_update key_action
     599                 : %type <keyactions> key_actions
     600                 : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     601                 : %type <str>       ExistingIndex
     602                 : 
     603                 : %type <list>  constraints_set_list
     604                 : %type <boolean> constraints_set_mode
     605                 : %type <str>       OptTableSpace OptConsTableSpace
     606                 : %type <rolespec> OptTableSpaceOwner
     607                 : %type <ival>  opt_check_option
     608                 : 
     609                 : %type <str>       opt_provider security_label
     610                 : 
     611                 : %type <target>    xml_attribute_el
     612                 : %type <list>  xml_attribute_list xml_attributes
     613                 : %type <node>  xml_root_version opt_xml_root_standalone
     614                 : %type <node>  xmlexists_argument
     615                 : %type <ival>  document_or_content
     616                 : %type <boolean>   xml_indent_option xml_whitespace_option
     617                 : %type <list>  xmltable_column_list xmltable_column_option_list
     618                 : %type <node>  xmltable_column_el
     619                 : %type <defelt>    xmltable_column_option_el
     620                 : %type <list>  xml_namespace_list
     621                 : %type <target>    xml_namespace_el
     622                 : 
     623                 : %type <node>  func_application func_expr_common_subexpr
     624                 : %type <node>  func_expr func_expr_windowless
     625                 : %type <node>  common_table_expr
     626                 : %type <with>  with_clause opt_with_clause
     627                 : %type <list>  cte_list
     628                 : 
     629                 : %type <list>  within_group_clause
     630                 : %type <node>  filter_clause
     631                 : %type <list>  window_clause window_definition_list opt_partition_clause
     632                 : %type <windef>    window_definition over_clause window_specification
     633                 :                 opt_frame_clause frame_extent frame_bound
     634                 : %type <ival>  opt_window_exclusion_clause
     635                 : %type <str>       opt_existing_window_name
     636                 : %type <boolean> opt_if_not_exists
     637                 : %type <boolean> opt_unique_null_treatment
     638                 : %type <ival>  generated_when override_kind
     639                 : %type <partspec>  PartitionSpec OptPartitionSpec
     640                 : %type <partelem>  part_elem
     641                 : %type <list>      part_params
     642                 : %type <partboundspec> PartitionBoundSpec
     643                 : %type <list>      hash_partbound
     644                 : %type <defelt>        hash_partbound_elem
     645                 : 
     646                 : 
     647                 : %type <node>      json_format_clause_opt
     648                 :                     json_value_expr
     649                 :                     json_output_clause_opt
     650                 :                     json_name_and_value
     651                 :                     json_aggregate_func
     652                 : 
     653                 : %type <list>      json_name_and_value_list
     654                 :                     json_value_expr_list
     655                 :                     json_array_aggregate_order_by_clause_opt
     656                 : 
     657                 : %type <ival>      json_encoding_clause_opt
     658                 :                     json_predicate_type_constraint
     659                 : 
     660                 : %type <boolean>       json_key_uniqueness_constraint_opt
     661                 :                     json_object_constructor_null_clause_opt
     662                 :                     json_array_constructor_null_clause_opt
     663                 : 
     664                 : /*
     665                 :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     666                 :  * They must be listed first so that their numeric codes do not depend on
     667                 :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     668                 :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     669                 :  *
     670                 :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     671                 :  * they need no productions here; but we must assign token codes to them.
     672                 :  *
     673                 :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     674                 :  * parse errors.  It is needed by PL/pgSQL.
     675                 :  */
     676                 : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     677                 : %token <ival> ICONST PARAM
     678                 : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     679                 : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     680                 : 
     681                 : /*
     682                 :  * If you want to make any keyword changes, update the keyword table in
     683                 :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     684                 :  * of the reserved-or-not-so-reserved keyword lists, below; search
     685                 :  * this file for "Keyword category lists".
     686                 :  */
     687                 : 
     688                 : /* ordinary key words in alphabetical order */
     689                 : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     690                 :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     691                 :     ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
     692                 : 
     693                 :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     694                 :     BOOLEAN_P BOTH BREADTH BY
     695                 : 
     696                 :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     697                 :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     698                 :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     699                 :     COMMITTED COMPRESSION CONCURRENTLY CONFIGURATION CONFLICT
     700                 :     CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
     701                 :     COST CREATE CROSS CSV CUBE CURRENT_P
     702                 :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     703                 :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     704                 : 
     705                 :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     706                 :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
     707                 :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     708                 :     DOUBLE_P DROP
     709                 : 
     710                 :     EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EVENT EXCEPT
     711                 :     EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN EXPRESSION
     712                 :     EXTENSION EXTERNAL EXTRACT
     713                 : 
     714                 :     FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
     715                 :     FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     716                 : 
     717                 :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     718                 : 
     719                 :     HANDLER HAVING HEADER_P HOLD HOUR_P
     720                 : 
     721                 :     IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     722                 :     INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     723                 :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     724                 :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     725                 : 
     726                 :     JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_OBJECT JSON_OBJECTAGG
     727                 : 
     728                 :     KEY KEYS
     729                 : 
     730                 :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     731                 :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     732                 :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED
     733                 : 
     734                 :     MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE METHOD
     735                 :     MINUTE_P MINVALUE MODE MONTH_P MOVE
     736                 : 
     737                 :     NAME_P NAMES NATIONAL NATURAL NCHAR NEW NEXT NFC NFD NFKC NFKD NO NONE
     738                 :     NORMALIZE NORMALIZED
     739                 :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     740                 :     NULLS_P NUMERIC
     741                 : 
     742                 :     OBJECT_P OF OFF OFFSET OIDS OLD ON ONLY OPERATOR OPTION OPTIONS OR
     743                 :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     744                 :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     745                 : 
     746                 :     PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD
     747                 :     PLACING PLANS POLICY
     748                 :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     749                 :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     750                 : 
     751                 :     QUOTE
     752                 : 
     753                 :     RANGE READ REAL REASSIGN RECHECK RECURSIVE REF_P REFERENCES REFERENCING
     754                 :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
     755                 :     RESET RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     756                 :     ROUTINE ROUTINES ROW ROWS RULE
     757                 : 
     758                 :     SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
     759                 :     SEQUENCE SEQUENCES
     760                 :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     761                 :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SQL_P STABLE STANDALONE_P
     762                 :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRIP_P
     763                 :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
     764                 : 
     765                 :     TABLE TABLES TABLESAMPLE TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN
     766                 :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     767                 :     TREAT TRIGGER TRIM TRUE_P
     768                 :     TRUNCATE TRUSTED TYPE_P TYPES_P
     769                 : 
     770                 :     UESCAPE UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     771                 :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     772                 : 
     773                 :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     774                 :     VERBOSE VERSION_P VIEW VIEWS VOLATILE
     775                 : 
     776                 :     WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     777                 : 
     778                 :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     779                 :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     780                 : 
     781                 :     YEAR_P YES_P
     782                 : 
     783                 :     ZONE
     784                 : 
     785                 : /*
     786                 :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     787                 :  * list and so can never be entered directly.  The filter in parser.c
     788                 :  * creates these tokens when required (based on looking one token ahead).
     789                 :  *
     790                 :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     791                 :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     792                 :  * as NOT, at least with respect to their left-hand subexpression.
     793                 :  * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
     794                 :  * LALR(1).
     795                 :  */
     796                 : %token      FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
     797                 : 
     798                 : /*
     799                 :  * The grammar likewise thinks these tokens are keywords, but they are never
     800                 :  * generated by the scanner.  Rather, they can be injected by parser.c as
     801                 :  * the initial token of the string (using the lookahead-token mechanism
     802                 :  * implemented there).  This provides a way to tell the grammar to parse
     803                 :  * something other than the usual list of SQL commands.
     804                 :  */
     805                 : %token      MODE_TYPE_NAME
     806                 : %token      MODE_PLPGSQL_EXPR
     807                 : %token      MODE_PLPGSQL_ASSIGN1
     808                 : %token      MODE_PLPGSQL_ASSIGN2
     809                 : %token      MODE_PLPGSQL_ASSIGN3
     810                 : 
     811                 : 
     812                 : /* Precedence: lowest to highest */
     813                 : %nonassoc   SET             /* see relation_expr_opt_alias */
     814                 : %left       UNION EXCEPT
     815                 : %left       INTERSECT
     816                 : %left       OR
     817                 : %left       AND
     818                 : %right      NOT
     819                 : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     820                 : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     821                 : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     822                 : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     823                 : 
     824                 : /* SQL/JSON related keywords */
     825                 : %nonassoc   UNIQUE JSON
     826                 : %nonassoc   KEYS OBJECT_P SCALAR VALUE_P
     827                 : %nonassoc   WITH WITHOUT
     828                 : 
     829                 : /*
     830                 :  * To support target_el without AS, it used to be necessary to assign IDENT an
     831                 :  * explicit precedence just less than Op.  While that's not really necessary
     832                 :  * since we removed postfix operators, it's still helpful to do so because
     833                 :  * there are some other unreserved keywords that need precedence assignments.
     834                 :  * If those keywords have the same precedence as IDENT then they clearly act
     835                 :  * the same as non-keywords, reducing the risk of unwanted precedence effects.
     836                 :  *
     837                 :  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
     838                 :  * opt_existing_window_name (see comment there).
     839                 :  *
     840                 :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     841                 :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     842                 :  * there is no principled way to distinguish these from the productions
     843                 :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     844                 :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     845                 :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     846                 :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     847                 :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     848                 :  *
     849                 :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     850                 :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     851                 :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     852                 :  * Using the same precedence as IDENT seems right for the reasons given above.
     853                 :  */
     854                 : %nonassoc   UNBOUNDED       /* ideally would have same precedence as IDENT */
     855                 : %nonassoc   IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     856                 : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     857                 : %left       '+' '-'
     858                 : %left       '*' '/' '%'
     859                 : %left       '^'
     860                 : /* Unary Operators */
     861                 : %left       AT              /* sets precedence for AT TIME ZONE */
     862                 : %left       COLLATE
     863                 : %right      UMINUS
     864                 : %left       '[' ']'
     865                 : %left       '(' ')'
     866                 : %left       TYPECAST
     867                 : %left       '.'
     868                 : /*
     869                 :  * These might seem to be low-precedence, but actually they are not part
     870                 :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     871                 :  * We make them high-precedence to support their use as function names.
     872                 :  * They wouldn't be given a precedence at all, were it not that we need
     873                 :  * left-associativity among the JOIN rules themselves.
     874                 :  */
     875                 : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     876                 : 
     877                 : %%
     878                 : 
     879                 : /*
     880                 :  *  The target production for the whole parse.
     881                 :  *
     882                 :  * Ordinarily we parse a list of statements, but if we see one of the
     883                 :  * special MODE_XXX symbols as first token, we parse something else.
     884                 :  * The options here correspond to enum RawParseMode, which see for details.
     885                 :  */
     886                 : parse_toplevel:
     887                 :             stmtmulti
     888                 :             {
     889 GIC      475494 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     890                 :                 (void) yynerrs;     /* suppress compiler warning */
     891                 :             }
     892                 :             | MODE_TYPE_NAME Typename
     893                 :             {
     894            4552 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     895                 :             }
     896                 :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     897                 :             {
     898           14331 :                 pg_yyget_extra(yyscanner)->parsetree =
     899           14331 :                     list_make1(makeRawStmt($2, 0));
     900                 :             }
     901                 :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     902                 :             {
     903            2928 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     904                 : 
     905            2928 :                 n->nnames = 1;
     906            2928 :                 pg_yyget_extra(yyscanner)->parsetree =
     907            2928 :                     list_make1(makeRawStmt((Node *) n, 0));
     908                 :             }
     909                 :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     910                 :             {
     911             309 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     912                 : 
     913             309 :                 n->nnames = 2;
     914             309 :                 pg_yyget_extra(yyscanner)->parsetree =
     915             309 :                     list_make1(makeRawStmt((Node *) n, 0));
     916                 :             }
     917 ECB             :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     918                 :             {
     919 GIC          14 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     920                 : 
     921              14 :                 n->nnames = 3;
     922 CBC          14 :                 pg_yyget_extra(yyscanner)->parsetree =
     923 GIC          14 :                     list_make1(makeRawStmt((Node *) n, 0));
     924                 :             }
     925                 :         ;
     926 ECB             : 
     927                 : /*
     928                 :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     929                 :  * and length of the stmt's text.  Notice that the start loc/len are driven
     930                 :  * entirely from semicolon locations (@2).  It would seem natural to use
     931                 :  * @1 or @3 to get the true start location of a stmt, but that doesn't work
     932                 :  * for statements that can start with empty nonterminals (opt_with_clause is
     933                 :  * the main offender here); as noted in the comments for YYLLOC_DEFAULT,
     934                 :  * we'd get -1 for the location in such cases.
     935                 :  * We also take care to discard empty statements entirely.
     936                 :  */
     937                 : stmtmulti:  stmtmulti ';' toplevel_stmt
     938                 :                 {
     939 CBC      454266 :                     if ($1 != NIL)
     940                 :                     {
     941 ECB             :                         /* update length of previous stmt */
     942 CBC      454229 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     943 ECB             :                     }
     944 GIC      454266 :                     if ($3 != NULL)
     945           47881 :                         $$ = lappend($1, makeRawStmt($3, @2 + 1));
     946                 :                     else
     947 CBC      406385 :                         $$ = $1;
     948                 :                 }
     949 ECB             :             | toplevel_stmt
     950                 :                 {
     951 CBC      475497 :                     if ($1 != NULL)
     952 GIC      475313 :                         $$ = list_make1(makeRawStmt($1, 0));
     953                 :                     else
     954             184 :                         $$ = NIL;
     955                 :                 }
     956                 :         ;
     957                 : 
     958                 : /*
     959                 :  * toplevel_stmt includes BEGIN and END.  stmt does not include them, because
     960                 :  * those words have different meanings in function bodys.
     961                 :  */
     962                 : toplevel_stmt:
     963                 :             stmt
     964                 :             | TransactionStmtLegacy
     965                 :         ;
     966                 : 
     967 ECB             : stmt:
     968                 :             AlterEventTrigStmt
     969                 :             | AlterCollationStmt
     970                 :             | AlterDatabaseStmt
     971                 :             | AlterDatabaseSetStmt
     972                 :             | AlterDefaultPrivilegesStmt
     973                 :             | AlterDomainStmt
     974                 :             | AlterEnumStmt
     975                 :             | AlterExtensionStmt
     976                 :             | AlterExtensionContentsStmt
     977                 :             | AlterFdwStmt
     978                 :             | AlterForeignServerStmt
     979                 :             | AlterFunctionStmt
     980                 :             | AlterGroupStmt
     981                 :             | AlterObjectDependsStmt
     982                 :             | AlterObjectSchemaStmt
     983                 :             | AlterOwnerStmt
     984                 :             | AlterOperatorStmt
     985                 :             | AlterTypeStmt
     986                 :             | AlterPolicyStmt
     987                 :             | AlterSeqStmt
     988                 :             | AlterSystemStmt
     989                 :             | AlterTableStmt
     990                 :             | AlterTblSpcStmt
     991                 :             | AlterCompositeTypeStmt
     992                 :             | AlterPublicationStmt
     993                 :             | AlterRoleSetStmt
     994                 :             | AlterRoleStmt
     995                 :             | AlterSubscriptionStmt
     996                 :             | AlterStatsStmt
     997                 :             | AlterTSConfigurationStmt
     998                 :             | AlterTSDictionaryStmt
     999                 :             | AlterUserMappingStmt
    1000                 :             | AnalyzeStmt
    1001                 :             | CallStmt
    1002                 :             | CheckPointStmt
    1003                 :             | ClosePortalStmt
    1004                 :             | ClusterStmt
    1005                 :             | CommentStmt
    1006                 :             | ConstraintsSetStmt
    1007                 :             | CopyStmt
    1008                 :             | CreateAmStmt
    1009                 :             | CreateAsStmt
    1010                 :             | CreateAssertionStmt
    1011                 :             | CreateCastStmt
    1012                 :             | CreateConversionStmt
    1013                 :             | CreateDomainStmt
    1014                 :             | CreateExtensionStmt
    1015                 :             | CreateFdwStmt
    1016                 :             | CreateForeignServerStmt
    1017                 :             | CreateForeignTableStmt
    1018                 :             | CreateFunctionStmt
    1019                 :             | CreateGroupStmt
    1020                 :             | CreateMatViewStmt
    1021                 :             | CreateOpClassStmt
    1022                 :             | CreateOpFamilyStmt
    1023                 :             | CreatePublicationStmt
    1024                 :             | AlterOpFamilyStmt
    1025                 :             | CreatePolicyStmt
    1026                 :             | CreatePLangStmt
    1027                 :             | CreateSchemaStmt
    1028                 :             | CreateSeqStmt
    1029                 :             | CreateStmt
    1030                 :             | CreateSubscriptionStmt
    1031                 :             | CreateStatsStmt
    1032                 :             | CreateTableSpaceStmt
    1033                 :             | CreateTransformStmt
    1034                 :             | CreateTrigStmt
    1035                 :             | CreateEventTrigStmt
    1036                 :             | CreateRoleStmt
    1037                 :             | CreateUserStmt
    1038                 :             | CreateUserMappingStmt
    1039                 :             | CreatedbStmt
    1040                 :             | DeallocateStmt
    1041                 :             | DeclareCursorStmt
    1042                 :             | DefineStmt
    1043                 :             | DeleteStmt
    1044                 :             | DiscardStmt
    1045                 :             | DoStmt
    1046                 :             | DropCastStmt
    1047                 :             | DropOpClassStmt
    1048                 :             | DropOpFamilyStmt
    1049                 :             | DropOwnedStmt
    1050                 :             | DropStmt
    1051                 :             | DropSubscriptionStmt
    1052                 :             | DropTableSpaceStmt
    1053                 :             | DropTransformStmt
    1054                 :             | DropRoleStmt
    1055                 :             | DropUserMappingStmt
    1056                 :             | DropdbStmt
    1057                 :             | ExecuteStmt
    1058                 :             | ExplainStmt
    1059                 :             | FetchStmt
    1060                 :             | GrantStmt
    1061                 :             | GrantRoleStmt
    1062                 :             | ImportForeignSchemaStmt
    1063                 :             | IndexStmt
    1064                 :             | InsertStmt
    1065                 :             | ListenStmt
    1066                 :             | RefreshMatViewStmt
    1067                 :             | LoadStmt
    1068                 :             | LockStmt
    1069                 :             | MergeStmt
    1070                 :             | NotifyStmt
    1071                 :             | PrepareStmt
    1072                 :             | ReassignOwnedStmt
    1073                 :             | ReindexStmt
    1074                 :             | RemoveAggrStmt
    1075                 :             | RemoveFuncStmt
    1076                 :             | RemoveOperStmt
    1077                 :             | RenameStmt
    1078                 :             | RevokeStmt
    1079                 :             | RevokeRoleStmt
    1080                 :             | RuleStmt
    1081                 :             | SecLabelStmt
    1082                 :             | SelectStmt
    1083                 :             | TransactionStmt
    1084                 :             | TruncateStmt
    1085                 :             | UnlistenStmt
    1086                 :             | UpdateStmt
    1087                 :             | VacuumStmt
    1088                 :             | VariableResetStmt
    1089                 :             | VariableSetStmt
    1090                 :             | VariableShowStmt
    1091                 :             | ViewStmt
    1092                 :             | /*EMPTY*/
    1093 GIC      406577 :                 { $$ = NULL; }
    1094                 :         ;
    1095                 : 
    1096                 : /*
    1097                 :  * Generic supporting productions for DDL
    1098                 :  */
    1099                 : opt_single_name:
    1100 GNC        2360 :             ColId                           { $$ = $1; }
    1101             525 :             | /* EMPTY */                   { $$ = NULL; }
    1102                 :         ;
    1103                 : 
    1104                 : opt_qualified_name:
    1105             802 :             any_name                        { $$ = $1; }
    1106            6459 :             | /*EMPTY*/                     { $$ = NIL; }
    1107                 :         ;
    1108                 : 
    1109                 : opt_concurrently:
    1110             447 :             CONCURRENTLY                    { $$ = true; }
    1111            3206 :             | /*EMPTY*/                     { $$ = false; }
    1112                 :         ;
    1113                 : 
    1114                 : opt_drop_behavior:
    1115             864 :             CASCADE                         { $$ = DROP_CASCADE; }
    1116              86 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1117           36494 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1118                 :         ;
    1119                 : 
    1120                 : /*****************************************************************************
    1121                 :  *
    1122                 :  * CALL statement
    1123                 :  *
    1124                 :  *****************************************************************************/
    1125                 : 
    1126                 : CallStmt:   CALL func_application
    1127                 :                 {
    1128 GIC         249 :                     CallStmt   *n = makeNode(CallStmt);
    1129                 : 
    1130             249 :                     n->funccall = castNode(FuncCall, $2);
    1131             249 :                     $$ = (Node *) n;
    1132                 :                 }
    1133                 :         ;
    1134                 : 
    1135                 : /*****************************************************************************
    1136                 :  *
    1137                 :  * Create a new Postgres DBMS role
    1138                 :  *
    1139                 :  *****************************************************************************/
    1140                 : 
    1141                 : CreateRoleStmt:
    1142                 :             CREATE ROLE RoleId opt_with OptRoleList
    1143                 :                 {
    1144             574 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1145 ECB             : 
    1146 GIC         574 :                     n->stmt_type = ROLESTMT_ROLE;
    1147             574 :                     n->role = $3;
    1148             574 :                     n->options = $5;
    1149             574 :                     $$ = (Node *) n;
    1150                 :                 }
    1151                 :         ;
    1152 ECB             : 
    1153                 : 
    1154                 : opt_with:   WITH
    1155                 :             | WITH_LA
    1156                 :             | /*EMPTY*/
    1157                 :         ;
    1158                 : 
    1159                 : /*
    1160                 :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1161                 :  * for backwards compatibility).  Note: the only option required by SQL99
    1162                 :  * is "WITH ADMIN name".
    1163                 :  */
    1164                 : OptRoleList:
    1165 GIC         518 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1166             799 :             | /* EMPTY */                           { $$ = NIL; }
    1167 ECB             :         ;
    1168                 : 
    1169                 : AlterOptRoleList:
    1170 GIC         260 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1171             182 :             | /* EMPTY */                           { $$ = NIL; }
    1172                 :         ;
    1173                 : 
    1174                 : AlterOptRoleElem:
    1175                 :             PASSWORD Sconst
    1176                 :                 {
    1177              79 :                     $$ = makeDefElem("password",
    1178              79 :                                      (Node *) makeString($2), @1);
    1179                 :                 }
    1180 ECB             :             | PASSWORD NULL_P
    1181                 :                 {
    1182 CBC           6 :                     $$ = makeDefElem("password", NULL, @1);
    1183 ECB             :                 }
    1184                 :             | ENCRYPTED PASSWORD Sconst
    1185                 :                 {
    1186                 :                     /*
    1187                 :                      * These days, passwords are always stored in encrypted
    1188                 :                      * form, so there is no difference between PASSWORD and
    1189                 :                      * ENCRYPTED PASSWORD.
    1190                 :                      */
    1191 GIC           5 :                     $$ = makeDefElem("password",
    1192               5 :                                      (Node *) makeString($3), @1);
    1193                 :                 }
    1194                 :             | UNENCRYPTED PASSWORD Sconst
    1195                 :                 {
    1196 LBC           0 :                     ereport(ERROR,
    1197                 :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1198 ECB             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1199                 :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1200                 :                              parser_errposition(@1)));
    1201                 :                 }
    1202                 :             | INHERIT
    1203                 :                 {
    1204 GIC          36 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1205                 :                 }
    1206                 :             | CONNECTION LIMIT SignedIconst
    1207                 :                 {
    1208              12 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1209                 :                 }
    1210                 :             | VALID UNTIL Sconst
    1211                 :                 {
    1212               1 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1213                 :                 }
    1214                 :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1215                 :             | USER role_list
    1216                 :                 {
    1217 CBC           3 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1218 ECB             :                 }
    1219                 :             | IDENT
    1220                 :                 {
    1221                 :                     /*
    1222                 :                      * We handle identifiers that aren't parser keywords with
    1223                 :                      * the following special-case codes, to avoid bloating the
    1224                 :                      * size of the main parser.
    1225                 :                      */
    1226 GIC         568 :                     if (strcmp($1, "superuser") == 0)
    1227              78 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1228             490 :                     else if (strcmp($1, "nosuperuser") == 0)
    1229 CBC          43 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1230             447 :                     else if (strcmp($1, "createrole") == 0)
    1231 GIC          44 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1232             403 :                     else if (strcmp($1, "nocreaterole") == 0)
    1233              14 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1234 CBC         389 :                     else if (strcmp($1, "replication") == 0)
    1235 GIC          55 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1236             334 :                     else if (strcmp($1, "noreplication") == 0)
    1237              43 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1238             291 :                     else if (strcmp($1, "createdb") == 0)
    1239              39 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1240             252 :                     else if (strcmp($1, "nocreatedb") == 0)
    1241              18 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1242             234 :                     else if (strcmp($1, "login") == 0)
    1243 CBC         111 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1244             123 :                     else if (strcmp($1, "nologin") == 0)
    1245 GIC          42 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1246              81 :                     else if (strcmp($1, "bypassrls") == 0)
    1247              34 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1248 GBC          47 :                     else if (strcmp($1, "nobypassrls") == 0)
    1249 GIC          29 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1250              18 :                     else if (strcmp($1, "noinherit") == 0)
    1251                 :                     {
    1252                 :                         /*
    1253                 :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1254                 :                          * NOINHERIT is handled here.
    1255                 :                          */
    1256 CBC          18 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1257                 :                     }
    1258                 :                     else
    1259 UIC           0 :                         ereport(ERROR,
    1260 ECB             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1261                 :                                  errmsg("unrecognized role option \"%s\"", $1),
    1262                 :                                      parser_errposition(@1)));
    1263                 :                 }
    1264                 :         ;
    1265                 : 
    1266                 : CreateOptRoleElem:
    1267 GIC         450 :             AlterOptRoleElem            { $$ = $1; }
    1268                 :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1269 ECB             :             | SYSID Iconst
    1270                 :                 {
    1271 GIC           3 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1272                 :                 }
    1273                 :             | ADMIN role_list
    1274                 :                 {
    1275              10 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1276                 :                 }
    1277                 :             | ROLE role_list
    1278 ECB             :                 {
    1279 CBC           7 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1280 ECB             :                 }
    1281                 :             | IN_P ROLE role_list
    1282                 :                 {
    1283 CBC          48 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1284 ECB             :                 }
    1285                 :             | IN_P GROUP_P role_list
    1286                 :                 {
    1287 LBC           0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1288 ECB             :                 }
    1289                 :         ;
    1290                 : 
    1291                 : 
    1292                 : /*****************************************************************************
    1293                 :  *
    1294                 :  * Create a new Postgres DBMS user (role with implied login ability)
    1295                 :  *
    1296                 :  *****************************************************************************/
    1297                 : 
    1298                 : CreateUserStmt:
    1299                 :             CREATE USER RoleId opt_with OptRoleList
    1300                 :                 {
    1301 CBC         213 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1302 ECB             : 
    1303 GIC         213 :                     n->stmt_type = ROLESTMT_USER;
    1304             213 :                     n->role = $3;
    1305             213 :                     n->options = $5;
    1306             213 :                     $$ = (Node *) n;
    1307                 :                 }
    1308 ECB             :         ;
    1309                 : 
    1310                 : 
    1311 EUB             : /*****************************************************************************
    1312                 :  *
    1313                 :  * Alter a postgresql DBMS role
    1314                 :  *
    1315                 :  *****************************************************************************/
    1316                 : 
    1317                 : AlterRoleStmt:
    1318                 :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1319 ECB             :                  {
    1320 GIC         142 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1321                 : 
    1322             142 :                     n->role = $3;
    1323 CBC         142 :                     n->action = +1;  /* add, if there are members */
    1324 GIC         142 :                     n->options = $5;
    1325             142 :                     $$ = (Node *) n;
    1326                 :                  }
    1327 ECB             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1328                 :                  {
    1329 GIC          40 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1330                 : 
    1331 CBC          40 :                     n->role = $3;
    1332 GIC          40 :                     n->action = +1;  /* add, if there are members */
    1333              40 :                     n->options = $5;
    1334              40 :                     $$ = (Node *) n;
    1335 ECB             :                  }
    1336                 :         ;
    1337                 : 
    1338                 : opt_in_database:
    1339 GBC          48 :                /* EMPTY */                  { $$ = NULL; }
    1340 UIC           0 :             | IN_P DATABASE name    { $$ = $3; }
    1341                 :         ;
    1342                 : 
    1343                 : AlterRoleSetStmt:
    1344                 :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1345                 :                 {
    1346 GIC          29 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1347                 : 
    1348              29 :                     n->role = $3;
    1349              29 :                     n->database = $4;
    1350              29 :                     n->setstmt = $5;
    1351              29 :                     $$ = (Node *) n;
    1352                 :                 }
    1353 ECB             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1354                 :                 {
    1355 CBC           2 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1356 ECB             : 
    1357 CBC           2 :                     n->role = NULL;
    1358               2 :                     n->database = $4;
    1359 GIC           2 :                     n->setstmt = $5;
    1360               2 :                     $$ = (Node *) n;
    1361                 :                 }
    1362                 :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1363                 :                 {
    1364              13 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1365                 : 
    1366              13 :                     n->role = $3;
    1367              13 :                     n->database = $4;
    1368              13 :                     n->setstmt = $5;
    1369              13 :                     $$ = (Node *) n;
    1370                 :                 }
    1371                 :             | ALTER USER ALL opt_in_database SetResetClause
    1372 ECB             :                 {
    1373 GIC           2 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1374 ECB             : 
    1375 CBC           2 :                     n->role = NULL;
    1376               2 :                     n->database = $4;
    1377               2 :                     n->setstmt = $5;
    1378 GIC           2 :                     $$ = (Node *) n;
    1379                 :                 }
    1380                 :         ;
    1381 ECB             : 
    1382                 : 
    1383                 : /*****************************************************************************
    1384                 :  *
    1385                 :  * Drop a postgresql DBMS role
    1386                 :  *
    1387                 :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1388                 :  * might own objects in multiple databases, and there is presently no way to
    1389                 :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1390                 :  *****************************************************************************/
    1391                 : 
    1392 EUB             : DropRoleStmt:
    1393                 :             DROP ROLE role_list
    1394                 :                 {
    1395 GIC         496 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1396                 : 
    1397             496 :                     n->missing_ok = false;
    1398 CBC         496 :                     n->roles = $3;
    1399 GIC         496 :                     $$ = (Node *) n;
    1400 ECB             :                 }
    1401                 :             | DROP ROLE IF_P EXISTS role_list
    1402                 :                 {
    1403 CBC          67 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1404                 : 
    1405 GIC          67 :                     n->missing_ok = true;
    1406              67 :                     n->roles = $5;
    1407 CBC          67 :                     $$ = (Node *) n;
    1408                 :                 }
    1409 ECB             :             | DROP USER role_list
    1410                 :                 {
    1411 CBC         195 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1412 ECB             : 
    1413 GIC         195 :                     n->missing_ok = false;
    1414             195 :                     n->roles = $3;
    1415             195 :                     $$ = (Node *) n;
    1416 ECB             :                 }
    1417                 :             | DROP USER IF_P EXISTS role_list
    1418                 :                 {
    1419 CBC          18 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1420 ECB             : 
    1421 CBC          18 :                     n->roles = $5;
    1422 GIC          18 :                     n->missing_ok = true;
    1423              18 :                     $$ = (Node *) n;
    1424                 :                 }
    1425 ECB             :             | DROP GROUP_P role_list
    1426                 :                 {
    1427 CBC          18 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1428 ECB             : 
    1429 CBC          18 :                     n->missing_ok = false;
    1430              18 :                     n->roles = $3;
    1431 GIC          18 :                     $$ = (Node *) n;
    1432                 :                 }
    1433                 :             | DROP GROUP_P IF_P EXISTS role_list
    1434                 :                 {
    1435               3 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1436                 : 
    1437               3 :                     n->missing_ok = true;
    1438               3 :                     n->roles = $5;
    1439               3 :                     $$ = (Node *) n;
    1440                 :                 }
    1441                 :             ;
    1442                 : 
    1443                 : 
    1444                 : /*****************************************************************************
    1445                 :  *
    1446                 :  * Create a postgresql group (role without login ability)
    1447 ECB             :  *
    1448                 :  *****************************************************************************/
    1449                 : 
    1450                 : CreateGroupStmt:
    1451                 :             CREATE GROUP_P RoleId opt_with OptRoleList
    1452                 :                 {
    1453 GIC          12 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1454                 : 
    1455 CBC          12 :                     n->stmt_type = ROLESTMT_GROUP;
    1456 GIC          12 :                     n->role = $3;
    1457 CBC          12 :                     n->options = $5;
    1458              12 :                     $$ = (Node *) n;
    1459 ECB             :                 }
    1460                 :         ;
    1461                 : 
    1462                 : 
    1463                 : /*****************************************************************************
    1464                 :  *
    1465                 :  * Alter a postgresql group
    1466                 :  *
    1467                 :  *****************************************************************************/
    1468                 : 
    1469                 : AlterGroupStmt:
    1470                 :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1471                 :                 {
    1472 GIC          15 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1473 ECB             : 
    1474 CBC          15 :                     n->role = $3;
    1475              15 :                     n->action = $4;
    1476 GIC          15 :                     n->options = list_make1(makeDefElem("rolemembers",
    1477                 :                                                         (Node *) $6, @6));
    1478              15 :                     $$ = (Node *) n;
    1479 ECB             :                 }
    1480                 :         ;
    1481                 : 
    1482 CBC          38 : add_drop:   ADD_P                                   { $$ = +1; }
    1483              64 :             | DROP                                  { $$ = -1; }
    1484                 :         ;
    1485                 : 
    1486                 : 
    1487 ECB             : /*****************************************************************************
    1488                 :  *
    1489                 :  * Manipulate a schema
    1490                 :  *
    1491                 :  *****************************************************************************/
    1492                 : 
    1493                 : CreateSchemaStmt:
    1494                 :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1495                 :                 {
    1496 GIC          25 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1497                 : 
    1498                 :                     /* One can omit the schema name or the authorization id. */
    1499              25 :                     n->schemaname = $3;
    1500              25 :                     n->authrole = $5;
    1501              25 :                     n->schemaElts = $6;
    1502              25 :                     n->if_not_exists = false;
    1503              25 :                     $$ = (Node *) n;
    1504                 :                 }
    1505 ECB             :             | CREATE SCHEMA ColId OptSchemaEltList
    1506                 :                 {
    1507 CBC         626 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1508 ECB             : 
    1509                 :                     /* ...but not both */
    1510 CBC         626 :                     n->schemaname = $3;
    1511 GIC         626 :                     n->authrole = NULL;
    1512             626 :                     n->schemaElts = $4;
    1513             626 :                     n->if_not_exists = false;
    1514             626 :                     $$ = (Node *) n;
    1515                 :                 }
    1516                 :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1517                 :                 {
    1518               9 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1519                 : 
    1520                 :                     /* schema name can be omitted here, too */
    1521               9 :                     n->schemaname = $6;
    1522               9 :                     n->authrole = $8;
    1523               9 :                     if ($9 != NIL)
    1524 LBC           0 :                         ereport(ERROR,
    1525                 :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1526 ECB             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1527                 :                                  parser_errposition(@9)));
    1528 CBC           9 :                     n->schemaElts = $9;
    1529 GIC           9 :                     n->if_not_exists = true;
    1530 CBC           9 :                     $$ = (Node *) n;
    1531                 :                 }
    1532                 :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1533                 :                 {
    1534              17 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1535 ECB             : 
    1536                 :                     /* ...but not here */
    1537 GIC          17 :                     n->schemaname = $6;
    1538              17 :                     n->authrole = NULL;
    1539              17 :                     if ($7 != NIL)
    1540               3 :                         ereport(ERROR,
    1541                 :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1542                 :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1543                 :                                  parser_errposition(@7)));
    1544              14 :                     n->schemaElts = $7;
    1545              14 :                     n->if_not_exists = true;
    1546              14 :                     $$ = (Node *) n;
    1547                 :                 }
    1548 ECB             :         ;
    1549                 : 
    1550                 : OptSchemaEltList:
    1551                 :             OptSchemaEltList schema_stmt
    1552                 :                 {
    1553 GIC         178 :                     if (@$ < 0)          /* see comments for YYLLOC_DEFAULT */
    1554 CBC          50 :                         @$ = @2;
    1555 GIC         178 :                     $$ = lappend($1, $2);
    1556                 :                 }
    1557 ECB             :             | /* EMPTY */
    1558 CBC         677 :                 { $$ = NIL; }
    1559 ECB             :         ;
    1560                 : 
    1561                 : /*
    1562                 :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1563                 :  *  statement (in addition to by themselves).
    1564                 :  */
    1565                 : schema_stmt:
    1566                 :             CreateStmt
    1567                 :             | IndexStmt
    1568                 :             | CreateSeqStmt
    1569                 :             | CreateTrigStmt
    1570                 :             | GrantStmt
    1571 EUB             :             | ViewStmt
    1572                 :         ;
    1573                 : 
    1574                 : 
    1575 ECB             : /*****************************************************************************
    1576                 :  *
    1577                 :  * Set PG internal variable
    1578                 :  *    SET name TO 'var_value'
    1579                 :  * Include SQL syntax (thomas 1997-10-22):
    1580                 :  *    SET TIME ZONE 'var_value'
    1581                 :  *
    1582                 :  *****************************************************************************/
    1583                 : 
    1584                 : VariableSetStmt:
    1585                 :             SET set_rest
    1586                 :                 {
    1587 CBC        8795 :                     VariableSetStmt *n = $2;
    1588                 : 
    1589 GIC        8795 :                     n->is_local = false;
    1590            8795 :                     $$ = (Node *) n;
    1591 ECB             :                 }
    1592                 :             | SET LOCAL set_rest
    1593                 :                 {
    1594 GIC         496 :                     VariableSetStmt *n = $3;
    1595                 : 
    1596             496 :                     n->is_local = true;
    1597             496 :                     $$ = (Node *) n;
    1598                 :                 }
    1599                 :             | SET SESSION set_rest
    1600 ECB             :                 {
    1601 CBC          40 :                     VariableSetStmt *n = $3;
    1602 ECB             : 
    1603 GIC          40 :                     n->is_local = false;
    1604              40 :                     $$ = (Node *) n;
    1605 ECB             :                 }
    1606                 :         ;
    1607                 : 
    1608                 : set_rest:
    1609                 :             TRANSACTION transaction_mode_list
    1610                 :                 {
    1611 GIC         221 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1612                 : 
    1613             221 :                     n->kind = VAR_SET_MULTI;
    1614             221 :                     n->name = "TRANSACTION";
    1615             221 :                     n->args = $2;
    1616             221 :                     $$ = n;
    1617                 :                 }
    1618                 :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1619                 :                 {
    1620               6 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1621                 : 
    1622               6 :                     n->kind = VAR_SET_MULTI;
    1623               6 :                     n->name = "SESSION CHARACTERISTICS";
    1624               6 :                     n->args = $5;
    1625               6 :                     $$ = n;
    1626                 :                 }
    1627                 :             | set_rest_more
    1628                 :             ;
    1629                 : 
    1630                 : generic_set:
    1631                 :             var_name TO var_list
    1632                 :                 {
    1633            2295 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1634 ECB             : 
    1635 GIC        2295 :                     n->kind = VAR_SET_VALUE;
    1636 CBC        2295 :                     n->name = $1;
    1637            2295 :                     n->args = $3;
    1638 GIC        2295 :                     $$ = n;
    1639                 :                 }
    1640                 :             | var_name '=' var_list
    1641 ECB             :                 {
    1642 GIC        5717 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1643 ECB             : 
    1644 CBC        5717 :                     n->kind = VAR_SET_VALUE;
    1645 GIC        5717 :                     n->name = $1;
    1646            5717 :                     n->args = $3;
    1647            5717 :                     $$ = n;
    1648 ECB             :                 }
    1649                 :             | var_name TO var_list USER SET
    1650                 :                 {
    1651 UNC           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1652                 : 
    1653               0 :                     n->kind = VAR_SET_VALUE;
    1654               0 :                     n->name = $1;
    1655               0 :                     n->args = $3;
    1656               0 :                     n->user_set = true;
    1657               0 :                     $$ = n;
    1658                 :                 }
    1659                 :             | var_name '=' var_list USER SET
    1660                 :                 {
    1661 GNC           3 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1662                 : 
    1663               3 :                     n->kind = VAR_SET_VALUE;
    1664               3 :                     n->name = $1;
    1665               3 :                     n->args = $3;
    1666               3 :                     n->user_set = true;
    1667               3 :                     $$ = n;
    1668                 :                 }
    1669                 :             | var_name TO DEFAULT
    1670 ECB             :                 {
    1671 CBC          63 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1672                 : 
    1673 GIC          63 :                     n->kind = VAR_SET_DEFAULT;
    1674              63 :                     n->name = $1;
    1675              63 :                     $$ = n;
    1676                 :                 }
    1677                 :             | var_name '=' DEFAULT
    1678 ECB             :                 {
    1679 UIC           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1680 ECB             : 
    1681 LBC           0 :                     n->kind = VAR_SET_DEFAULT;
    1682               0 :                     n->name = $1;
    1683               0 :                     $$ = n;
    1684                 :                 }
    1685                 :         ;
    1686                 : 
    1687 ECB             : set_rest_more:  /* Generic SET syntaxes: */
    1688 GIC        8027 :             generic_set                         {$$ = $1;}
    1689 ECB             :             | var_name FROM CURRENT_P
    1690                 :                 {
    1691 LBC           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1692 ECB             : 
    1693 UIC           0 :                     n->kind = VAR_SET_CURRENT;
    1694               0 :                     n->name = $1;
    1695               0 :                     $$ = n;
    1696                 :                 }
    1697                 :             /* Special syntaxes mandated by SQL standard: */
    1698                 :             | TIME ZONE zone_value
    1699                 :                 {
    1700 CBC          37 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1701                 : 
    1702              37 :                     n->kind = VAR_SET_VALUE;
    1703              37 :                     n->name = "timezone";
    1704              37 :                     if ($3 != NULL)
    1705              31 :                         n->args = list_make1($3);
    1706                 :                     else
    1707 GIC           6 :                         n->kind = VAR_SET_DEFAULT;
    1708              37 :                     $$ = n;
    1709 ECB             :                 }
    1710                 :             | CATALOG_P Sconst
    1711                 :                 {
    1712 LBC           0 :                     ereport(ERROR,
    1713 ECB             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1714                 :                              errmsg("current database cannot be changed"),
    1715                 :                              parser_errposition(@2)));
    1716                 :                     $$ = NULL; /*not reached*/
    1717                 :                 }
    1718 EUB             :             | SCHEMA Sconst
    1719                 :                 {
    1720 UBC           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1721 EUB             : 
    1722 UBC           0 :                     n->kind = VAR_SET_VALUE;
    1723               0 :                     n->name = "search_path";
    1724               0 :                     n->args = list_make1(makeStringConst($2, @2));
    1725 UIC           0 :                     $$ = n;
    1726                 :                 }
    1727                 :             | NAMES opt_encoding
    1728 ECB             :                 {
    1729 UIC           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1730 ECB             : 
    1731 LBC           0 :                     n->kind = VAR_SET_VALUE;
    1732               0 :                     n->name = "client_encoding";
    1733               0 :                     if ($2 != NULL)
    1734               0 :                         n->args = list_make1(makeStringConst($2, @2));
    1735                 :                     else
    1736 UIC           0 :                         n->kind = VAR_SET_DEFAULT;
    1737               0 :                     $$ = n;
    1738 ECB             :                 }
    1739                 :             | ROLE NonReservedWord_or_Sconst
    1740                 :                 {
    1741 CBC         394 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1742 ECB             : 
    1743 GIC         394 :                     n->kind = VAR_SET_VALUE;
    1744             394 :                     n->name = "role";
    1745             394 :                     n->args = list_make1(makeStringConst($2, @2));
    1746 GBC         394 :                     $$ = n;
    1747                 :                 }
    1748 EUB             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1749                 :                 {
    1750 GBC        1215 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1751                 : 
    1752 GIC        1215 :                     n->kind = VAR_SET_VALUE;
    1753            1215 :                     n->name = "session_authorization";
    1754            1215 :                     n->args = list_make1(makeStringConst($3, @3));
    1755 CBC        1215 :                     $$ = n;
    1756                 :                 }
    1757                 :             | SESSION AUTHORIZATION DEFAULT
    1758 EUB             :                 {
    1759 GIC           2 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1760 EUB             : 
    1761 GBC           2 :                     n->kind = VAR_SET_DEFAULT;
    1762               2 :                     n->name = "session_authorization";
    1763 GIC           2 :                     $$ = n;
    1764                 :                 }
    1765                 :             | XML_P OPTION document_or_content
    1766                 :                 {
    1767 CBC           6 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1768                 : 
    1769               6 :                     n->kind = VAR_SET_VALUE;
    1770               6 :                     n->name = "xmloption";
    1771               6 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1772               6 :                     $$ = n;
    1773                 :                 }
    1774 ECB             :             /* Special syntaxes invented by PostgreSQL: */
    1775                 :             | TRANSACTION SNAPSHOT Sconst
    1776                 :                 {
    1777 GIC          18 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1778                 : 
    1779 GBC          18 :                     n->kind = VAR_SET_MULTI;
    1780 GIC          18 :                     n->name = "TRANSACTION SNAPSHOT";
    1781              18 :                     n->args = list_make1(makeStringConst($3, @3));
    1782              18 :                     $$ = n;
    1783                 :                 }
    1784                 :         ;
    1785                 : 
    1786            9887 : var_name:   ColId                               { $$ = $1; }
    1787 EUB             :             | var_name '.' ColId
    1788 GIC         202 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1789 EUB             :         ;
    1790                 : 
    1791 GBC        8015 : var_list:   var_value                               { $$ = list_make1($1); }
    1792              70 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1793                 :         ;
    1794                 : 
    1795                 : var_value:  opt_boolean_or_string
    1796            6427 :                 { $$ = makeStringConst($1, @1); }
    1797                 :             | NumericOnly
    1798            1658 :                 { $$ = makeAConst($1, @1); }
    1799 EUB             :         ;
    1800                 : 
    1801 UBC           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1802 GIC         415 :             | READ COMMITTED                        { $$ = "read committed"; }
    1803 GBC        1133 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1804            1598 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1805                 :         ;
    1806                 : 
    1807                 : opt_boolean_or_string:
    1808 CBC         522 :             TRUE_P                                  { $$ = "true"; }
    1809 GIC         873 :             | FALSE_P                               { $$ = "false"; }
    1810 CBC         915 :             | ON                                    { $$ = "on"; }
    1811 ECB             :             /*
    1812                 :              * OFF is also accepted as a boolean value, but is handled by
    1813                 :              * the NonReservedWord rule.  The action for booleans and strings
    1814                 :              * is the same, so we don't need to distinguish them here.
    1815                 :              */
    1816 GIC       12292 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1817 ECB             :         ;
    1818                 : 
    1819                 : /* Timezone values can be:
    1820                 :  * - a string such as 'pst8pdt'
    1821                 :  * - an identifier such as "pst8pdt"
    1822                 :  * - an integer or floating point number
    1823                 :  * - a time interval per SQL99
    1824                 :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1825                 :  * so use IDENT (meaning we reject anything that is a key word).
    1826                 :  */
    1827                 : zone_value:
    1828                 :             Sconst
    1829                 :                 {
    1830 CBC          18 :                     $$ = makeStringConst($1, @1);
    1831                 :                 }
    1832                 :             | IDENT
    1833                 :                 {
    1834               1 :                     $$ = makeStringConst($1, @1);
    1835                 :                 }
    1836 ECB             :             | ConstInterval Sconst opt_interval
    1837                 :                 {
    1838 LBC           0 :                     TypeName   *t = $1;
    1839 ECB             : 
    1840 UIC           0 :                     if ($3 != NIL)
    1841                 :                     {
    1842               0 :                         A_Const    *n = (A_Const *) linitial($3);
    1843                 : 
    1844 LBC           0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1845 UIC           0 :                             ereport(ERROR,
    1846 ECB             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1847                 :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1848                 :                                      parser_errposition(@3)));
    1849                 :                     }
    1850 UIC           0 :                     t->typmods = $3;
    1851               0 :                     $$ = makeStringConstCast($2, @2, t);
    1852                 :                 }
    1853 ECB             :             | ConstInterval '(' Iconst ')' Sconst
    1854                 :                 {
    1855 LBC           0 :                     TypeName   *t = $1;
    1856                 : 
    1857 UIC           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1858 ECB             :                                             makeIntConst($3, @3));
    1859 LBC           0 :                     $$ = makeStringConstCast($5, @5, t);
    1860                 :                 }
    1861 GIC          12 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1862               6 :             | DEFAULT                               { $$ = NULL; }
    1863 LBC           0 :             | LOCAL                                 { $$ = NULL; }
    1864                 :         ;
    1865 ECB             : 
    1866                 : opt_encoding:
    1867 UIC           0 :             Sconst                                  { $$ = $1; }
    1868 UBC           0 :             | DEFAULT                               { $$ = NULL; }
    1869 LBC           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1870 ECB             :         ;
    1871                 : 
    1872                 : NonReservedWord_or_Sconst:
    1873 GIC       47139 :             NonReservedWord                         { $$ = $1; }
    1874            2283 :             | Sconst                                { $$ = $1; }
    1875 ECB             :         ;
    1876                 : 
    1877                 : VariableResetStmt:
    1878 GIC        1782 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1879                 :         ;
    1880                 : 
    1881                 : reset_rest:
    1882            1417 :             generic_reset                           { $$ = $1; }
    1883 ECB             :             | TIME ZONE
    1884                 :                 {
    1885 GIC           6 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1886                 : 
    1887               6 :                     n->kind = VAR_RESET;
    1888               6 :                     n->name = "timezone";
    1889               6 :                     $$ = n;
    1890                 :                 }
    1891                 :             | TRANSACTION ISOLATION LEVEL
    1892                 :                 {
    1893 UIC           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1894                 : 
    1895               0 :                     n->kind = VAR_RESET;
    1896               0 :                     n->name = "transaction_isolation";
    1897 LBC           0 :                     $$ = n;
    1898                 :                 }
    1899                 :             | SESSION AUTHORIZATION
    1900                 :                 {
    1901 CBC         359 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1902                 : 
    1903 GIC         359 :                     n->kind = VAR_RESET;
    1904             359 :                     n->name = "session_authorization";
    1905 GBC         359 :                     $$ = n;
    1906                 :                 }
    1907 EUB             :         ;
    1908                 : 
    1909                 : generic_reset:
    1910                 :             var_name
    1911                 :                 {
    1912 GBC        1433 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1913                 : 
    1914 GIC        1433 :                     n->kind = VAR_RESET;
    1915            1433 :                     n->name = $1;
    1916            1433 :                     $$ = n;
    1917 EUB             :                 }
    1918                 :             | ALL
    1919                 :                 {
    1920 GIC           8 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1921                 : 
    1922 GBC           8 :                     n->kind = VAR_RESET_ALL;
    1923 GIC           8 :                     $$ = n;
    1924 EUB             :                 }
    1925                 :         ;
    1926                 : 
    1927                 : /* SetResetClause allows SET or RESET without LOCAL */
    1928 ECB             : SetResetClause:
    1929 CBC         548 :             SET set_rest                    { $$ = $2; }
    1930 GBC          14 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1931                 :         ;
    1932                 : 
    1933                 : /* SetResetClause allows SET or RESET without LOCAL */
    1934 EUB             : FunctionSetResetClause:
    1935 GBC          47 :             SET set_rest_more               { $$ = $2; }
    1936               6 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    1937                 :         ;
    1938                 : 
    1939                 : 
    1940 ECB             : VariableShowStmt:
    1941                 :             SHOW var_name
    1942                 :                 {
    1943 GIC         376 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1944                 : 
    1945 CBC         376 :                     n->name = $2;
    1946 GIC         376 :                     $$ = (Node *) n;
    1947                 :                 }
    1948                 :             | SHOW TIME ZONE
    1949 ECB             :                 {
    1950 GIC           4 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1951                 : 
    1952 CBC           4 :                     n->name = "timezone";
    1953 GIC           4 :                     $$ = (Node *) n;
    1954 ECB             :                 }
    1955                 :             | SHOW TRANSACTION ISOLATION LEVEL
    1956                 :                 {
    1957 GIC           1 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1958                 : 
    1959               1 :                     n->name = "transaction_isolation";
    1960 GBC           1 :                     $$ = (Node *) n;
    1961                 :                 }
    1962 EUB             :             | SHOW SESSION AUTHORIZATION
    1963                 :                 {
    1964 UBC           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1965                 : 
    1966 UIC           0 :                     n->name = "session_authorization";
    1967               0 :                     $$ = (Node *) n;
    1968 ECB             :                 }
    1969                 :             | SHOW ALL
    1970                 :                 {
    1971 LBC           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    1972 ECB             : 
    1973 UIC           0 :                     n->name = "all";
    1974               0 :                     $$ = (Node *) n;
    1975                 :                 }
    1976                 :         ;
    1977                 : 
    1978                 : 
    1979 ECB             : ConstraintsSetStmt:
    1980                 :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    1981                 :                 {
    1982 CBC          52 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    1983 ECB             : 
    1984 GIC          52 :                     n->constraints = $3;
    1985              52 :                     n->deferred = $4;
    1986              52 :                     $$ = (Node *) n;
    1987 ECB             :                 }
    1988                 :         ;
    1989                 : 
    1990                 : constraints_set_list:
    1991 GIC          28 :             ALL                                     { $$ = NIL; }
    1992              24 :             | qualified_name_list                   { $$ = $1; }
    1993                 :         ;
    1994                 : 
    1995                 : constraints_set_mode:
    1996 CBC          34 :             DEFERRED                                { $$ = true; }
    1997              18 :             | IMMEDIATE                             { $$ = false; }
    1998                 :         ;
    1999                 : 
    2000                 : 
    2001                 : /*
    2002 ECB             :  * Checkpoint statement
    2003                 :  */
    2004                 : CheckPointStmt:
    2005                 :             CHECKPOINT
    2006                 :                 {
    2007 GIC          77 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2008                 : 
    2009              77 :                     $$ = (Node *) n;
    2010 ECB             :                 }
    2011                 :         ;
    2012                 : 
    2013                 : 
    2014                 : /*****************************************************************************
    2015                 :  *
    2016                 :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2017                 :  *
    2018                 :  *****************************************************************************/
    2019                 : 
    2020                 : DiscardStmt:
    2021                 :             DISCARD ALL
    2022                 :                 {
    2023 GIC           3 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2024 ECB             : 
    2025 GIC           3 :                     n->target = DISCARD_ALL;
    2026 CBC           3 :                     $$ = (Node *) n;
    2027 ECB             :                 }
    2028                 :             | DISCARD TEMP
    2029                 :                 {
    2030 GIC           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2031 EUB             : 
    2032 GIC           4 :                     n->target = DISCARD_TEMP;
    2033 GBC           4 :                     $$ = (Node *) n;
    2034 EUB             :                 }
    2035                 :             | DISCARD TEMPORARY
    2036                 :                 {
    2037 UIC           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2038 EUB             : 
    2039 UIC           0 :                     n->target = DISCARD_TEMP;
    2040 UBC           0 :                     $$ = (Node *) n;
    2041 EUB             :                 }
    2042                 :             | DISCARD PLANS
    2043                 :                 {
    2044 GIC           2 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2045                 : 
    2046               2 :                     n->target = DISCARD_PLANS;
    2047               2 :                     $$ = (Node *) n;
    2048                 :                 }
    2049 ECB             :             | DISCARD SEQUENCES
    2050                 :                 {
    2051 CBC           6 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2052 ECB             : 
    2053 CBC           6 :                     n->target = DISCARD_SEQUENCES;
    2054 GIC           6 :                     $$ = (Node *) n;
    2055                 :                 }
    2056                 : 
    2057                 :         ;
    2058 ECB             : 
    2059                 : 
    2060                 : /*****************************************************************************
    2061                 :  *
    2062                 :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2063                 :  *
    2064                 :  * Note: we accept all subcommands for each of the variants, and sort
    2065                 :  * out what's really legal at execution time.
    2066                 :  *****************************************************************************/
    2067                 : 
    2068                 : AlterTableStmt:
    2069                 :             ALTER TABLE relation_expr alter_table_cmds
    2070                 :                 {
    2071 GIC       39413 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2072                 : 
    2073           39413 :                     n->relation = $3;
    2074 CBC       39413 :                     n->cmds = $4;
    2075 GIC       39413 :                     n->objtype = OBJECT_TABLE;
    2076 CBC       39413 :                     n->missing_ok = false;
    2077 GIC       39413 :                     $$ = (Node *) n;
    2078                 :                 }
    2079                 :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2080                 :                 {
    2081              27 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2082                 : 
    2083              27 :                     n->relation = $5;
    2084              27 :                     n->cmds = $6;
    2085              27 :                     n->objtype = OBJECT_TABLE;
    2086              27 :                     n->missing_ok = true;
    2087              27 :                     $$ = (Node *) n;
    2088                 :                 }
    2089                 :         |   ALTER TABLE relation_expr partition_cmd
    2090 ECB             :                 {
    2091 GIC        1320 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2092 ECB             : 
    2093 CBC        1320 :                     n->relation = $3;
    2094 GIC        1320 :                     n->cmds = list_make1($4);
    2095            1320 :                     n->objtype = OBJECT_TABLE;
    2096            1320 :                     n->missing_ok = false;
    2097 CBC        1320 :                     $$ = (Node *) n;
    2098                 :                 }
    2099 ECB             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2100                 :                 {
    2101 UIC           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2102                 : 
    2103               0 :                     n->relation = $5;
    2104 UBC           0 :                     n->cmds = list_make1($6);
    2105 UIC           0 :                     n->objtype = OBJECT_TABLE;
    2106 UBC           0 :                     n->missing_ok = true;
    2107               0 :                     $$ = (Node *) n;
    2108                 :                 }
    2109                 :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2110                 :                 {
    2111 CBC           6 :                     AlterTableMoveAllStmt *n =
    2112 GIC           6 :                         makeNode(AlterTableMoveAllStmt);
    2113 ECB             : 
    2114 CBC           6 :                     n->orig_tablespacename = $6;
    2115 GIC           6 :                     n->objtype = OBJECT_TABLE;
    2116               6 :                     n->roles = NIL;
    2117               6 :                     n->new_tablespacename = $9;
    2118 CBC           6 :                     n->nowait = $10;
    2119 GIC           6 :                     $$ = (Node *) n;
    2120 ECB             :                 }
    2121                 :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2122                 :                 {
    2123 UIC           0 :                     AlterTableMoveAllStmt *n =
    2124               0 :                         makeNode(AlterTableMoveAllStmt);
    2125                 : 
    2126               0 :                     n->orig_tablespacename = $6;
    2127               0 :                     n->objtype = OBJECT_TABLE;
    2128               0 :                     n->roles = $9;
    2129               0 :                     n->new_tablespacename = $12;
    2130               0 :                     n->nowait = $13;
    2131               0 :                     $$ = (Node *) n;
    2132                 :                 }
    2133                 :         |   ALTER INDEX qualified_name alter_table_cmds
    2134                 :                 {
    2135 GIC         113 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2136                 : 
    2137             113 :                     n->relation = $3;
    2138 CBC         113 :                     n->cmds = $4;
    2139 GIC         113 :                     n->objtype = OBJECT_INDEX;
    2140 CBC         113 :                     n->missing_ok = false;
    2141             113 :                     $$ = (Node *) n;
    2142 ECB             :                 }
    2143                 :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2144                 :                 {
    2145 UIC           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2146                 : 
    2147               0 :                     n->relation = $5;
    2148 LBC           0 :                     n->cmds = $6;
    2149 UIC           0 :                     n->objtype = OBJECT_INDEX;
    2150 LBC           0 :                     n->missing_ok = true;
    2151               0 :                     $$ = (Node *) n;
    2152 ECB             :                 }
    2153                 :         |   ALTER INDEX qualified_name index_partition_cmd
    2154                 :                 {
    2155 GIC         189 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2156                 : 
    2157             189 :                     n->relation = $3;
    2158 CBC         189 :                     n->cmds = list_make1($4);
    2159 GIC         189 :                     n->objtype = OBJECT_INDEX;
    2160 CBC         189 :                     n->missing_ok = false;
    2161             189 :                     $$ = (Node *) n;
    2162 ECB             :                 }
    2163                 :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2164                 :                 {
    2165 GIC           3 :                     AlterTableMoveAllStmt *n =
    2166               3 :                         makeNode(AlterTableMoveAllStmt);
    2167                 : 
    2168 GBC           3 :                     n->orig_tablespacename = $6;
    2169 GIC           3 :                     n->objtype = OBJECT_INDEX;
    2170 GBC           3 :                     n->roles = NIL;
    2171               3 :                     n->new_tablespacename = $9;
    2172               3 :                     n->nowait = $10;
    2173               3 :                     $$ = (Node *) n;
    2174 EUB             :                 }
    2175                 :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2176                 :                 {
    2177 UIC           0 :                     AlterTableMoveAllStmt *n =
    2178 LBC           0 :                         makeNode(AlterTableMoveAllStmt);
    2179 ECB             : 
    2180 UIC           0 :                     n->orig_tablespacename = $6;
    2181 LBC           0 :                     n->objtype = OBJECT_INDEX;
    2182               0 :                     n->roles = $9;
    2183               0 :                     n->new_tablespacename = $12;
    2184               0 :                     n->nowait = $13;
    2185               0 :                     $$ = (Node *) n;
    2186 ECB             :                 }
    2187                 :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2188                 :                 {
    2189 GIC          32 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2190 EUB             : 
    2191 GBC          32 :                     n->relation = $3;
    2192 GIC          32 :                     n->cmds = $4;
    2193 GBC          32 :                     n->objtype = OBJECT_SEQUENCE;
    2194              32 :                     n->missing_ok = false;
    2195              32 :                     $$ = (Node *) n;
    2196 EUB             :                 }
    2197                 :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2198                 :                 {
    2199 UIC           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2200                 : 
    2201               0 :                     n->relation = $5;
    2202 LBC           0 :                     n->cmds = $6;
    2203 UIC           0 :                     n->objtype = OBJECT_SEQUENCE;
    2204 LBC           0 :                     n->missing_ok = true;
    2205               0 :                     $$ = (Node *) n;
    2206 ECB             :                 }
    2207                 :         |   ALTER VIEW qualified_name alter_table_cmds
    2208                 :                 {
    2209 GIC         119 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2210                 : 
    2211             119 :                     n->relation = $3;
    2212 GBC         119 :                     n->cmds = $4;
    2213 GIC         119 :                     n->objtype = OBJECT_VIEW;
    2214 GBC         119 :                     n->missing_ok = false;
    2215             119 :                     $$ = (Node *) n;
    2216 EUB             :                 }
    2217                 :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2218                 :                 {
    2219 UIC           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2220                 : 
    2221               0 :                     n->relation = $5;
    2222 LBC           0 :                     n->cmds = $6;
    2223 UIC           0 :                     n->objtype = OBJECT_VIEW;
    2224 LBC           0 :                     n->missing_ok = true;
    2225               0 :                     $$ = (Node *) n;
    2226 ECB             :                 }
    2227                 :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2228                 :                 {
    2229 GIC          24 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2230                 : 
    2231              24 :                     n->relation = $4;
    2232 CBC          24 :                     n->cmds = $5;
    2233              24 :                     n->objtype = OBJECT_MATVIEW;
    2234 GIC          24 :                     n->missing_ok = false;
    2235 CBC          24 :                     $$ = (Node *) n;
    2236 ECB             :                 }
    2237                 :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2238                 :                 {
    2239 LBC           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2240 ECB             : 
    2241 UIC           0 :                     n->relation = $6;
    2242               0 :                     n->cmds = $7;
    2243               0 :                     n->objtype = OBJECT_MATVIEW;
    2244 UBC           0 :                     n->missing_ok = true;
    2245               0 :                     $$ = (Node *) n;
    2246                 :                 }
    2247 EUB             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2248                 :                 {
    2249 GBC           6 :                     AlterTableMoveAllStmt *n =
    2250               6 :                         makeNode(AlterTableMoveAllStmt);
    2251 EUB             : 
    2252 GBC           6 :                     n->orig_tablespacename = $7;
    2253 GIC           6 :                     n->objtype = OBJECT_MATVIEW;
    2254               6 :                     n->roles = NIL;
    2255               6 :                     n->new_tablespacename = $10;
    2256 CBC           6 :                     n->nowait = $11;
    2257 GIC           6 :                     $$ = (Node *) n;
    2258 ECB             :                 }
    2259                 :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2260                 :                 {
    2261 LBC           0 :                     AlterTableMoveAllStmt *n =
    2262               0 :                         makeNode(AlterTableMoveAllStmt);
    2263                 : 
    2264 UIC           0 :                     n->orig_tablespacename = $7;
    2265               0 :                     n->objtype = OBJECT_MATVIEW;
    2266 UBC           0 :                     n->roles = $10;
    2267 UIC           0 :                     n->new_tablespacename = $13;
    2268 UBC           0 :                     n->nowait = $14;
    2269               0 :                     $$ = (Node *) n;
    2270 EUB             :                 }
    2271                 :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2272                 :                 {
    2273 GIC         178 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2274                 : 
    2275             178 :                     n->relation = $4;
    2276 CBC         178 :                     n->cmds = $5;
    2277 GIC         178 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2278 CBC         178 :                     n->missing_ok = false;
    2279             178 :                     $$ = (Node *) n;
    2280 ECB             :                 }
    2281                 :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2282                 :                 {
    2283 GIC          54 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2284                 : 
    2285              54 :                     n->relation = $6;
    2286 GBC          54 :                     n->cmds = $7;
    2287 GIC          54 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2288 GBC          54 :                     n->missing_ok = true;
    2289              54 :                     $$ = (Node *) n;
    2290 EUB             :                 }
    2291                 :         ;
    2292                 : 
    2293                 : alter_table_cmds:
    2294 GIC       39960 :             alter_table_cmd                         { $$ = list_make1($1); }
    2295             408 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2296 ECB             :         ;
    2297                 : 
    2298                 : partition_cmd:
    2299                 :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2300                 :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2301                 :                 {
    2302 CBC        1052 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2303 GIC        1052 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2304                 : 
    2305            1052 :                     n->subtype = AT_AttachPartition;
    2306 GBC        1052 :                     cmd->name = $3;
    2307 GIC        1052 :                     cmd->bound = $4;
    2308 GBC        1052 :                     cmd->concurrent = false;
    2309            1052 :                     n->def = (Node *) cmd;
    2310 EUB             : 
    2311 GBC        1052 :                     $$ = (Node *) n;
    2312 EUB             :                 }
    2313                 :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2314                 :             | DETACH PARTITION qualified_name opt_concurrently
    2315                 :                 {
    2316 CBC         261 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2317             261 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2318                 : 
    2319             261 :                     n->subtype = AT_DetachPartition;
    2320             261 :                     cmd->name = $3;
    2321             261 :                     cmd->bound = NULL;
    2322             261 :                     cmd->concurrent = $4;
    2323             261 :                     n->def = (Node *) cmd;
    2324 ECB             : 
    2325 GIC         261 :                     $$ = (Node *) n;
    2326                 :                 }
    2327                 :             | DETACH PARTITION qualified_name FINALIZE
    2328 EUB             :                 {
    2329 GBC           7 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2330 GIC           7 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2331 EUB             : 
    2332 GBC           7 :                     n->subtype = AT_DetachPartitionFinalize;
    2333               7 :                     cmd->name = $3;
    2334               7 :                     cmd->bound = NULL;
    2335               7 :                     cmd->concurrent = false;
    2336               7 :                     n->def = (Node *) cmd;
    2337 GIC           7 :                     $$ = (Node *) n;
    2338                 :                 }
    2339                 :         ;
    2340 ECB             : 
    2341                 : index_partition_cmd:
    2342                 :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2343                 :             ATTACH PARTITION qualified_name
    2344                 :                 {
    2345 CBC         189 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2346             189 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2347                 : 
    2348 GIC         189 :                     n->subtype = AT_AttachPartition;
    2349             189 :                     cmd->name = $3;
    2350 CBC         189 :                     cmd->bound = NULL;
    2351 GIC         189 :                     cmd->concurrent = false;
    2352 CBC         189 :                     n->def = (Node *) cmd;
    2353 ECB             : 
    2354 CBC         189 :                     $$ = (Node *) n;
    2355 ECB             :                 }
    2356                 :         ;
    2357                 : 
    2358                 : alter_table_cmd:
    2359                 :             /* ALTER TABLE <name> ADD <coldef> */
    2360                 :             ADD_P columnDef
    2361                 :                 {
    2362 CBC          82 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2363                 : 
    2364 GIC          82 :                     n->subtype = AT_AddColumn;
    2365              82 :                     n->def = $2;
    2366              82 :                     n->missing_ok = false;
    2367              82 :                     $$ = (Node *) n;
    2368                 :                 }
    2369 ECB             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2370                 :             | ADD_P IF_P NOT EXISTS columnDef
    2371                 :                 {
    2372 LBC           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2373 ECB             : 
    2374 LBC           0 :                     n->subtype = AT_AddColumn;
    2375               0 :                     n->def = $5;
    2376               0 :                     n->missing_ok = true;
    2377 UIC           0 :                     $$ = (Node *) n;
    2378 ECB             :                 }
    2379                 :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2380                 :             | ADD_P COLUMN columnDef
    2381                 :                 {
    2382 GIC         791 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2383 ECB             : 
    2384 CBC         791 :                     n->subtype = AT_AddColumn;
    2385 GIC         791 :                     n->def = $3;
    2386 CBC         791 :                     n->missing_ok = false;
    2387             791 :                     $$ = (Node *) n;
    2388 ECB             :                 }
    2389                 :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2390                 :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2391                 :                 {
    2392 CBC          30 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2393                 : 
    2394 GIC          30 :                     n->subtype = AT_AddColumn;
    2395              30 :                     n->def = $6;
    2396 CBC          30 :                     n->missing_ok = true;
    2397              30 :                     $$ = (Node *) n;
    2398                 :                 }
    2399 ECB             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2400                 :             | ALTER opt_column ColId alter_column_default
    2401                 :                 {
    2402 CBC         249 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2403 ECB             : 
    2404 CBC         249 :                     n->subtype = AT_ColumnDefault;
    2405 GIC         249 :                     n->name = $3;
    2406             249 :                     n->def = $4;
    2407             249 :                     $$ = (Node *) n;
    2408                 :                 }
    2409                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2410                 :             | ALTER opt_column ColId DROP NOT NULL_P
    2411                 :                 {
    2412 CBC         120 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2413 ECB             : 
    2414 GIC         120 :                     n->subtype = AT_DropNotNull;
    2415 CBC         120 :                     n->name = $3;
    2416             120 :                     $$ = (Node *) n;
    2417 ECB             :                 }
    2418                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2419                 :             | ALTER opt_column ColId SET NOT NULL_P
    2420                 :                 {
    2421 CBC         172 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2422                 : 
    2423 GIC         172 :                     n->subtype = AT_SetNotNull;
    2424             172 :                     n->name = $3;
    2425             172 :                     $$ = (Node *) n;
    2426                 :                 }
    2427                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2428                 :             | ALTER opt_column ColId DROP EXPRESSION
    2429 ECB             :                 {
    2430 GIC          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2431 ECB             : 
    2432 CBC          16 :                     n->subtype = AT_DropExpression;
    2433              16 :                     n->name = $3;
    2434              16 :                     $$ = (Node *) n;
    2435                 :                 }
    2436                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2437                 :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2438                 :                 {
    2439 GBC           3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2440                 : 
    2441               3 :                     n->subtype = AT_DropExpression;
    2442               3 :                     n->name = $3;
    2443               3 :                     n->missing_ok = true;
    2444               3 :                     $$ = (Node *) n;
    2445                 :                 }
    2446                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS <SignedIconst> */
    2447                 :             | ALTER opt_column ColId SET STATISTICS SignedIconst
    2448                 :                 {
    2449 CBC          31 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2450                 : 
    2451              31 :                     n->subtype = AT_SetStatistics;
    2452              31 :                     n->name = $3;
    2453              31 :                     n->def = (Node *) makeInteger($6);
    2454              31 :                     $$ = (Node *) n;
    2455                 :                 }
    2456                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS <SignedIconst> */
    2457                 :             | ALTER opt_column Iconst SET STATISTICS SignedIconst
    2458                 :                 {
    2459              35 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2460                 : 
    2461              35 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2462               3 :                         ereport(ERROR,
    2463 ECB             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2464                 :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2465                 :                                  parser_errposition(@3)));
    2466                 : 
    2467 GIC          32 :                     n->subtype = AT_SetStatistics;
    2468              32 :                     n->num = (int16) $3;
    2469 CBC          32 :                     n->def = (Node *) makeInteger($6);
    2470 GIC          32 :                     $$ = (Node *) n;
    2471 ECB             :                 }
    2472                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2473                 :             | ALTER opt_column ColId SET reloptions
    2474                 :                 {
    2475 GIC          19 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2476                 : 
    2477              19 :                     n->subtype = AT_SetOptions;
    2478              19 :                     n->name = $3;
    2479 CBC          19 :                     n->def = (Node *) $5;
    2480 GIC          19 :                     $$ = (Node *) n;
    2481 ECB             :                 }
    2482                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2483                 :             | ALTER opt_column ColId RESET reloptions
    2484                 :                 {
    2485 GIC           3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2486                 : 
    2487               3 :                     n->subtype = AT_ResetOptions;
    2488 CBC           3 :                     n->name = $3;
    2489 GIC           3 :                     n->def = (Node *) $5;
    2490 CBC           3 :                     $$ = (Node *) n;
    2491 ECB             :                 }
    2492                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2493                 :             | ALTER opt_column ColId SET column_storage
    2494                 :                 {
    2495 GIC         104 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2496                 : 
    2497 CBC         104 :                     n->subtype = AT_SetStorage;
    2498 GIC         104 :                     n->name = $3;
    2499 GNC         104 :                     n->def = (Node *) makeString($5);
    2500 CBC         104 :                     $$ = (Node *) n;
    2501 ECB             :                 }
    2502                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2503                 :             | ALTER opt_column ColId SET column_compression
    2504                 :                 {
    2505 GIC          33 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2506 ECB             : 
    2507 GIC          33 :                     n->subtype = AT_SetCompression;
    2508 CBC          33 :                     n->name = $3;
    2509              33 :                     n->def = (Node *) makeString($5);
    2510              33 :                     $$ = (Node *) n;
    2511 ECB             :                 }
    2512                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2513                 :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2514                 :                 {
    2515 GIC          51 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2516 CBC          51 :                     Constraint *c = makeNode(Constraint);
    2517                 : 
    2518              51 :                     c->contype = CONSTR_IDENTITY;
    2519              51 :                     c->generated_when = $6;
    2520              51 :                     c->options = $9;
    2521              51 :                     c->location = @5;
    2522                 : 
    2523 GIC          51 :                     n->subtype = AT_AddIdentity;
    2524              51 :                     n->name = $3;
    2525              51 :                     n->def = (Node *) c;
    2526 ECB             : 
    2527 GIC          51 :                     $$ = (Node *) n;
    2528 ECB             :                 }
    2529                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2530                 :             | ALTER opt_column ColId alter_identity_column_option_list
    2531                 :                 {
    2532 GIC          19 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2533                 : 
    2534 CBC          19 :                     n->subtype = AT_SetIdentity;
    2535              19 :                     n->name = $3;
    2536              19 :                     n->def = (Node *) $4;
    2537              19 :                     $$ = (Node *) n;
    2538                 :                 }
    2539                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2540                 :             | ALTER opt_column ColId DROP IDENTITY_P
    2541                 :                 {
    2542              16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2543                 : 
    2544              16 :                     n->subtype = AT_DropIdentity;
    2545              16 :                     n->name = $3;
    2546              16 :                     n->missing_ok = false;
    2547              16 :                     $$ = (Node *) n;
    2548                 :                 }
    2549                 :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2550                 :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2551                 :                 {
    2552               3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2553                 : 
    2554               3 :                     n->subtype = AT_DropIdentity;
    2555               3 :                     n->name = $3;
    2556               3 :                     n->missing_ok = true;
    2557               3 :                     $$ = (Node *) n;
    2558                 :                 }
    2559                 :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2560                 :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2561                 :                 {
    2562               9 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2563                 : 
    2564               9 :                     n->subtype = AT_DropColumn;
    2565               9 :                     n->name = $5;
    2566               9 :                     n->behavior = $6;
    2567               9 :                     n->missing_ok = true;
    2568 GIC           9 :                     $$ = (Node *) n;
    2569                 :                 }
    2570                 :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2571                 :             | DROP opt_column ColId opt_drop_behavior
    2572 ECB             :                 {
    2573 GIC         740 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2574 ECB             : 
    2575 CBC         740 :                     n->subtype = AT_DropColumn;
    2576             740 :                     n->name = $3;
    2577             740 :                     n->behavior = $4;
    2578 GIC         740 :                     n->missing_ok = false;
    2579             740 :                     $$ = (Node *) n;
    2580                 :                 }
    2581                 :             /*
    2582 ECB             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2583                 :              *      [ USING <expression> ]
    2584                 :              */
    2585                 :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2586                 :                 {
    2587 CBC         412 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2588             412 :                     ColumnDef *def = makeNode(ColumnDef);
    2589                 : 
    2590             412 :                     n->subtype = AT_AlterColumnType;
    2591             412 :                     n->name = $3;
    2592             412 :                     n->def = (Node *) def;
    2593                 :                     /* We only use these fields of the ColumnDef node */
    2594             412 :                     def->typeName = $6;
    2595 GIC         412 :                     def->collClause = (CollateClause *) $7;
    2596             412 :                     def->raw_default = $8;
    2597             412 :                     def->location = @3;
    2598             412 :                     $$ = (Node *) n;
    2599 ECB             :                 }
    2600                 :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2601                 :             | ALTER opt_column ColId alter_generic_options
    2602                 :                 {
    2603 CBC          25 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2604 ECB             : 
    2605 GIC          25 :                     n->subtype = AT_AlterColumnGenericOptions;
    2606              25 :                     n->name = $3;
    2607              25 :                     n->def = (Node *) $4;
    2608              25 :                     $$ = (Node *) n;
    2609 ECB             :                 }
    2610                 :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2611                 :             | ADD_P TableConstraint
    2612                 :                 {
    2613 CBC       34735 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2614 ECB             : 
    2615 GIC       34735 :                     n->subtype = AT_AddConstraint;
    2616           34735 :                     n->def = $2;
    2617           34735 :                     $$ = (Node *) n;
    2618                 :                 }
    2619 ECB             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2620                 :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2621                 :                 {
    2622 CBC          36 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2623              36 :                     Constraint *c = makeNode(Constraint);
    2624 ECB             : 
    2625 GIC          36 :                     n->subtype = AT_AlterConstraint;
    2626              36 :                     n->def = (Node *) c;
    2627              36 :                     c->contype = CONSTR_FOREIGN; /* others not supported, yet */
    2628              36 :                     c->conname = $3;
    2629 CBC          36 :                     processCASbits($4, @4, "ALTER CONSTRAINT statement",
    2630                 :                                     &c->deferrable,
    2631 ECB             :                                     &c->initdeferred,
    2632                 :                                     NULL, NULL, yyscanner);
    2633 CBC          36 :                     $$ = (Node *) n;
    2634 ECB             :                 }
    2635                 :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2636                 :             | VALIDATE CONSTRAINT name
    2637                 :                 {
    2638 GIC         194 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2639                 : 
    2640 CBC         194 :                     n->subtype = AT_ValidateConstraint;
    2641 GIC         194 :                     n->name = $3;
    2642 CBC         194 :                     $$ = (Node *) n;
    2643 ECB             :                 }
    2644                 :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2645                 :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2646                 :                 {
    2647 GIC           9 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2648                 : 
    2649               9 :                     n->subtype = AT_DropConstraint;
    2650               9 :                     n->name = $5;
    2651               9 :                     n->behavior = $6;
    2652               9 :                     n->missing_ok = true;
    2653               9 :                     $$ = (Node *) n;
    2654 ECB             :                 }
    2655                 :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2656                 :             | DROP CONSTRAINT name opt_drop_behavior
    2657                 :                 {
    2658 CBC         264 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2659 ECB             : 
    2660 GIC         264 :                     n->subtype = AT_DropConstraint;
    2661 CBC         264 :                     n->name = $3;
    2662             264 :                     n->behavior = $4;
    2663             264 :                     n->missing_ok = false;
    2664             264 :                     $$ = (Node *) n;
    2665 ECB             :                 }
    2666                 :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2667                 :             | SET WITHOUT OIDS
    2668                 :                 {
    2669 GIC           3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2670 ECB             : 
    2671 GIC           3 :                     n->subtype = AT_DropOids;
    2672 CBC           3 :                     $$ = (Node *) n;
    2673 ECB             :                 }
    2674                 :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2675                 :             | CLUSTER ON name
    2676                 :                 {
    2677 GIC          23 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2678                 : 
    2679              23 :                     n->subtype = AT_ClusterOn;
    2680 CBC          23 :                     n->name = $3;
    2681 GIC          23 :                     $$ = (Node *) n;
    2682 ECB             :                 }
    2683                 :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2684                 :             | SET WITHOUT CLUSTER
    2685                 :                 {
    2686 GIC           9 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2687                 : 
    2688               9 :                     n->subtype = AT_DropCluster;
    2689 CBC           9 :                     n->name = NULL;
    2690               9 :                     $$ = (Node *) n;
    2691                 :                 }
    2692 ECB             :             /* ALTER TABLE <name> SET LOGGED */
    2693                 :             | SET LOGGED
    2694                 :                 {
    2695 CBC          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2696 ECB             : 
    2697 GIC          16 :                     n->subtype = AT_SetLogged;
    2698              16 :                     $$ = (Node *) n;
    2699                 :                 }
    2700 ECB             :             /* ALTER TABLE <name> SET UNLOGGED */
    2701                 :             | SET UNLOGGED
    2702                 :                 {
    2703 GIC          19 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2704                 : 
    2705 CBC          19 :                     n->subtype = AT_SetUnLogged;
    2706 GIC          19 :                     $$ = (Node *) n;
    2707 ECB             :                 }
    2708                 :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2709                 :             | ENABLE_P TRIGGER name
    2710                 :                 {
    2711 GIC          60 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2712                 : 
    2713              60 :                     n->subtype = AT_EnableTrig;
    2714 CBC          60 :                     n->name = $3;
    2715 GIC          60 :                     $$ = (Node *) n;
    2716 ECB             :                 }
    2717                 :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2718                 :             | ENABLE_P ALWAYS TRIGGER name
    2719                 :                 {
    2720 CBC          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2721                 : 
    2722 GIC          20 :                     n->subtype = AT_EnableAlwaysTrig;
    2723              20 :                     n->name = $4;
    2724              20 :                     $$ = (Node *) n;
    2725 ECB             :                 }
    2726                 :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2727                 :             | ENABLE_P REPLICA TRIGGER name
    2728                 :                 {
    2729 CBC           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2730 ECB             : 
    2731 CBC           8 :                     n->subtype = AT_EnableReplicaTrig;
    2732 GIC           8 :                     n->name = $4;
    2733               8 :                     $$ = (Node *) n;
    2734                 :                 }
    2735                 :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2736 ECB             :             | ENABLE_P TRIGGER ALL
    2737                 :                 {
    2738 LBC           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2739 ECB             : 
    2740 UIC           0 :                     n->subtype = AT_EnableTrigAll;
    2741               0 :                     $$ = (Node *) n;
    2742                 :                 }
    2743                 :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2744 ECB             :             | ENABLE_P TRIGGER USER
    2745                 :                 {
    2746 LBC           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2747 ECB             : 
    2748 LBC           0 :                     n->subtype = AT_EnableTrigUser;
    2749 UIC           0 :                     $$ = (Node *) n;
    2750                 :                 }
    2751                 :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2752                 :             | DISABLE_P TRIGGER name
    2753 ECB             :                 {
    2754 GIC          68 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2755 ECB             : 
    2756 CBC          68 :                     n->subtype = AT_DisableTrig;
    2757              68 :                     n->name = $3;
    2758 GIC          68 :                     $$ = (Node *) n;
    2759                 :                 }
    2760                 :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2761                 :             | DISABLE_P TRIGGER ALL
    2762 ECB             :                 {
    2763 GIC           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2764 ECB             : 
    2765 CBC           6 :                     n->subtype = AT_DisableTrigAll;
    2766 GIC           6 :                     $$ = (Node *) n;
    2767                 :                 }
    2768                 :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2769                 :             | DISABLE_P TRIGGER USER
    2770 ECB             :                 {
    2771 GIC           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2772 ECB             : 
    2773 CBC           6 :                     n->subtype = AT_DisableTrigUser;
    2774 GIC           6 :                     $$ = (Node *) n;
    2775                 :                 }
    2776                 :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2777                 :             | ENABLE_P RULE name
    2778 ECB             :                 {
    2779 GIC           3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2780 ECB             : 
    2781 CBC           3 :                     n->subtype = AT_EnableRule;
    2782               3 :                     n->name = $3;
    2783 GIC           3 :                     $$ = (Node *) n;
    2784                 :                 }
    2785                 :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2786                 :             | ENABLE_P ALWAYS RULE name
    2787 ECB             :                 {
    2788 UIC           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2789 ECB             : 
    2790 LBC           0 :                     n->subtype = AT_EnableAlwaysRule;
    2791               0 :                     n->name = $4;
    2792 UIC           0 :                     $$ = (Node *) n;
    2793                 :                 }
    2794                 :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2795                 :             | ENABLE_P REPLICA RULE name
    2796 ECB             :                 {
    2797 GIC           3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2798 ECB             : 
    2799 CBC           3 :                     n->subtype = AT_EnableReplicaRule;
    2800               3 :                     n->name = $4;
    2801 GIC           3 :                     $$ = (Node *) n;
    2802                 :                 }
    2803                 :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2804                 :             | DISABLE_P RULE name
    2805 EUB             :                 {
    2806 GIC           3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2807 EUB             : 
    2808 GBC           3 :                     n->subtype = AT_DisableRule;
    2809 GIC           3 :                     n->name = $3;
    2810               3 :                     $$ = (Node *) n;
    2811                 :                 }
    2812                 :             /* ALTER TABLE <name> INHERIT <parent> */
    2813 EUB             :             | INHERIT qualified_name
    2814                 :                 {
    2815 GBC         143 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2816 EUB             : 
    2817 GIC         143 :                     n->subtype = AT_AddInherit;
    2818             143 :                     n->def = (Node *) $2;
    2819             143 :                     $$ = (Node *) n;
    2820                 :                 }
    2821 ECB             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2822                 :             | NO INHERIT qualified_name
    2823                 :                 {
    2824 CBC          22 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2825 ECB             : 
    2826 GIC          22 :                     n->subtype = AT_DropInherit;
    2827              22 :                     n->def = (Node *) $3;
    2828              22 :                     $$ = (Node *) n;
    2829                 :                 }
    2830 ECB             :             /* ALTER TABLE <name> OF <type_name> */
    2831                 :             | OF any_name
    2832                 :                 {
    2833 CBC          33 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2834 GIC          33 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2835                 : 
    2836              33 :                     def->location = @2;
    2837              33 :                     n->subtype = AT_AddOf;
    2838 CBC          33 :                     n->def = (Node *) def;
    2839 GIC          33 :                     $$ = (Node *) n;
    2840 ECB             :                 }
    2841                 :             /* ALTER TABLE <name> NOT OF */
    2842                 :             | NOT OF
    2843                 :                 {
    2844 GIC           3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2845                 : 
    2846 CBC           3 :                     n->subtype = AT_DropOf;
    2847 GIC           3 :                     $$ = (Node *) n;
    2848 ECB             :                 }
    2849                 :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2850                 :             | OWNER TO RoleSpec
    2851                 :                 {
    2852 GIC         861 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2853                 : 
    2854             861 :                     n->subtype = AT_ChangeOwner;
    2855 GBC         861 :                     n->newowner = $3;
    2856 GIC         861 :                     $$ = (Node *) n;
    2857 EUB             :                 }
    2858                 :             /* ALTER TABLE <name> SET ACCESS METHOD <amname> */
    2859                 :             | SET ACCESS METHOD name
    2860                 :                 {
    2861 GIC          24 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2862                 : 
    2863              24 :                     n->subtype = AT_SetAccessMethod;
    2864 CBC          24 :                     n->name = $4;
    2865 GIC          24 :                     $$ = (Node *) n;
    2866 ECB             :                 }
    2867                 :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    2868                 :             | SET TABLESPACE name
    2869                 :                 {
    2870 GIC          52 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2871                 : 
    2872              52 :                     n->subtype = AT_SetTableSpace;
    2873 CBC          52 :                     n->name = $3;
    2874 GIC          52 :                     $$ = (Node *) n;
    2875 ECB             :                 }
    2876                 :             /* ALTER TABLE <name> SET (...) */
    2877                 :             | SET reloptions
    2878                 :                 {
    2879 GIC         291 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2880                 : 
    2881             291 :                     n->subtype = AT_SetRelOptions;
    2882 CBC         291 :                     n->def = (Node *) $2;
    2883 GIC         291 :                     $$ = (Node *) n;
    2884 ECB             :                 }
    2885                 :             /* ALTER TABLE <name> RESET (...) */
    2886                 :             | RESET reloptions
    2887                 :                 {
    2888 GIC          76 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2889                 : 
    2890              76 :                     n->subtype = AT_ResetRelOptions;
    2891 CBC          76 :                     n->def = (Node *) $2;
    2892 GIC          76 :                     $$ = (Node *) n;
    2893 ECB             :                 }
    2894                 :             /* ALTER TABLE <name> REPLICA IDENTITY */
    2895                 :             | REPLICA IDENTITY_P replica_identity
    2896                 :                 {
    2897 GIC         198 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2898                 : 
    2899             198 :                     n->subtype = AT_ReplicaIdentity;
    2900 CBC         198 :                     n->def = $3;
    2901             198 :                     $$ = (Node *) n;
    2902                 :                 }
    2903 ECB             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    2904                 :             | ENABLE_P ROW LEVEL SECURITY
    2905                 :                 {
    2906 CBC         135 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2907                 : 
    2908 GIC         135 :                     n->subtype = AT_EnableRowSecurity;
    2909             135 :                     $$ = (Node *) n;
    2910                 :                 }
    2911 ECB             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    2912                 :             | DISABLE_P ROW LEVEL SECURITY
    2913                 :                 {
    2914 CBC           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2915                 : 
    2916 GIC           4 :                     n->subtype = AT_DisableRowSecurity;
    2917               4 :                     $$ = (Node *) n;
    2918                 :                 }
    2919 ECB             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    2920                 :             | FORCE ROW LEVEL SECURITY
    2921                 :                 {
    2922 CBC          40 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2923 ECB             : 
    2924 GIC          40 :                     n->subtype = AT_ForceRowSecurity;
    2925              40 :                     $$ = (Node *) n;
    2926                 :                 }
    2927                 :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    2928 ECB             :             | NO FORCE ROW LEVEL SECURITY
    2929                 :                 {
    2930 CBC          15 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2931 ECB             : 
    2932 CBC          15 :                     n->subtype = AT_NoForceRowSecurity;
    2933 GIC          15 :                     $$ = (Node *) n;
    2934                 :                 }
    2935                 :             | alter_generic_options
    2936                 :                 {
    2937 CBC          26 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2938                 : 
    2939              26 :                     n->subtype = AT_GenericOptions;
    2940              26 :                     n->def = (Node *) $1;
    2941              26 :                     $$ = (Node *) n;
    2942                 :                 }
    2943                 :         ;
    2944                 : 
    2945                 : alter_column_default:
    2946             166 :             SET DEFAULT a_expr          { $$ = $3; }
    2947 GIC          90 :             | DROP DEFAULT              { $$ = NULL; }
    2948 ECB             :         ;
    2949                 : 
    2950                 : opt_collate_clause:
    2951                 :             COLLATE any_name
    2952                 :                 {
    2953 CBC           9 :                     CollateClause *n = makeNode(CollateClause);
    2954                 : 
    2955 GIC           9 :                     n->arg = NULL;
    2956               9 :                     n->collname = $2;
    2957               9 :                     n->location = @1;
    2958 CBC           9 :                     $$ = (Node *) n;
    2959                 :                 }
    2960            2058 :             | /* EMPTY */               { $$ = NULL; }
    2961 ECB             :         ;
    2962                 : 
    2963                 : alter_using:
    2964 GIC          75 :             USING a_expr                { $$ = $2; }
    2965             337 :             | /* EMPTY */               { $$ = NULL; }
    2966                 :         ;
    2967 ECB             : 
    2968                 : replica_identity:
    2969                 :             NOTHING
    2970                 :                 {
    2971 GIC          18 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    2972                 : 
    2973              18 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    2974              18 :                     n->name = NULL;
    2975 CBC          18 :                     $$ = (Node *) n;
    2976                 :                 }
    2977 ECB             :             | FULL
    2978                 :                 {
    2979 GIC          61 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    2980                 : 
    2981              61 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    2982              61 :                     n->name = NULL;
    2983 CBC          61 :                     $$ = (Node *) n;
    2984                 :                 }
    2985 ECB             :             | DEFAULT
    2986                 :                 {
    2987 GIC           3 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    2988                 : 
    2989               3 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    2990               3 :                     n->name = NULL;
    2991 CBC           3 :                     $$ = (Node *) n;
    2992                 :                 }
    2993 ECB             :             | USING INDEX name
    2994                 :                 {
    2995 GIC         116 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    2996                 : 
    2997             116 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    2998 CBC         116 :                     n->name = $3;
    2999 GIC         116 :                     $$ = (Node *) n;
    3000 ECB             :                 }
    3001                 : ;
    3002                 : 
    3003                 : reloptions:
    3004 GIC        1967 :             '(' reloption_list ')'                  { $$ = $2; }
    3005                 :         ;
    3006                 : 
    3007 CBC        1201 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3008           46019 :              |      /* EMPTY */                     { $$ = NIL; }
    3009                 :         ;
    3010                 : 
    3011                 : reloption_list:
    3012 GIC        1967 :             reloption_elem                          { $$ = list_make1($1); }
    3013             110 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3014 ECB             :         ;
    3015                 : 
    3016                 : /* This should match def_elem and also allow qualified names */
    3017                 : reloption_elem:
    3018                 :             ColLabel '=' def_arg
    3019                 :                 {
    3020 GIC         998 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3021 ECB             :                 }
    3022                 :             | ColLabel
    3023                 :                 {
    3024 GIC        1045 :                     $$ = makeDefElem($1, NULL, @1);
    3025 ECB             :                 }
    3026                 :             | ColLabel '.' ColLabel '=' def_arg
    3027                 :                 {
    3028 GIC          31 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3029              31 :                                              DEFELEM_UNSPEC, @1);
    3030                 :                 }
    3031                 :             | ColLabel '.' ColLabel
    3032 ECB             :                 {
    3033 GIC           3 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3034 ECB             :                 }
    3035                 :         ;
    3036                 : 
    3037                 : alter_identity_column_option_list:
    3038                 :             alter_identity_column_option
    3039 GIC          19 :                 { $$ = list_make1($1); }
    3040 ECB             :             | alter_identity_column_option_list alter_identity_column_option
    3041 GIC          12 :                 { $$ = lappend($1, $2); }
    3042 ECB             :         ;
    3043                 : 
    3044                 : alter_identity_column_option:
    3045                 :             RESTART
    3046                 :                 {
    3047 GIC           6 :                     $$ = makeDefElem("restart", NULL, @1);
    3048 ECB             :                 }
    3049                 :             | RESTART opt_with NumericOnly
    3050                 :                 {
    3051 LBC           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3052 ECB             :                 }
    3053                 :             | SET SeqOptElem
    3054                 :                 {
    3055 GIC          12 :                     if (strcmp($2->defname, "as") == 0 ||
    3056 CBC          12 :                         strcmp($2->defname, "restart") == 0 ||
    3057 GIC          12 :                         strcmp($2->defname, "owned_by") == 0)
    3058 LBC           0 :                         ereport(ERROR,
    3059 ECB             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3060                 :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3061                 :                                  parser_errposition(@2)));
    3062 GIC          12 :                     $$ = $2;
    3063                 :                 }
    3064                 :             | SET GENERATED generated_when
    3065 ECB             :                 {
    3066 GIC          13 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3067                 :                 }
    3068 ECB             :         ;
    3069                 : 
    3070                 : PartitionBoundSpec:
    3071                 :             /* a HASH partition */
    3072                 :             FOR VALUES WITH '(' hash_partbound ')'
    3073                 :                 {
    3074                 :                     ListCell   *lc;
    3075 GIC         296 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3076                 : 
    3077             296 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3078             296 :                     n->modulus = n->remainder = -1;
    3079                 : 
    3080             888 :                     foreach (lc, $5)
    3081 ECB             :                     {
    3082 GIC         592 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3083                 : 
    3084             592 :                         if (strcmp(opt->defname, "modulus") == 0)
    3085 ECB             :                         {
    3086 GIC         296 :                             if (n->modulus != -1)
    3087 UIC           0 :                                 ereport(ERROR,
    3088                 :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3089 ECB             :                                          errmsg("modulus for hash partition provided more than once"),
    3090                 :                                          parser_errposition(opt->location)));
    3091 GIC         296 :                             n->modulus = defGetInt32(opt);
    3092                 :                         }
    3093             296 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3094 ECB             :                         {
    3095 GIC         296 :                             if (n->remainder != -1)
    3096 UIC           0 :                                 ereport(ERROR,
    3097                 :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3098                 :                                          errmsg("remainder for hash partition provided more than once"),
    3099                 :                                          parser_errposition(opt->location)));
    3100 CBC         296 :                             n->remainder = defGetInt32(opt);
    3101                 :                         }
    3102 ECB             :                         else
    3103 UIC           0 :                             ereport(ERROR,
    3104                 :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3105                 :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3106                 :                                             opt->defname),
    3107                 :                                      parser_errposition(opt->location)));
    3108 ECB             :                     }
    3109                 : 
    3110 GIC         296 :                     if (n->modulus == -1)
    3111 UIC           0 :                         ereport(ERROR,
    3112 EUB             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3113                 :                                  errmsg("modulus for hash partition must be specified")));
    3114 GIC         296 :                     if (n->remainder == -1)
    3115 UIC           0 :                         ereport(ERROR,
    3116 ECB             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3117                 :                                  errmsg("remainder for hash partition must be specified")));
    3118                 : 
    3119 GBC         296 :                     n->location = @3;
    3120                 : 
    3121 GIC         296 :                     $$ = n;
    3122                 :                 }
    3123 ECB             : 
    3124                 :             /* a LIST partition */
    3125                 :             | FOR VALUES IN_P '(' expr_list ')'
    3126                 :                 {
    3127 CBC        2195 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3128                 : 
    3129 GIC        2195 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3130            2195 :                     n->is_default = false;
    3131            2195 :                     n->listdatums = $5;
    3132            2195 :                     n->location = @3;
    3133                 : 
    3134            2195 :                     $$ = n;
    3135                 :                 }
    3136 ECB             : 
    3137                 :             /* a RANGE partition */
    3138                 :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3139                 :                 {
    3140 GIC        1897 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3141 ECB             : 
    3142 GIC        1897 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3143 CBC        1897 :                     n->is_default = false;
    3144 GIC        1897 :                     n->lowerdatums = $5;
    3145 CBC        1897 :                     n->upperdatums = $9;
    3146 GIC        1897 :                     n->location = @3;
    3147 ECB             : 
    3148 GBC        1897 :                     $$ = n;
    3149                 :                 }
    3150                 : 
    3151                 :             /* a DEFAULT partition */
    3152 ECB             :             | DEFAULT
    3153                 :                 {
    3154 CBC         284 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3155                 : 
    3156             284 :                     n->is_default = true;
    3157 GBC         284 :                     n->location = @1;
    3158                 : 
    3159 GIC         284 :                     $$ = n;
    3160                 :                 }
    3161 ECB             :         ;
    3162                 : 
    3163                 : hash_partbound_elem:
    3164 EUB             :         NonReservedWord Iconst
    3165                 :             {
    3166 GIC         592 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3167                 :             }
    3168                 :         ;
    3169                 : 
    3170                 : hash_partbound:
    3171 ECB             :         hash_partbound_elem
    3172 EUB             :             {
    3173 GIC         296 :                 $$ = list_make1($1);
    3174                 :             }
    3175 ECB             :         | hash_partbound ',' hash_partbound_elem
    3176 EUB             :             {
    3177 GIC         296 :                 $$ = lappend($1, $3);
    3178                 :             }
    3179                 :         ;
    3180 ECB             : 
    3181                 : /*****************************************************************************
    3182                 :  *
    3183                 :  *  ALTER TYPE
    3184                 :  *
    3185                 :  * really variants of the ALTER TABLE subcommands with different spellings
    3186                 :  *****************************************************************************/
    3187                 : 
    3188                 : AlterCompositeTypeStmt:
    3189                 :             ALTER TYPE_P any_name alter_type_cmds
    3190                 :                 {
    3191 CBC         104 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3192 ECB             : 
    3193                 :                     /* can't use qualified_name, sigh */
    3194 GIC         104 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3195 CBC         104 :                     n->cmds = $4;
    3196 GIC         104 :                     n->objtype = OBJECT_TYPE;
    3197             104 :                     $$ = (Node *) n;
    3198                 :                 }
    3199                 :             ;
    3200                 : 
    3201 ECB             : alter_type_cmds:
    3202 GIC         104 :             alter_type_cmd                          { $$ = list_make1($1); }
    3203 CBC           6 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3204 ECB             :         ;
    3205                 : 
    3206                 : alter_type_cmd:
    3207                 :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3208                 :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3209                 :                 {
    3210 GIC          32 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3211                 : 
    3212              32 :                     n->subtype = AT_AddColumn;
    3213              32 :                     n->def = $3;
    3214              32 :                     n->behavior = $4;
    3215 CBC          32 :                     $$ = (Node *) n;
    3216                 :                 }
    3217 ECB             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3218                 :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3219                 :                 {
    3220 CBC           3 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3221                 : 
    3222 GIC           3 :                     n->subtype = AT_DropColumn;
    3223               3 :                     n->name = $5;
    3224               3 :                     n->behavior = $6;
    3225               3 :                     n->missing_ok = true;
    3226               3 :                     $$ = (Node *) n;
    3227 ECB             :                 }
    3228                 :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3229                 :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3230                 :                 {
    3231 GIC          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3232                 : 
    3233              38 :                     n->subtype = AT_DropColumn;
    3234 CBC          38 :                     n->name = $3;
    3235 GIC          38 :                     n->behavior = $4;
    3236              38 :                     n->missing_ok = false;
    3237              38 :                     $$ = (Node *) n;
    3238 ECB             :                 }
    3239                 :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3240                 :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3241                 :                 {
    3242 GIC          37 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3243              37 :                     ColumnDef *def = makeNode(ColumnDef);
    3244                 : 
    3245              37 :                     n->subtype = AT_AlterColumnType;
    3246              37 :                     n->name = $3;
    3247              37 :                     n->def = (Node *) def;
    3248              37 :                     n->behavior = $8;
    3249                 :                     /* We only use these fields of the ColumnDef node */
    3250              37 :                     def->typeName = $6;
    3251              37 :                     def->collClause = (CollateClause *) $7;
    3252 CBC          37 :                     def->raw_default = NULL;
    3253 GIC          37 :                     def->location = @3;
    3254              37 :                     $$ = (Node *) n;
    3255 ECB             :                 }
    3256                 :         ;
    3257                 : 
    3258                 : 
    3259                 : /*****************************************************************************
    3260                 :  *
    3261                 :  *      QUERY :
    3262                 :  *              close <portalname>
    3263                 :  *
    3264                 :  *****************************************************************************/
    3265                 : 
    3266                 : ClosePortalStmt:
    3267                 :             CLOSE cursor_name
    3268                 :                 {
    3269 GIC        1045 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3270                 : 
    3271 CBC        1045 :                     n->portalname = $2;
    3272 GIC        1045 :                     $$ = (Node *) n;
    3273 ECB             :                 }
    3274                 :             | CLOSE ALL
    3275                 :                 {
    3276 CBC           6 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3277                 : 
    3278 GIC           6 :                     n->portalname = NULL;
    3279               6 :                     $$ = (Node *) n;
    3280                 :                 }
    3281 ECB             :         ;
    3282                 : 
    3283                 : 
    3284                 : /*****************************************************************************
    3285                 :  *
    3286                 :  *      QUERY :
    3287                 :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3288                 :  *              COPY ( query ) TO file  [WITH] [(options)]
    3289                 :  *
    3290                 :  *              where 'query' can be one of:
    3291                 :  *              { SELECT | UPDATE | INSERT | DELETE }
    3292                 :  *
    3293                 :  *              and 'file' can be one of:
    3294                 :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3295                 :  *
    3296                 :  *              In the preferred syntax the options are comma-separated
    3297                 :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3298                 :  *              syntax had a hard-wired, space-separated set of options.
    3299                 :  *
    3300                 :  *              Really old syntax, from versions 7.2 and prior:
    3301                 :  *              COPY [ BINARY ] table FROM/TO file
    3302                 :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3303                 :  *                  [ WITH NULL AS 'null string' ]
    3304                 :  *              This option placement is not supported with COPY (query...).
    3305                 :  *
    3306                 :  *****************************************************************************/
    3307                 : 
    3308                 : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3309                 :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3310                 :             copy_options where_clause
    3311                 :                 {
    3312 CBC        4319 :                     CopyStmt *n = makeNode(CopyStmt);
    3313 ECB             : 
    3314 CBC        4319 :                     n->relation = $3;
    3315            4319 :                     n->query = NULL;
    3316 GIC        4319 :                     n->attlist = $4;
    3317            4319 :                     n->is_from = $5;
    3318            4319 :                     n->is_program = $6;
    3319            4319 :                     n->filename = $7;
    3320            4319 :                     n->whereClause = $11;
    3321                 : 
    3322            4319 :                     if (n->is_program && n->filename == NULL)
    3323 UIC           0 :                         ereport(ERROR,
    3324                 :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3325                 :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3326                 :                                  parser_errposition(@8)));
    3327                 : 
    3328 GIC        4319 :                     if (!n->is_from && n->whereClause != NULL)
    3329               3 :                         ereport(ERROR,
    3330 ECB             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3331                 :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3332                 :                                  parser_errposition(@11)));
    3333                 : 
    3334 GIC        4316 :                     n->options = NIL;
    3335                 :                     /* Concatenate user-supplied flags */
    3336            4316 :                     if ($2)
    3337 CBC           6 :                         n->options = lappend(n->options, $2);
    3338 GIC        4316 :                     if ($8)
    3339 LBC           0 :                         n->options = lappend(n->options, $8);
    3340 CBC        4316 :                     if ($10)
    3341 GIC         344 :                         n->options = list_concat(n->options, $10);
    3342            4316 :                     $$ = (Node *) n;
    3343                 :                 }
    3344                 :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3345                 :                 {
    3346             196 :                     CopyStmt *n = makeNode(CopyStmt);
    3347                 : 
    3348             196 :                     n->relation = NULL;
    3349             196 :                     n->query = $3;
    3350             196 :                     n->attlist = NIL;
    3351             196 :                     n->is_from = false;
    3352             196 :                     n->is_program = $6;
    3353             196 :                     n->filename = $7;
    3354             196 :                     n->options = $9;
    3355                 : 
    3356             196 :                     if (n->is_program && n->filename == NULL)
    3357 UIC           0 :                         ereport(ERROR,
    3358                 :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3359                 :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3360                 :                                  parser_errposition(@5)));
    3361                 : 
    3362 GIC         196 :                     $$ = (Node *) n;
    3363                 :                 }
    3364                 :         ;
    3365                 : 
    3366                 : copy_from:
    3367             963 :             FROM                                    { $$ = true; }
    3368            3356 :             | TO                                    { $$ = false; }
    3369                 :         ;
    3370                 : 
    3371                 : opt_program:
    3372 UIC           0 :             PROGRAM                                 { $$ = true; }
    3373 CBC        4515 :             | /* EMPTY */                           { $$ = false; }
    3374                 :         ;
    3375 ECB             : 
    3376                 : /*
    3377                 :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3378                 :  * used depends on the direction. (It really doesn't make sense to copy from
    3379                 :  * stdout. We silently correct the "typo".)        - AY 9/94
    3380                 :  */
    3381                 : copy_file_name:
    3382 GIC         451 :             Sconst                                  { $$ = $1; }
    3383 CBC         547 :             | STDIN                                 { $$ = NULL; }
    3384 GBC        3517 :             | STDOUT                                { $$ = NULL; }
    3385                 :         ;
    3386                 : 
    3387 GIC        4314 : copy_options: copy_opt_list                         { $$ = $1; }
    3388             201 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3389 ECB             :         ;
    3390                 : 
    3391                 : /* old COPY option syntax */
    3392                 : copy_opt_list:
    3393 GIC         248 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3394            4314 :             | /* EMPTY */                           { $$ = NIL; }
    3395 ECB             :         ;
    3396                 : 
    3397                 : copy_opt_item:
    3398                 :             BINARY
    3399                 :                 {
    3400 UBC           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3401 ECB             :                 }
    3402                 :             | FREEZE
    3403                 :                 {
    3404 GIC          25 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3405                 :                 }
    3406                 :             | DELIMITER opt_as Sconst
    3407 ECB             :                 {
    3408 GIC          85 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3409 ECB             :                 }
    3410                 :             | NULL_P opt_as Sconst
    3411                 :                 {
    3412 CBC          24 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3413 ECB             :                 }
    3414                 :             | CSV
    3415                 :                 {
    3416 GIC          72 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3417 ECB             :                 }
    3418 EUB             :             | HEADER_P
    3419                 :                 {
    3420 GIC           9 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3421                 :                 }
    3422                 :             | QUOTE opt_as Sconst
    3423 ECB             :                 {
    3424 GIC           9 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3425                 :                 }
    3426                 :             | ESCAPE opt_as Sconst
    3427                 :                 {
    3428 CBC           9 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3429 ECB             :                 }
    3430                 :             | FORCE QUOTE columnList
    3431                 :                 {
    3432 GIC           6 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3433 EUB             :                 }
    3434 ECB             :             | FORCE QUOTE '*'
    3435                 :                 {
    3436 GIC           3 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3437                 :                 }
    3438                 :             | FORCE NOT NULL_P columnList
    3439                 :                 {
    3440 UIC           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3441                 :                 }
    3442                 :             | FORCE NULL_P columnList
    3443 ECB             :                 {
    3444 LBC           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3445 ECB             :                 }
    3446                 :             | ENCODING Sconst
    3447                 :                 {
    3448 CBC           6 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3449 ECB             :                 }
    3450                 :         ;
    3451                 : 
    3452                 : /* The following exist for backward compatibility with very old versions */
    3453                 : 
    3454                 : opt_binary:
    3455                 :             BINARY
    3456                 :                 {
    3457 GIC           6 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3458                 :                 }
    3459            4313 :             | /*EMPTY*/                             { $$ = NULL; }
    3460                 :         ;
    3461 EUB             : 
    3462                 : copy_delimiter:
    3463                 :             opt_using DELIMITERS Sconst
    3464                 :                 {
    3465 LBC           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3466                 :                 }
    3467 GIC        4319 :             | /*EMPTY*/                             { $$ = NULL; }
    3468                 :         ;
    3469 ECB             : 
    3470                 : opt_using:
    3471                 :             USING
    3472                 :             | /*EMPTY*/
    3473                 :         ;
    3474                 : 
    3475                 : /* new COPY option syntax */
    3476                 : copy_generic_opt_list:
    3477                 :             copy_generic_opt_elem
    3478                 :                 {
    3479 GIC         201 :                     $$ = list_make1($1);
    3480                 :                 }
    3481 ECB             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3482                 :                 {
    3483 GIC         141 :                     $$ = lappend($1, $3);
    3484                 :                 }
    3485 ECB             :         ;
    3486                 : 
    3487                 : copy_generic_opt_elem:
    3488                 :             ColLabel copy_generic_opt_arg
    3489                 :                 {
    3490 GIC         342 :                     $$ = makeDefElem($1, $2, @1);
    3491                 :                 }
    3492                 :         ;
    3493 ECB             : 
    3494                 : copy_generic_opt_arg:
    3495 GIC         255 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3496 UIC           0 :             | NumericOnly                   { $$ = (Node *) $1; }
    3497 CBC           9 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3498 GIC          69 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3499               9 :             | /* EMPTY */                   { $$ = NULL; }
    3500                 :         ;
    3501 EUB             : 
    3502                 : copy_generic_opt_arg_list:
    3503                 :               copy_generic_opt_arg_list_item
    3504                 :                 {
    3505 GBC          69 :                     $$ = list_make1($1);
    3506                 :                 }
    3507                 :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3508                 :                 {
    3509 CBC           6 :                     $$ = lappend($1, $3);
    3510                 :                 }
    3511                 :         ;
    3512                 : 
    3513                 : /* beware of emitting non-string list elements here; see commands/define.c */
    3514                 : copy_generic_opt_arg_list_item:
    3515 GIC          75 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3516                 :         ;
    3517                 : 
    3518 ECB             : 
    3519                 : /*****************************************************************************
    3520                 :  *
    3521                 :  *      QUERY :
    3522                 :  *              CREATE TABLE relname
    3523                 :  *
    3524                 :  *****************************************************************************/
    3525                 : 
    3526 EUB             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3527                 :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3528 ECB             :             OnCommitOption OptTableSpace
    3529                 :                 {
    3530 GIC       13410 :                     CreateStmt *n = makeNode(CreateStmt);
    3531                 : 
    3532           13410 :                     $4->relpersistence = $2;
    3533           13410 :                     n->relation = $4;
    3534           13410 :                     n->tableElts = $6;
    3535           13410 :                     n->inhRelations = $8;
    3536           13410 :                     n->partspec = $9;
    3537           13410 :                     n->ofTypename = NULL;
    3538           13410 :                     n->constraints = NIL;
    3539           13410 :                     n->accessMethod = $10;
    3540 CBC       13410 :                     n->options = $11;
    3541 GIC       13410 :                     n->oncommit = $12;
    3542           13410 :                     n->tablespacename = $13;
    3543           13410 :                     n->if_not_exists = false;
    3544 CBC       13410 :                     $$ = (Node *) n;
    3545                 :                 }
    3546                 :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3547                 :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3548                 :             OptWith OnCommitOption OptTableSpace
    3549                 :                 {
    3550 GIC          14 :                     CreateStmt *n = makeNode(CreateStmt);
    3551 ECB             : 
    3552 GIC          14 :                     $7->relpersistence = $2;
    3553              14 :                     n->relation = $7;
    3554              14 :                     n->tableElts = $9;
    3555              14 :                     n->inhRelations = $11;
    3556 CBC          14 :                     n->partspec = $12;
    3557 GBC          14 :                     n->ofTypename = NULL;
    3558 CBC          14 :                     n->constraints = NIL;
    3559              14 :                     n->accessMethod = $13;
    3560              14 :                     n->options = $14;
    3561 GIC          14 :                     n->oncommit = $15;
    3562              14 :                     n->tablespacename = $16;
    3563              14 :                     n->if_not_exists = true;
    3564              14 :                     $$ = (Node *) n;
    3565                 :                 }
    3566 ECB             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3567                 :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3568                 :             OptWith OnCommitOption OptTableSpace
    3569                 :                 {
    3570 CBC          55 :                     CreateStmt *n = makeNode(CreateStmt);
    3571                 : 
    3572 GIC          55 :                     $4->relpersistence = $2;
    3573              55 :                     n->relation = $4;
    3574              55 :                     n->tableElts = $7;
    3575              55 :                     n->inhRelations = NIL;
    3576 CBC          55 :                     n->partspec = $8;
    3577 GIC          55 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3578              55 :                     n->ofTypename->location = @6;
    3579              55 :                     n->constraints = NIL;
    3580              55 :                     n->accessMethod = $9;
    3581              55 :                     n->options = $10;
    3582              55 :                     n->oncommit = $11;
    3583              55 :                     n->tablespacename = $12;
    3584              55 :                     n->if_not_exists = false;
    3585              55 :                     $$ = (Node *) n;
    3586                 :                 }
    3587                 :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3588                 :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3589                 :             OptWith OnCommitOption OptTableSpace
    3590                 :                 {
    3591 CBC           3 :                     CreateStmt *n = makeNode(CreateStmt);
    3592                 : 
    3593               3 :                     $7->relpersistence = $2;
    3594               3 :                     n->relation = $7;
    3595               3 :                     n->tableElts = $10;
    3596               3 :                     n->inhRelations = NIL;
    3597               3 :                     n->partspec = $11;
    3598               3 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3599               3 :                     n->ofTypename->location = @9;
    3600               3 :                     n->constraints = NIL;
    3601               3 :                     n->accessMethod = $12;
    3602               3 :                     n->options = $13;
    3603               3 :                     n->oncommit = $14;
    3604               3 :                     n->tablespacename = $15;
    3605               3 :                     n->if_not_exists = true;
    3606 GIC           3 :                     $$ = (Node *) n;
    3607                 :                 }
    3608                 :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3609                 :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3610                 :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3611 ECB             :                 {
    3612 GIC        3580 :                     CreateStmt *n = makeNode(CreateStmt);
    3613 ECB             : 
    3614 CBC        3580 :                     $4->relpersistence = $2;
    3615            3580 :                     n->relation = $4;
    3616            3580 :                     n->tableElts = $8;
    3617            3580 :                     n->inhRelations = list_make1($7);
    3618            3580 :                     n->partbound = $9;
    3619            3580 :                     n->partspec = $10;
    3620            3580 :                     n->ofTypename = NULL;
    3621            3580 :                     n->constraints = NIL;
    3622            3580 :                     n->accessMethod = $11;
    3623            3580 :                     n->options = $12;
    3624            3580 :                     n->oncommit = $13;
    3625            3580 :                     n->tablespacename = $14;
    3626 GIC        3580 :                     n->if_not_exists = false;
    3627            3580 :                     $$ = (Node *) n;
    3628                 :                 }
    3629                 :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3630                 :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3631 ECB             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3632                 :                 {
    3633 LBC           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3634 ECB             : 
    3635 LBC           0 :                     $7->relpersistence = $2;
    3636               0 :                     n->relation = $7;
    3637               0 :                     n->tableElts = $11;
    3638               0 :                     n->inhRelations = list_make1($10);
    3639               0 :                     n->partbound = $12;
    3640               0 :                     n->partspec = $13;
    3641               0 :                     n->ofTypename = NULL;
    3642               0 :                     n->constraints = NIL;
    3643               0 :                     n->accessMethod = $14;
    3644               0 :                     n->options = $15;
    3645               0 :                     n->oncommit = $16;
    3646               0 :                     n->tablespacename = $17;
    3647 UIC           0 :                     n->if_not_exists = true;
    3648               0 :                     $$ = (Node *) n;
    3649                 :                 }
    3650                 :         ;
    3651                 : 
    3652 ECB             : /*
    3653                 :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3654                 :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3655                 :  *
    3656                 :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3657                 :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3658                 :  * temp table behavior, so warn about that.  Since we have no modules the
    3659                 :  * LOCAL keyword is really meaningless; furthermore, some other products
    3660                 :  * implement LOCAL as meaning the same as our default temp table behavior,
    3661                 :  * so we'll probably continue to treat LOCAL as a noise word.
    3662                 :  */
    3663 CBC         147 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3664            1252 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3665 LBC           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3666               0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3667 ECB             :             | GLOBAL TEMPORARY
    3668                 :                 {
    3669 UIC           0 :                     ereport(WARNING,
    3670                 :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3671                 :                              parser_errposition(@1)));
    3672               0 :                     $$ = RELPERSISTENCE_TEMP;
    3673 ECB             :                 }
    3674                 :             | GLOBAL TEMP
    3675                 :                 {
    3676 LBC           0 :                     ereport(WARNING,
    3677 ECB             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3678                 :                              parser_errposition(@1)));
    3679 LBC           0 :                     $$ = RELPERSISTENCE_TEMP;
    3680 ECB             :                 }
    3681 CBC          69 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3682           60671 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3683 ECB             :         ;
    3684                 : 
    3685                 : OptTableElementList:
    3686 CBC       13006 :             TableElementList                    { $$ = $1; }
    3687             618 :             | /*EMPTY*/                         { $$ = NIL; }
    3688 ECB             :         ;
    3689                 : 
    3690                 : OptTypedTableElementList:
    3691 GIC         144 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3692            3537 :             | /*EMPTY*/                         { $$ = NIL; }
    3693                 :         ;
    3694 EUB             : 
    3695                 : TableElementList:
    3696                 :             TableElement
    3697                 :                 {
    3698 GBC       13030 :                     $$ = list_make1($1);
    3699 EUB             :                 }
    3700                 :             | TableElementList ',' TableElement
    3701                 :                 {
    3702 GBC       22068 :                     $$ = lappend($1, $3);
    3703 EUB             :                 }
    3704                 :         ;
    3705                 : 
    3706                 : TypedTableElementList:
    3707                 :             TypedTableElement
    3708                 :                 {
    3709 GBC         144 :                     $$ = list_make1($1);
    3710                 :                 }
    3711                 :             | TypedTableElementList ',' TypedTableElement
    3712                 :                 {
    3713 GIC          34 :                     $$ = lappend($1, $3);
    3714                 :                 }
    3715                 :         ;
    3716                 : 
    3717                 : TableElement:
    3718           33886 :             columnDef                           { $$ = $1; }
    3719             348 :             | TableLikeClause                   { $$ = $1; }
    3720             864 :             | TableConstraint                   { $$ = $1; }
    3721                 :         ;
    3722                 : 
    3723                 : TypedTableElement:
    3724 CBC         143 :             columnOptions                       { $$ = $1; }
    3725              35 :             | TableConstraint                   { $$ = $1; }
    3726 EUB             :         ;
    3727                 : 
    3728                 : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3729                 :                 {
    3730 GBC       34789 :                     ColumnDef *n = makeNode(ColumnDef);
    3731                 : 
    3732 GIC       34789 :                     n->colname = $1;
    3733 GBC       34789 :                     n->typeName = $2;
    3734 GNC       34789 :                     n->storage_name = $3;
    3735           34789 :                     n->compression = $4;
    3736 GIC       34789 :                     n->inhcount = 0;
    3737           34789 :                     n->is_local = true;
    3738 GBC       34789 :                     n->is_not_null = false;
    3739 GIC       34789 :                     n->is_from_type = false;
    3740           34789 :                     n->storage = 0;
    3741 GBC       34789 :                     n->raw_default = NULL;
    3742 GIC       34789 :                     n->cooked_default = NULL;
    3743 CBC       34789 :                     n->collOid = InvalidOid;
    3744 GNC       34789 :                     n->fdwoptions = $5;
    3745           34789 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3746                 :                                      yyscanner);
    3747 GIC       34789 :                     n->location = @1;
    3748 CBC       34789 :                     $$ = (Node *) n;
    3749 ECB             :                 }
    3750                 :         ;
    3751                 : 
    3752                 : columnOptions:  ColId ColQualList
    3753                 :                 {
    3754 CBC          60 :                     ColumnDef *n = makeNode(ColumnDef);
    3755                 : 
    3756 GIC          60 :                     n->colname = $1;
    3757              60 :                     n->typeName = NULL;
    3758              60 :                     n->inhcount = 0;
    3759              60 :                     n->is_local = true;
    3760 CBC          60 :                     n->is_not_null = false;
    3761 GIC          60 :                     n->is_from_type = false;
    3762              60 :                     n->storage = 0;
    3763              60 :                     n->raw_default = NULL;
    3764 CBC          60 :                     n->cooked_default = NULL;
    3765 GIC          60 :                     n->collOid = InvalidOid;
    3766              60 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3767                 :                                      yyscanner);
    3768              60 :                     n->location = @1;
    3769              60 :                     $$ = (Node *) n;
    3770                 :                 }
    3771 ECB             :                 | ColId WITH OPTIONS ColQualList
    3772                 :                 {
    3773 GIC          83 :                     ColumnDef *n = makeNode(ColumnDef);
    3774                 : 
    3775 CBC          83 :                     n->colname = $1;
    3776 GIC          83 :                     n->typeName = NULL;
    3777              83 :                     n->inhcount = 0;
    3778              83 :                     n->is_local = true;
    3779              83 :                     n->is_not_null = false;
    3780 CBC          83 :                     n->is_from_type = false;
    3781              83 :                     n->storage = 0;
    3782              83 :                     n->raw_default = NULL;
    3783 GIC          83 :                     n->cooked_default = NULL;
    3784              83 :                     n->collOid = InvalidOid;
    3785              83 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3786 ECB             :                                      yyscanner);
    3787 CBC          83 :                     n->location = @1;
    3788 GIC          83 :                     $$ = (Node *) n;
    3789                 :                 }
    3790                 :         ;
    3791                 : 
    3792 ECB             : column_compression:
    3793 GIC          68 :             COMPRESSION ColId                       { $$ = $2; }
    3794 CBC           3 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3795 ECB             :         ;
    3796                 : 
    3797                 : opt_column_compression:
    3798 CBC          38 :             column_compression                      { $$ = $1; }
    3799           34781 :             | /*EMPTY*/                             { $$ = NULL; }
    3800 ECB             :         ;
    3801                 : 
    3802                 : column_storage:
    3803 GNC         107 :             STORAGE ColId                           { $$ = $2; }
    3804               3 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3805                 :         ;
    3806                 : 
    3807                 : opt_column_storage:
    3808               6 :             column_storage                          { $$ = $1; }
    3809           34813 :             | /*EMPTY*/                             { $$ = NULL; }
    3810                 :         ;
    3811                 : 
    3812 ECB             : ColQualList:
    3813 CBC        9328 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3814           36824 :             | /*EMPTY*/                             { $$ = NIL; }
    3815 ECB             :         ;
    3816                 : 
    3817                 : ColConstraint:
    3818                 :             CONSTRAINT name ColConstraintElem
    3819                 :                 {
    3820 CBC         675 :                     Constraint *n = castNode(Constraint, $3);
    3821                 : 
    3822 GIC         675 :                     n->conname = $2;
    3823             675 :                     n->location = @1;
    3824             675 :                     $$ = (Node *) n;
    3825                 :                 }
    3826 CBC        7704 :             | ColConstraintElem                     { $$ = $1; }
    3827 GIC          76 :             | ConstraintAttr                        { $$ = $1; }
    3828 ECB             :             | COLLATE any_name
    3829                 :                 {
    3830                 :                     /*
    3831                 :                      * Note: the CollateClause is momentarily included in
    3832                 :                      * the list built by ColQualList, but we split it out
    3833                 :                      * again in SplitColQualList.
    3834                 :                      */
    3835 CBC         873 :                     CollateClause *n = makeNode(CollateClause);
    3836 ECB             : 
    3837 CBC         873 :                     n->arg = NULL;
    3838             873 :                     n->collname = $2;
    3839 GIC         873 :                     n->location = @1;
    3840 CBC         873 :                     $$ = (Node *) n;
    3841 ECB             :                 }
    3842                 :         ;
    3843                 : 
    3844                 : /* DEFAULT NULL is already the default for Postgres.
    3845                 :  * But define it here and carry it forward into the system
    3846                 :  * to make it explicit.
    3847                 :  * - thomas 1998-09-13
    3848                 :  *
    3849                 :  * WITH NULL and NULL are not SQL-standard syntax elements,
    3850                 :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    3851                 :  * that a column may have that value. WITH NULL leads to
    3852                 :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    3853                 :  * - thomas 1999-01-08
    3854                 :  *
    3855                 :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    3856                 :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    3857                 :  * or be part of a_expr NOT LIKE or similar constructs).
    3858                 :  */
    3859                 : ColConstraintElem:
    3860                 :             NOT NULL_P
    3861                 :                 {
    3862 GIC        2770 :                     Constraint *n = makeNode(Constraint);
    3863                 : 
    3864            2770 :                     n->contype = CONSTR_NOTNULL;
    3865 CBC        2770 :                     n->location = @1;
    3866            2770 :                     $$ = (Node *) n;
    3867                 :                 }
    3868                 :             | NULL_P
    3869                 :                 {
    3870              11 :                     Constraint *n = makeNode(Constraint);
    3871 ECB             : 
    3872 GIC          11 :                     n->contype = CONSTR_NULL;
    3873              11 :                     n->location = @1;
    3874              11 :                     $$ = (Node *) n;
    3875 ECB             :                 }
    3876                 :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    3877                 :                 {
    3878 GIC         183 :                     Constraint *n = makeNode(Constraint);
    3879                 : 
    3880 CBC         183 :                     n->contype = CONSTR_UNIQUE;
    3881             183 :                     n->location = @1;
    3882 GIC         183 :                     n->nulls_not_distinct = !$2;
    3883             183 :                     n->keys = NULL;
    3884             183 :                     n->options = $3;
    3885 CBC         183 :                     n->indexname = NULL;
    3886             183 :                     n->indexspace = $4;
    3887 GIC         183 :                     $$ = (Node *) n;
    3888                 :                 }
    3889                 :             | PRIMARY KEY opt_definition OptConsTableSpace
    3890                 :                 {
    3891            2578 :                     Constraint *n = makeNode(Constraint);
    3892 ECB             : 
    3893 GIC        2578 :                     n->contype = CONSTR_PRIMARY;
    3894 CBC        2578 :                     n->location = @1;
    3895            2578 :                     n->keys = NULL;
    3896            2578 :                     n->options = $3;
    3897 GIC        2578 :                     n->indexname = NULL;
    3898 CBC        2578 :                     n->indexspace = $4;
    3899            2578 :                     $$ = (Node *) n;
    3900                 :                 }
    3901                 :             | CHECK '(' a_expr ')' opt_no_inherit
    3902                 :                 {
    3903 GIC         898 :                     Constraint *n = makeNode(Constraint);
    3904                 : 
    3905             898 :                     n->contype = CONSTR_CHECK;
    3906             898 :                     n->location = @1;
    3907 CBC         898 :                     n->is_no_inherit = $5;
    3908 GIC         898 :                     n->raw_expr = $3;
    3909 CBC         898 :                     n->cooked_expr = NULL;
    3910             898 :                     n->skip_validation = false;
    3911             898 :                     n->initially_valid = true;
    3912             898 :                     $$ = (Node *) n;
    3913                 :                 }
    3914                 :             | DEFAULT b_expr
    3915                 :                 {
    3916 GIC        1052 :                     Constraint *n = makeNode(Constraint);
    3917                 : 
    3918            1052 :                     n->contype = CONSTR_DEFAULT;
    3919            1052 :                     n->location = @1;
    3920            1052 :                     n->raw_expr = $2;
    3921            1052 :                     n->cooked_expr = NULL;
    3922            1052 :                     $$ = (Node *) n;
    3923                 :                 }
    3924                 :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    3925                 :                 {
    3926             114 :                     Constraint *n = makeNode(Constraint);
    3927                 : 
    3928             114 :                     n->contype = CONSTR_IDENTITY;
    3929             114 :                     n->generated_when = $2;
    3930             114 :                     n->options = $5;
    3931             114 :                     n->location = @1;
    3932             114 :                     $$ = (Node *) n;
    3933                 :                 }
    3934 ECB             :             | GENERATED generated_when AS '(' a_expr ')' STORED
    3935                 :                 {
    3936 CBC         415 :                     Constraint *n = makeNode(Constraint);
    3937 ECB             : 
    3938 CBC         415 :                     n->contype = CONSTR_GENERATED;
    3939 GIC         415 :                     n->generated_when = $2;
    3940             415 :                     n->raw_expr = $5;
    3941             415 :                     n->cooked_expr = NULL;
    3942 CBC         415 :                     n->location = @1;
    3943                 : 
    3944 ECB             :                     /*
    3945                 :                      * Can't do this in the grammar because of shift/reduce
    3946                 :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    3947                 :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    3948                 :                      * can also give a more useful error message and location.
    3949                 :                      */
    3950 CBC         415 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    3951 GIC           3 :                         ereport(ERROR,
    3952 ECB             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3953                 :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    3954                 :                                  parser_errposition(@2)));
    3955                 : 
    3956 CBC         412 :                     $$ = (Node *) n;
    3957 ECB             :                 }
    3958                 :             | REFERENCES qualified_name opt_column_list key_match key_actions
    3959                 :                 {
    3960 GIC         361 :                     Constraint *n = makeNode(Constraint);
    3961                 : 
    3962             361 :                     n->contype = CONSTR_FOREIGN;
    3963 CBC         361 :                     n->location = @1;
    3964 GIC         361 :                     n->pktable = $2;
    3965 CBC         361 :                     n->fk_attrs = NIL;
    3966             361 :                     n->pk_attrs = $3;
    3967             361 :                     n->fk_matchtype = $4;
    3968             361 :                     n->fk_upd_action = ($5)->updateAction->action;
    3969             361 :                     n->fk_del_action = ($5)->deleteAction->action;
    3970             361 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    3971             361 :                     n->skip_validation = false;
    3972 GIC         361 :                     n->initially_valid = true;
    3973             361 :                     $$ = (Node *) n;
    3974                 :                 }
    3975 ECB             :         ;
    3976                 : 
    3977                 : opt_unique_null_treatment:
    3978 CBC           6 :             NULLS_P DISTINCT        { $$ = true; }
    3979              15 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    3980            3214 :             | /*EMPTY*/             { $$ = true; }
    3981 ECB             :         ;
    3982                 : 
    3983                 : generated_when:
    3984 CBC         536 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    3985 GIC          57 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    3986                 :         ;
    3987                 : 
    3988 ECB             : /*
    3989                 :  * ConstraintAttr represents constraint attributes, which we parse as if
    3990                 :  * they were independent constraint clauses, in order to avoid shift/reduce
    3991                 :  * conflicts (since NOT might start either an independent NOT NULL clause
    3992                 :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    3993                 :  * attribute information to the preceding "real" constraint node, and for
    3994                 :  * complaining if attribute clauses appear in the wrong place or wrong
    3995                 :  * combinations.
    3996                 :  *
    3997                 :  * See also ConstraintAttributeSpec, which can be used in places where
    3998                 :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    3999                 :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4000                 :  * might need to allow them here too, but for the moment it doesn't seem
    4001                 :  * useful in the statements that use ConstraintAttr.)
    4002                 :  */
    4003                 : ConstraintAttr:
    4004                 :             DEFERRABLE
    4005                 :                 {
    4006 GIC          42 :                     Constraint *n = makeNode(Constraint);
    4007                 : 
    4008 CBC          42 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4009 GIC          42 :                     n->location = @1;
    4010 CBC          42 :                     $$ = (Node *) n;
    4011 ECB             :                 }
    4012                 :             | NOT DEFERRABLE
    4013                 :                 {
    4014 LBC           0 :                     Constraint *n = makeNode(Constraint);
    4015                 : 
    4016 UIC           0 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4017               0 :                     n->location = @1;
    4018               0 :                     $$ = (Node *) n;
    4019                 :                 }
    4020                 :             | INITIALLY DEFERRED
    4021                 :                 {
    4022 CBC          31 :                     Constraint *n = makeNode(Constraint);
    4023 ECB             : 
    4024 GIC          31 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4025              31 :                     n->location = @1;
    4026              31 :                     $$ = (Node *) n;
    4027                 :                 }
    4028 ECB             :             | INITIALLY IMMEDIATE
    4029                 :                 {
    4030 GIC           3 :                     Constraint *n = makeNode(Constraint);
    4031                 : 
    4032 CBC           3 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4033 GIC           3 :                     n->location = @1;
    4034 CBC           3 :                     $$ = (Node *) n;
    4035 ECB             :                 }
    4036                 :         ;
    4037                 : 
    4038                 : 
    4039                 : TableLikeClause:
    4040                 :             LIKE qualified_name TableLikeOptionList
    4041                 :                 {
    4042 CBC         348 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4043 ECB             : 
    4044 CBC         348 :                     n->relation = $2;
    4045             348 :                     n->options = $3;
    4046 GIC         348 :                     n->relationOid = InvalidOid;
    4047             348 :                     $$ = (Node *) n;
    4048                 :                 }
    4049                 :         ;
    4050 ECB             : 
    4051                 : TableLikeOptionList:
    4052 CBC         120 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4053 GIC           1 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4054             348 :                 | /* EMPTY */                       { $$ = 0; }
    4055                 :         ;
    4056 ECB             : 
    4057                 : TableLikeOption:
    4058 GIC          12 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4059               3 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4060              27 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4061              10 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4062               3 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4063              12 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4064              19 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4065 UIC           0 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4066 GIC          13 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4067              22 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4068                 :         ;
    4069                 : 
    4070                 : 
    4071                 : /* ConstraintElem specifies constraint syntax which is not embedded into
    4072                 :  *  a column definition. ColConstraintElem specifies the embedded form.
    4073                 :  * - thomas 1997-12-03
    4074                 :  */
    4075                 : TableConstraint:
    4076                 :             CONSTRAINT name ConstraintElem
    4077                 :                 {
    4078 CBC        1280 :                     Constraint *n = castNode(Constraint, $3);
    4079                 : 
    4080            1280 :                     n->conname = $2;
    4081            1280 :                     n->location = @1;
    4082            1280 :                     $$ = (Node *) n;
    4083                 :                 }
    4084 GIC       34426 :             | ConstraintElem                        { $$ = $1; }
    4085                 :         ;
    4086 EUB             : 
    4087                 : ConstraintElem:
    4088                 :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4089                 :                 {
    4090 GBC         579 :                     Constraint *n = makeNode(Constraint);
    4091                 : 
    4092 GIC         579 :                     n->contype = CONSTR_CHECK;
    4093             579 :                     n->location = @1;
    4094 CBC         579 :                     n->raw_expr = $3;
    4095 GIC         579 :                     n->cooked_expr = NULL;
    4096 CBC         579 :                     processCASbits($5, @5, "CHECK",
    4097 ECB             :                                    NULL, NULL, &n->skip_validation,
    4098                 :                                    &n->is_no_inherit, yyscanner);
    4099 GIC         579 :                     n->initially_valid = !n->skip_validation;
    4100             579 :                     $$ = (Node *) n;
    4101                 :                 }
    4102                 :             | NOT NULL_P ColId ConstraintAttributeSpec
    4103                 :                 {
    4104 GNC          40 :                     Constraint *n = makeNode(Constraint);
    4105                 : 
    4106              40 :                     n->contype = CONSTR_NOTNULL;
    4107              40 :                     n->location = @1;
    4108              40 :                     n->colname = $3;
    4109              40 :                     processCASbits($4, @4, "NOT NULL",
    4110                 :                                    NULL, NULL, NULL,
    4111                 :                                    &n->is_no_inherit, yyscanner);
    4112              40 :                     n->initially_valid = !n->skip_validation;
    4113              40 :                     $$ = (Node *) n;
    4114                 :                 }
    4115 ECB             :             | UNIQUE opt_unique_null_treatment '(' columnList ')' opt_c_include opt_definition OptConsTableSpace
    4116                 :                 ConstraintAttributeSpec
    4117                 :                 {
    4118 CBC         223 :                     Constraint *n = makeNode(Constraint);
    4119 ECB             : 
    4120 GIC         223 :                     n->contype = CONSTR_UNIQUE;
    4121             223 :                     n->location = @1;
    4122             223 :                     n->nulls_not_distinct = !$2;
    4123             223 :                     n->keys = $4;
    4124             223 :                     n->including = $6;
    4125             223 :                     n->options = $7;
    4126             223 :                     n->indexname = NULL;
    4127 CBC         223 :                     n->indexspace = $8;
    4128 GIC         223 :                     processCASbits($9, @9, "UNIQUE",
    4129 ECB             :                                    &n->deferrable, &n->initdeferred, NULL,
    4130                 :                                    NULL, yyscanner);
    4131 CBC         223 :                     $$ = (Node *) n;
    4132 ECB             :                 }
    4133                 :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4134                 :                 {
    4135 GIC       14555 :                     Constraint *n = makeNode(Constraint);
    4136                 : 
    4137 CBC       14555 :                     n->contype = CONSTR_UNIQUE;
    4138           14555 :                     n->location = @1;
    4139           14555 :                     n->keys = NIL;
    4140 GIC       14555 :                     n->including = NIL;
    4141           14555 :                     n->options = NIL;
    4142           14555 :                     n->indexname = $2;
    4143 CBC       14555 :                     n->indexspace = NULL;
    4144           14555 :                     processCASbits($3, @3, "UNIQUE",
    4145 ECB             :                                    &n->deferrable, &n->initdeferred, NULL,
    4146                 :                                    NULL, yyscanner);
    4147 CBC       14555 :                     $$ = (Node *) n;
    4148 ECB             :                 }
    4149                 :             | PRIMARY KEY '(' columnList ')' opt_c_include opt_definition OptConsTableSpace
    4150 EUB             :                 ConstraintAttributeSpec
    4151 ECB             :                 {
    4152 CBC         742 :                     Constraint *n = makeNode(Constraint);
    4153                 : 
    4154 GIC         742 :                     n->contype = CONSTR_PRIMARY;
    4155             742 :                     n->location = @1;
    4156             742 :                     n->keys = $4;
    4157             742 :                     n->including = $6;
    4158             742 :                     n->options = $7;
    4159             742 :                     n->indexname = NULL;
    4160             742 :                     n->indexspace = $8;
    4161             742 :                     processCASbits($9, @9, "PRIMARY KEY",
    4162                 :                                    &n->deferrable, &n->initdeferred, NULL,
    4163 ECB             :                                    NULL, yyscanner);
    4164 GIC         742 :                     $$ = (Node *) n;
    4165 ECB             :                 }
    4166                 :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4167                 :                 {
    4168 GIC       18813 :                     Constraint *n = makeNode(Constraint);
    4169 ECB             : 
    4170 GIC       18813 :                     n->contype = CONSTR_PRIMARY;
    4171           18813 :                     n->location = @1;
    4172           18813 :                     n->keys = NIL;
    4173           18813 :                     n->including = NIL;
    4174           18813 :                     n->options = NIL;
    4175 CBC       18813 :                     n->indexname = $3;
    4176 GIC       18813 :                     n->indexspace = NULL;
    4177 CBC       18813 :                     processCASbits($4, @4, "PRIMARY KEY",
    4178 ECB             :                                    &n->deferrable, &n->initdeferred, NULL,
    4179                 :                                    NULL, yyscanner);
    4180 CBC       18813 :                     $$ = (Node *) n;
    4181 ECB             :                 }
    4182                 :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4183                 :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4184                 :                 ConstraintAttributeSpec
    4185                 :                 {
    4186 GIC          76 :                     Constraint *n = makeNode(Constraint);
    4187                 : 
    4188              76 :                     n->contype = CONSTR_EXCLUSION;
    4189 CBC          76 :                     n->location = @1;
    4190 GIC          76 :                     n->access_method = $2;
    4191 CBC          76 :                     n->exclusions = $4;
    4192              76 :                     n->including = $6;
    4193              76 :                     n->options = $7;
    4194              76 :                     n->indexname = NULL;
    4195 GIC          76 :                     n->indexspace = $8;
    4196              76 :                     n->where_clause = $9;
    4197 CBC          76 :                     processCASbits($10, @10, "EXCLUDE",
    4198 ECB             :                                    &n->deferrable, &n->initdeferred, NULL,
    4199                 :                                    NULL, yyscanner);
    4200 GIC          76 :                     $$ = (Node *) n;
    4201                 :                 }
    4202                 :             | FOREIGN KEY '(' columnList ')' REFERENCES qualified_name
    4203 ECB             :                 opt_column_list key_match key_actions ConstraintAttributeSpec
    4204                 :                 {
    4205 CBC         678 :                     Constraint *n = makeNode(Constraint);
    4206 ECB             : 
    4207 CBC         678 :                     n->contype = CONSTR_FOREIGN;
    4208             678 :                     n->location = @1;
    4209             678 :                     n->pktable = $7;
    4210             678 :                     n->fk_attrs = $4;
    4211             678 :                     n->pk_attrs = $8;
    4212             678 :                     n->fk_matchtype = $9;
    4213             678 :                     n->fk_upd_action = ($10)->updateAction->action;
    4214 GIC         678 :                     n->fk_del_action = ($10)->deleteAction->action;
    4215             678 :                     n->fk_del_set_cols = ($10)->deleteAction->cols;
    4216 CBC         678 :                     processCASbits($11, @11, "FOREIGN KEY",
    4217                 :                                    &n->deferrable, &n->initdeferred,
    4218                 :                                    &n->skip_validation, NULL,
    4219                 :                                    yyscanner);
    4220             678 :                     n->initially_valid = !n->skip_validation;
    4221 GIC         678 :                     $$ = (Node *) n;
    4222 ECB             :                 }
    4223                 :         ;
    4224                 : 
    4225 CBC           6 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4226             892 :             | /* EMPTY */                           {  $$ = false; }
    4227 ECB             :         ;
    4228                 : 
    4229                 : opt_column_list:
    4230 GIC        4861 :             '(' columnList ')'                      { $$ = $2; }
    4231           92629 :             | /*EMPTY*/                             { $$ = NIL; }
    4232 ECB             :         ;
    4233                 : 
    4234                 : columnList:
    4235 GIC        6786 :             columnElem                              { $$ = list_make1($1); }
    4236           16448 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4237 ECB             :         ;
    4238                 : 
    4239                 : columnElem: ColId
    4240                 :                 {
    4241 CBC       23234 :                     $$ = (Node *) makeString($1);
    4242 ECB             :                 }
    4243                 :         ;
    4244                 : 
    4245 CBC          84 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4246             957 :              |      /* EMPTY */                     { $$ = NIL; }
    4247                 :         ;
    4248                 : 
    4249 ECB             : key_match:  MATCH FULL
    4250                 :             {
    4251 GIC          49 :                 $$ = FKCONSTR_MATCH_FULL;
    4252                 :             }
    4253 ECB             :         | MATCH PARTIAL
    4254                 :             {
    4255 LBC           0 :                 ereport(ERROR,
    4256 ECB             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4257                 :                          errmsg("MATCH PARTIAL not yet implemented"),
    4258                 :                          parser_errposition(@1)));
    4259                 :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4260                 :             }
    4261                 :         | MATCH SIMPLE
    4262                 :             {
    4263 GIC           3 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4264                 :             }
    4265 ECB             :         | /*EMPTY*/
    4266                 :             {
    4267 GIC         990 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4268                 :             }
    4269                 :         ;
    4270                 : 
    4271 ECB             : ExclusionConstraintList:
    4272 GIC          76 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4273 ECB             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4274 CBC          15 :                                                     { $$ = lappend($1, $3); }
    4275 ECB             :         ;
    4276                 : 
    4277                 : ExclusionConstraintElem: index_elem WITH any_operator
    4278                 :             {
    4279 CBC          91 :                 $$ = list_make2($1, $3);
    4280 ECB             :             }
    4281                 :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4282                 :             | index_elem WITH OPERATOR '(' any_operator ')'
    4283                 :             {
    4284 UIC           0 :                 $$ = list_make2($1, $5);
    4285 ECB             :             }
    4286                 :         ;
    4287                 : 
    4288                 : OptWhereClause:
    4289 GIC         213 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4290 CBC         509 :             | /*EMPTY*/                             { $$ = NULL; }
    4291                 :         ;
    4292 ECB             : 
    4293                 : key_actions:
    4294                 :             key_update
    4295                 :                 {
    4296 CBC          13 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4297 ECB             : 
    4298 CBC          13 :                     n->updateAction = $1;
    4299              13 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4300              13 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4301              13 :                     n->deleteAction->cols = NIL;
    4302 GIC          13 :                     $$ = n;
    4303                 :                 }
    4304                 :             | key_delete
    4305 ECB             :                 {
    4306 CBC          58 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4307                 : 
    4308 GIC          58 :                     n->updateAction = palloc(sizeof(KeyAction));
    4309              58 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4310 CBC          58 :                     n->updateAction->cols = NIL;
    4311              58 :                     n->deleteAction = $1;
    4312 GIC          58 :                     $$ = n;
    4313                 :                 }
    4314                 :             | key_update key_delete
    4315 ECB             :                 {
    4316 CBC          75 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4317                 : 
    4318 GIC          75 :                     n->updateAction = $1;
    4319              75 :                     n->deleteAction = $2;
    4320 CBC          75 :                     $$ = n;
    4321 ECB             :                 }
    4322                 :             | key_delete key_update
    4323                 :                 {
    4324 GIC          48 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4325                 : 
    4326 CBC          48 :                     n->updateAction = $2;
    4327 GIC          48 :                     n->deleteAction = $1;
    4328              48 :                     $$ = n;
    4329                 :                 }
    4330 ECB             :             | /*EMPTY*/
    4331                 :                 {
    4332 GIC         845 :                     KeyActions *n = palloc(sizeof(KeyActions));
    4333                 : 
    4334             845 :                     n->updateAction = palloc(sizeof(KeyAction));
    4335             845 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4336 CBC         845 :                     n->updateAction->cols = NIL;
    4337 GIC         845 :                     n->deleteAction = palloc(sizeof(KeyAction));
    4338             845 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4339             845 :                     n->deleteAction->cols = NIL;
    4340 GBC         845 :                     $$ = n;
    4341                 :                 }
    4342                 :         ;
    4343                 : 
    4344                 : key_update: ON UPDATE key_action
    4345                 :                 {
    4346 GIC         139 :                     if (($3)->cols)
    4347               3 :                         ereport(ERROR,
    4348 ECB             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4349                 :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4350                 :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4351                 :                                  parser_errposition(@1)));
    4352 CBC         136 :                     $$ = $3;
    4353                 :                 }
    4354                 :         ;
    4355                 : 
    4356                 : key_delete: ON DELETE_P key_action
    4357 ECB             :                 {
    4358 GIC         181 :                     $$ = $3;
    4359 ECB             :                 }
    4360                 :         ;
    4361                 : 
    4362                 : key_action:
    4363                 :             NO ACTION
    4364                 :                 {
    4365 GIC          29 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4366                 : 
    4367              29 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4368              29 :                     n->cols = NIL;
    4369 GBC          29 :                     $$ = n;
    4370                 :                 }
    4371                 :             | RESTRICT
    4372                 :                 {
    4373 GIC          12 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4374 ECB             : 
    4375 CBC          12 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4376 GIC          12 :                     n->cols = NIL;
    4377              12 :                     $$ = n;
    4378                 :                 }
    4379                 :             | CASCADE
    4380                 :                 {
    4381 CBC         179 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4382                 : 
    4383             179 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4384             179 :                     n->cols = NIL;
    4385             179 :                     $$ = n;
    4386 ECB             :                 }
    4387                 :             | SET NULL_P opt_column_list
    4388                 :                 {
    4389 GIC          67 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4390                 : 
    4391 CBC          67 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4392 GIC          67 :                     n->cols = $3;
    4393 CBC          67 :                     $$ = n;
    4394 ECB             :                 }
    4395                 :             | SET DEFAULT opt_column_list
    4396                 :                 {
    4397 CBC          33 :                     KeyAction *n = palloc(sizeof(KeyAction));
    4398                 : 
    4399 GIC          33 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4400              33 :                     n->cols = $3;
    4401 CBC          33 :                     $$ = n;
    4402                 :                 }
    4403 ECB             :         ;
    4404                 : 
    4405 CBC         761 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4406 GIC       12854 :             | /*EMPTY*/                             { $$ = NIL; }
    4407                 :         ;
    4408                 : 
    4409 ECB             : /* Optional partition key specification */
    4410 GIC        2187 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4411 CBC       14881 :             | /*EMPTY*/         { $$ = NULL; }
    4412 ECB             :         ;
    4413                 : 
    4414                 : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4415                 :                 {
    4416 GIC        2190 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4417 ECB             : 
    4418 GNC        2190 :                     n->strategy = parsePartitionStrategy($3);
    4419 CBC        2187 :                     n->partParams = $5;
    4420            2187 :                     n->location = @1;
    4421 ECB             : 
    4422 CBC        2187 :                     $$ = n;
    4423 ECB             :                 }
    4424                 :         ;
    4425                 : 
    4426 GIC        2190 : part_params:    part_elem                       { $$ = list_make1($1); }
    4427             195 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4428                 :         ;
    4429                 : 
    4430                 : part_elem: ColId opt_collate opt_qualified_name
    4431 ECB             :                 {
    4432 CBC        2242 :                     PartitionElem *n = makeNode(PartitionElem);
    4433                 : 
    4434 GIC        2242 :                     n->name = $1;
    4435            2242 :                     n->expr = NULL;
    4436            2242 :                     n->collation = $2;
    4437 CBC        2242 :                     n->opclass = $3;
    4438 GIC        2242 :                     n->location = @1;
    4439            2242 :                     $$ = n;
    4440                 :                 }
    4441                 :             | func_expr_windowless opt_collate opt_qualified_name
    4442                 :                 {
    4443 CBC          65 :                     PartitionElem *n = makeNode(PartitionElem);
    4444                 : 
    4445 GIC          65 :                     n->name = NULL;
    4446              65 :                     n->expr = $1;
    4447              65 :                     n->collation = $2;
    4448              65 :                     n->opclass = $3;
    4449              65 :                     n->location = @1;
    4450 CBC          65 :                     $$ = n;
    4451                 :                 }
    4452                 :             | '(' a_expr ')' opt_collate opt_qualified_name
    4453 ECB             :                 {
    4454 CBC          78 :                     PartitionElem *n = makeNode(PartitionElem);
    4455                 : 
    4456 GIC          78 :                     n->name = NULL;
    4457              78 :                     n->expr = $2;
    4458 CBC          78 :                     n->collation = $4;
    4459 GIC          78 :                     n->opclass = $5;
    4460 CBC          78 :                     n->location = @1;
    4461              78 :                     $$ = n;
    4462 ECB             :                 }
    4463                 :         ;
    4464                 : 
    4465                 : table_access_method_clause:
    4466 CBC          57 :             USING name                          { $$ = $2; }
    4467 GIC       17918 :             | /*EMPTY*/                         { $$ = NULL; }
    4468 ECB             :         ;
    4469                 : 
    4470                 : /* WITHOUT OIDS is legacy only */
    4471                 : OptWith:
    4472 GIC         299 :             WITH reloptions             { $$ = $2; }
    4473              12 :             | WITHOUT OIDS              { $$ = NIL; }
    4474 CBC       17389 :             | /*EMPTY*/                 { $$ = NIL; }
    4475                 :         ;
    4476 ECB             : 
    4477 CBC          25 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4478              49 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4479 GIC          12 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4480           17614 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4481                 :         ;
    4482 ECB             : 
    4483 GIC          96 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4484 CBC       20705 :             | /*EMPTY*/                             { $$ = NULL; }
    4485 ECB             :         ;
    4486                 : 
    4487 GIC          33 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4488            3769 :             | /*EMPTY*/                             { $$ = NULL; }
    4489                 :         ;
    4490 ECB             : 
    4491 CBC       33368 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4492                 :         ;
    4493                 : 
    4494                 : /*****************************************************************************
    4495 ECB             :  *
    4496                 :  *      QUERY :
    4497                 :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4498                 :  *                  ON expression-list FROM from_list
    4499                 :  *
    4500                 :  * Note: the expectation here is that the clauses after ON are a subset of
    4501                 :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4502                 :  * someday a WHERE clause.  Much less than that is currently implemented,
    4503                 :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4504                 :  * errors as necessary at execution.
    4505                 :  *
    4506                 :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4507                 :  *
    4508                 :  *****************************************************************************/
    4509                 : 
    4510                 : CreateStatsStmt:
    4511                 :             CREATE STATISTICS opt_qualified_name
    4512                 :             opt_name_list ON stats_params FROM from_list
    4513                 :                 {
    4514 CBC         274 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4515                 : 
    4516 GIC         274 :                     n->defnames = $3;
    4517             274 :                     n->stat_types = $4;
    4518             274 :                     n->exprs = $6;
    4519 CBC         274 :                     n->relations = $8;
    4520 GIC         274 :                     n->stxcomment = NULL;
    4521 CBC         274 :                     n->if_not_exists = false;
    4522             274 :                     $$ = (Node *) n;
    4523 ECB             :                 }
    4524                 :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4525                 :             opt_name_list ON stats_params FROM from_list
    4526                 :                 {
    4527 GIC           6 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4528                 : 
    4529               6 :                     n->defnames = $6;
    4530 CBC           6 :                     n->stat_types = $7;
    4531 GIC           6 :                     n->exprs = $9;
    4532 CBC           6 :                     n->relations = $11;
    4533               6 :                     n->stxcomment = NULL;
    4534               6 :                     n->if_not_exists = true;
    4535               6 :                     $$ = (Node *) n;
    4536 ECB             :                 }
    4537                 :             ;
    4538                 : 
    4539                 : /*
    4540                 :  * Statistics attributes can be either simple column references, or arbitrary
    4541                 :  * expressions in parens.  For compatibility with index attributes permitted
    4542                 :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4543                 :  * written without parens.
    4544                 :  */
    4545                 : 
    4546 CBC         286 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4547             461 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4548 ECB             :         ;
    4549                 : 
    4550                 : stats_param:    ColId
    4551                 :                 {
    4552 GIC         531 :                     $$ = makeNode(StatsElem);
    4553 CBC         531 :                     $$->name = $1;
    4554             531 :                     $$->expr = NULL;
    4555                 :                 }
    4556                 :             | func_expr_windowless
    4557                 :                 {
    4558 GIC          10 :                     $$ = makeNode(StatsElem);
    4559 CBC          10 :                     $$->name = NULL;
    4560              10 :                     $$->expr = $1;
    4561 ECB             :                 }
    4562                 :             | '(' a_expr ')'
    4563                 :                 {
    4564 CBC         206 :                     $$ = makeNode(StatsElem);
    4565             206 :                     $$->name = NULL;
    4566             206 :                     $$->expr = $2;
    4567 ECB             :                 }
    4568                 :         ;
    4569                 : 
    4570                 : /*****************************************************************************
    4571                 :  *
    4572                 :  *      QUERY :
    4573                 :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4574                 :  *                  SET STATISTICS  <SignedIconst>
    4575                 :  *
    4576                 :  *****************************************************************************/
    4577                 : 
    4578                 : AlterStatsStmt:
    4579                 :             ALTER STATISTICS any_name SET STATISTICS SignedIconst
    4580                 :                 {
    4581 GIC          10 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4582                 : 
    4583              10 :                     n->defnames = $3;
    4584              10 :                     n->missing_ok = false;
    4585              10 :                     n->stxstattarget = $6;
    4586              10 :                     $$ = (Node *) n;
    4587                 :                 }
    4588                 :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS SignedIconst
    4589                 :                 {
    4590               3 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4591                 : 
    4592               3 :                     n->defnames = $5;
    4593               3 :                     n->missing_ok = true;
    4594               3 :                     n->stxstattarget = $8;
    4595               3 :                     $$ = (Node *) n;
    4596                 :                 }
    4597                 :             ;
    4598                 : 
    4599                 : /*****************************************************************************
    4600                 :  *
    4601 ECB             :  *      QUERY :
    4602                 :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4603                 :  *
    4604                 :  *
    4605                 :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4606                 :  *
    4607                 :  *****************************************************************************/
    4608                 : 
    4609                 : CreateAsStmt:
    4610                 :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4611                 :                 {
    4612 GIC         571 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4613                 : 
    4614 CBC         571 :                     ctas->query = $6;
    4615 GIC         571 :                     ctas->into = $4;
    4616 CBC         571 :                     ctas->objtype = OBJECT_TABLE;
    4617             571 :                     ctas->is_select_into = false;
    4618             571 :                     ctas->if_not_exists = false;
    4619 ECB             :                     /* cram additional flags into the IntoClause */
    4620 CBC         571 :                     $4->rel->relpersistence = $2;
    4621             571 :                     $4->skipData = !($7);
    4622             571 :                     $$ = (Node *) ctas;
    4623                 :                 }
    4624                 :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4625                 :                 {
    4626 GIC          25 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4627                 : 
    4628              25 :                     ctas->query = $9;
    4629              25 :                     ctas->into = $7;
    4630              25 :                     ctas->objtype = OBJECT_TABLE;
    4631              25 :                     ctas->is_select_into = false;
    4632              25 :                     ctas->if_not_exists = true;
    4633 ECB             :                     /* cram additional flags into the IntoClause */
    4634 CBC          25 :                     $7->rel->relpersistence = $2;
    4635 GIC          25 :                     $7->skipData = !($10);
    4636              25 :                     $$ = (Node *) ctas;
    4637                 :                 }
    4638                 :         ;
    4639 ECB             : 
    4640                 : create_as_target:
    4641                 :             qualified_name opt_column_list table_access_method_clause
    4642                 :             OptWith OnCommitOption OptTableSpace
    4643                 :                 {
    4644 GIC         638 :                     $$ = makeNode(IntoClause);
    4645 CBC         638 :                     $$->rel = $1;
    4646             638 :                     $$->colNames = $2;
    4647             638 :                     $$->accessMethod = $3;
    4648 GIC         638 :                     $$->options = $4;
    4649             638 :                     $$->onCommit = $5;
    4650             638 :                     $$->tableSpaceName = $6;
    4651 CBC         638 :                     $$->viewQuery = NULL;
    4652             638 :                     $$->skipData = false;        /* might get changed later */
    4653 ECB             :                 }
    4654                 :         ;
    4655                 : 
    4656                 : opt_with_data:
    4657 GIC          18 :             WITH DATA_P                             { $$ = true; }
    4658             105 :             | WITH NO DATA_P                        { $$ = false; }
    4659             910 :             | /*EMPTY*/                             { $$ = true; }
    4660                 :         ;
    4661                 : 
    4662                 : 
    4663                 : /*****************************************************************************
    4664                 :  *
    4665                 :  *      QUERY :
    4666                 :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4667                 :  *
    4668 ECB             :  *****************************************************************************/
    4669                 : 
    4670                 : CreateMatViewStmt:
    4671                 :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4672                 :                 {
    4673 CBC         248 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4674                 : 
    4675 GIC         248 :                     ctas->query = $7;
    4676             248 :                     ctas->into = $5;
    4677 CBC         248 :                     ctas->objtype = OBJECT_MATVIEW;
    4678 GIC         248 :                     ctas->is_select_into = false;
    4679 CBC         248 :                     ctas->if_not_exists = false;
    4680 ECB             :                     /* cram additional flags into the IntoClause */
    4681 CBC         248 :                     $5->rel->relpersistence = $2;
    4682             248 :                     $5->skipData = !($8);
    4683 GIC         248 :                     $$ = (Node *) ctas;
    4684                 :                 }
    4685                 :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4686                 :                 {
    4687              24 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4688                 : 
    4689              24 :                     ctas->query = $10;
    4690              24 :                     ctas->into = $8;
    4691              24 :                     ctas->objtype = OBJECT_MATVIEW;
    4692              24 :                     ctas->is_select_into = false;
    4693              24 :                     ctas->if_not_exists = true;
    4694                 :                     /* cram additional flags into the IntoClause */
    4695              24 :                     $8->rel->relpersistence = $2;
    4696              24 :                     $8->skipData = !($11);
    4697              24 :                     $$ = (Node *) ctas;
    4698                 :                 }
    4699 ECB             :         ;
    4700                 : 
    4701                 : create_mv_target:
    4702                 :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4703                 :                 {
    4704 CBC         272 :                     $$ = makeNode(IntoClause);
    4705             272 :                     $$->rel = $1;
    4706 GIC         272 :                     $$->colNames = $2;
    4707 CBC         272 :                     $$->accessMethod = $3;
    4708             272 :                     $$->options = $4;
    4709             272 :                     $$->onCommit = ONCOMMIT_NOOP;
    4710 GIC         272 :                     $$->tableSpaceName = $5;
    4711             272 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    4712             272 :                     $$->skipData = false;        /* might get changed later */
    4713 ECB             :                 }
    4714                 :         ;
    4715                 : 
    4716 LBC           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    4717 CBC         272 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    4718 ECB             :         ;
    4719                 : 
    4720                 : 
    4721                 : /*****************************************************************************
    4722                 :  *
    4723                 :  *      QUERY :
    4724                 :  *              REFRESH MATERIALIZED VIEW qualified_name
    4725                 :  *
    4726                 :  *****************************************************************************/
    4727                 : 
    4728                 : RefreshMatViewStmt:
    4729                 :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    4730                 :                 {
    4731 CBC         123 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    4732 ECB             : 
    4733 CBC         123 :                     n->concurrent = $4;
    4734             123 :                     n->relation = $5;
    4735             123 :                     n->skipData = !($6);
    4736             123 :                     $$ = (Node *) n;
    4737 ECB             :                 }
    4738                 :         ;
    4739                 : 
    4740                 : 
    4741                 : /*****************************************************************************
    4742                 :  *
    4743                 :  *      QUERY :
    4744                 :  *              CREATE SEQUENCE seqname
    4745                 :  *              ALTER SEQUENCE seqname
    4746                 :  *
    4747                 :  *****************************************************************************/
    4748                 : 
    4749                 : CreateSeqStmt:
    4750                 :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    4751                 :                 {
    4752 GIC         296 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4753                 : 
    4754             296 :                     $4->relpersistence = $2;
    4755             296 :                     n->sequence = $4;
    4756             296 :                     n->options = $5;
    4757             296 :                     n->ownerId = InvalidOid;
    4758             296 :                     n->if_not_exists = false;
    4759             296 :                     $$ = (Node *) n;
    4760 ECB             :                 }
    4761                 :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    4762                 :                 {
    4763 CBC          12 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    4764 ECB             : 
    4765 CBC          12 :                     $7->relpersistence = $2;
    4766              12 :                     n->sequence = $7;
    4767 GIC          12 :                     n->options = $8;
    4768 CBC          12 :                     n->ownerId = InvalidOid;
    4769              12 :                     n->if_not_exists = true;
    4770              12 :                     $$ = (Node *) n;
    4771                 :                 }
    4772                 :         ;
    4773                 : 
    4774 ECB             : AlterSeqStmt:
    4775                 :             ALTER SEQUENCE qualified_name SeqOptList
    4776                 :                 {
    4777 CBC          87 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4778 ECB             : 
    4779 CBC          87 :                     n->sequence = $3;
    4780              87 :                     n->options = $4;
    4781 GIC          87 :                     n->missing_ok = false;
    4782 CBC          87 :                     $$ = (Node *) n;
    4783 ECB             :                 }
    4784                 :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    4785                 :                 {
    4786 GIC           6 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    4787                 : 
    4788               6 :                     n->sequence = $5;
    4789               6 :                     n->options = $6;
    4790               6 :                     n->missing_ok = true;
    4791 CBC           6 :                     $$ = (Node *) n;
    4792 ECB             :                 }
    4793                 : 
    4794                 :         ;
    4795                 : 
    4796 CBC         118 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    4797             190 :             | /*EMPTY*/                             { $$ = NIL; }
    4798 ECB             :         ;
    4799                 : 
    4800 GIC          20 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    4801             145 :             | /*EMPTY*/                             { $$ = NIL; }
    4802                 :         ;
    4803 EUB             : 
    4804 CBC         231 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    4805 GIC         322 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    4806                 :         ;
    4807                 : 
    4808                 : SeqOptElem: AS SimpleTypename
    4809                 :                 {
    4810              90 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    4811                 :                 }
    4812                 :             | CACHE NumericOnly
    4813                 :                 {
    4814              48 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    4815                 :                 }
    4816                 :             | CYCLE
    4817                 :                 {
    4818 CBC          17 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    4819                 :                 }
    4820 ECB             :             | NO CYCLE
    4821                 :                 {
    4822 CBC           7 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    4823 ECB             :                 }
    4824                 :             | INCREMENT opt_by NumericOnly
    4825                 :                 {
    4826 GIC          99 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    4827                 :                 }
    4828                 :             | MAXVALUE NumericOnly
    4829                 :                 {
    4830              34 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    4831                 :                 }
    4832                 :             | MINVALUE NumericOnly
    4833                 :                 {
    4834              36 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    4835                 :                 }
    4836                 :             | NO MAXVALUE
    4837                 :                 {
    4838              37 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    4839 ECB             :                 }
    4840                 :             | NO MINVALUE
    4841                 :                 {
    4842 CBC          37 :                     $$ = makeDefElem("minvalue", NULL, @1);
    4843 ECB             :                 }
    4844                 :             | OWNED BY any_name
    4845                 :                 {
    4846 CBC          31 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    4847                 :                 }
    4848                 :             | SEQUENCE NAME_P any_name
    4849                 :                 {
    4850 ECB             :                     /* not documented, only used by pg_dump */
    4851 GIC          14 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    4852 ECB             :                 }
    4853                 :             | START opt_with NumericOnly
    4854                 :                 {
    4855 CBC          82 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    4856 ECB             :                 }
    4857                 :             | RESTART
    4858                 :                 {
    4859 GIC           3 :                     $$ = makeDefElem("restart", NULL, @1);
    4860                 :                 }
    4861                 :             | RESTART opt_with NumericOnly
    4862                 :                 {
    4863              30 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    4864 ECB             :                 }
    4865                 :         ;
    4866                 : 
    4867                 : opt_by:     BY
    4868                 :             | /* EMPTY */
    4869                 :       ;
    4870                 : 
    4871                 : NumericOnly:
    4872 GIC         158 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    4873 LBC           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    4874                 :             | '-' FCONST
    4875 ECB             :                 {
    4876 CBC          10 :                     Float      *f = makeFloat($2);
    4877 ECB             : 
    4878 CBC          10 :                     doNegateFloat(f);
    4879 GIC          10 :                     $$ = (Node *) f;
    4880                 :                 }
    4881           18454 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    4882                 :         ;
    4883 ECB             : 
    4884 CBC          40 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    4885 GIC           3 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    4886                 :         ;
    4887 ECB             : 
    4888                 : /*****************************************************************************
    4889                 :  *
    4890                 :  *      QUERIES :
    4891                 :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    4892                 :  *              DROP [PROCEDURAL] LANGUAGE ...
    4893                 :  *
    4894                 :  *****************************************************************************/
    4895                 : 
    4896                 : CreatePLangStmt:
    4897                 :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    4898                 :             {
    4899                 :                 /*
    4900                 :                  * We now interpret parameterless CREATE LANGUAGE as
    4901                 :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    4902                 :                  * to "IF NOT EXISTS", which isn't quite the same, but
    4903                 :                  * seems more useful than throwing an error.  We just
    4904                 :                  * ignore TRUSTED, as the previous code would have too.
    4905                 :                  */
    4906 UIC           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    4907                 : 
    4908               0 :                 n->if_not_exists = $2;
    4909 LBC           0 :                 n->extname = $6;
    4910 UIC           0 :                 n->options = NIL;
    4911               0 :                 $$ = (Node *) n;
    4912                 :             }
    4913 ECB             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    4914                 :               HANDLER handler_name opt_inline_handler opt_validator
    4915                 :             {
    4916 GIC         326 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    4917 ECB             : 
    4918 GIC         326 :                 n->replace = $2;
    4919             326 :                 n->plname = $6;
    4920             326 :                 n->plhandler = $8;
    4921 CBC         326 :                 n->plinline = $9;
    4922 GIC         326 :                 n->plvalidator = $10;
    4923             326 :                 n->pltrusted = $3;
    4924             326 :                 $$ = (Node *) n;
    4925 ECB             :             }
    4926                 :         ;
    4927                 : 
    4928                 : opt_trusted:
    4929 CBC         311 :             TRUSTED                                 { $$ = true; }
    4930 GIC          18 :             | /*EMPTY*/                             { $$ = false; }
    4931                 :         ;
    4932                 : 
    4933 ECB             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    4934                 :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    4935                 :  * Work around by using simple names, instead.
    4936                 :  */
    4937                 : handler_name:
    4938 CBC        1038 :             name                        { $$ = list_make1(makeString($1)); }
    4939 GIC           1 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    4940                 :         ;
    4941                 : 
    4942 ECB             : opt_inline_handler:
    4943 GIC         317 :             INLINE_P handler_name                   { $$ = $2; }
    4944               9 :             | /*EMPTY*/                             { $$ = NIL; }
    4945                 :         ;
    4946 ECB             : 
    4947                 : validator_clause:
    4948 GIC         317 :             VALIDATOR handler_name                  { $$ = $2; }
    4949 UIC           0 :             | NO VALIDATOR                          { $$ = NIL; }
    4950 ECB             :         ;
    4951                 : 
    4952                 : opt_validator:
    4953 GIC         317 :             validator_clause                        { $$ = $1; }
    4954               9 :             | /*EMPTY*/                             { $$ = NIL; }
    4955                 :         ;
    4956                 : 
    4957                 : opt_procedural:
    4958                 :             PROCEDURAL
    4959 ECB             :             | /*EMPTY*/
    4960 EUB             :         ;
    4961                 : 
    4962                 : /*****************************************************************************
    4963 ECB             :  *
    4964                 :  *      QUERY:
    4965                 :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    4966                 :  *
    4967                 :  *****************************************************************************/
    4968                 : 
    4969                 : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    4970                 :                 {
    4971 CBC          48 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    4972 ECB             : 
    4973 GIC          48 :                     n->tablespacename = $3;
    4974              48 :                     n->owner = $4;
    4975              48 :                     n->location = $6;
    4976              48 :                     n->options = $7;
    4977              48 :                     $$ = (Node *) n;
    4978                 :                 }
    4979                 :         ;
    4980                 : 
    4981 UIC           0 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    4982 GIC          48 :             | /*EMPTY */                { $$ = NULL; }
    4983                 :         ;
    4984                 : 
    4985                 : /*****************************************************************************
    4986                 :  *
    4987                 :  *      QUERY :
    4988                 :  *              DROP TABLESPACE <tablespace>
    4989                 :  *
    4990                 :  *      No need for drop behaviour as we cannot implement dependencies for
    4991                 :  *      objects in other databases; we can only support RESTRICT.
    4992                 :  *
    4993 EUB             :  ****************************************************************************/
    4994                 : 
    4995                 : DropTableSpaceStmt: DROP TABLESPACE name
    4996                 :                 {
    4997 GBC          30 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    4998 EUB             : 
    4999 GIC          30 :                     n->tablespacename = $3;
    5000              30 :                     n->missing_ok = false;
    5001              30 :                     $$ = (Node *) n;
    5002                 :                 }
    5003 ECB             :                 |  DROP TABLESPACE IF_P EXISTS name
    5004                 :                 {
    5005 LBC           0 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5006 ECB             : 
    5007 LBC           0 :                     n->tablespacename = $5;
    5008               0 :                     n->missing_ok = true;
    5009               0 :                     $$ = (Node *) n;
    5010 ECB             :                 }
    5011                 :         ;
    5012                 : 
    5013                 : /*****************************************************************************
    5014                 :  *
    5015                 :  *      QUERY:
    5016                 :  *             CREATE EXTENSION extension
    5017                 :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5018                 :  *
    5019                 :  *****************************************************************************/
    5020                 : 
    5021                 : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5022                 :                 {
    5023 GIC         445 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5024                 : 
    5025 CBC         445 :                     n->extname = $3;
    5026             445 :                     n->if_not_exists = false;
    5027 GIC         445 :                     n->options = $5;
    5028             445 :                     $$ = (Node *) n;
    5029                 :                 }
    5030 ECB             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5031                 :                 {
    5032 GIC           7 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5033                 : 
    5034               7 :                     n->extname = $6;
    5035 CBC           7 :                     n->if_not_exists = true;
    5036 GBC           7 :                     n->options = $8;
    5037 GIC           7 :                     $$ = (Node *) n;
    5038                 :                 }
    5039                 :         ;
    5040 ECB             : 
    5041                 : create_extension_opt_list:
    5042                 :             create_extension_opt_list create_extension_opt_item
    5043 GIC          39 :                 { $$ = lappend($1, $2); }
    5044                 :             | /* EMPTY */
    5045             452 :                 { $$ = NIL; }
    5046                 :         ;
    5047                 : 
    5048                 : create_extension_opt_item:
    5049                 :             SCHEMA name
    5050                 :                 {
    5051              17 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5052                 :                 }
    5053                 :             | VERSION_P NonReservedWord_or_Sconst
    5054                 :                 {
    5055               3 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5056                 :                 }
    5057                 :             | FROM NonReservedWord_or_Sconst
    5058 ECB             :                 {
    5059 UIC           0 :                     ereport(ERROR,
    5060 ECB             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5061                 :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5062                 :                              parser_errposition(@1)));
    5063                 :                 }
    5064                 :             | CASCADE
    5065                 :                 {
    5066 GIC          19 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5067                 :                 }
    5068 EUB             :         ;
    5069 ECB             : 
    5070                 : /*****************************************************************************
    5071                 :  *
    5072                 :  * ALTER EXTENSION name UPDATE [ TO version ]
    5073                 :  *
    5074                 :  *****************************************************************************/
    5075                 : 
    5076                 : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5077                 :                 {
    5078 GIC          11 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5079                 : 
    5080              11 :                     n->extname = $3;
    5081              11 :                     n->options = $5;
    5082              11 :                     $$ = (Node *) n;
    5083                 :                 }
    5084 ECB             :         ;
    5085                 : 
    5086                 : alter_extension_opt_list:
    5087                 :             alter_extension_opt_list alter_extension_opt_item
    5088 CBC          11 :                 { $$ = lappend($1, $2); }
    5089                 :             | /* EMPTY */
    5090 GIC          11 :                 { $$ = NIL; }
    5091                 :         ;
    5092 EUB             : 
    5093                 : alter_extension_opt_item:
    5094                 :             TO NonReservedWord_or_Sconst
    5095                 :                 {
    5096 GBC          11 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5097                 :                 }
    5098                 :         ;
    5099                 : 
    5100                 : /*****************************************************************************
    5101                 :  *
    5102                 :  * ALTER EXTENSION name ADD/DROP object-identifier
    5103                 :  *
    5104                 :  *****************************************************************************/
    5105                 : 
    5106                 : AlterExtensionContentsStmt:
    5107                 :             ALTER EXTENSION name add_drop object_type_name name
    5108                 :                 {
    5109 GIC           9 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5110 ECB             : 
    5111 GIC           9 :                     n->extname = $3;
    5112 CBC           9 :                     n->action = $4;
    5113               9 :                     n->objtype = $5;
    5114               9 :                     n->object = (Node *) makeString($6);
    5115               9 :                     $$ = (Node *) n;
    5116                 :                 }
    5117                 :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5118                 :                 {
    5119              24 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5120                 : 
    5121              24 :                     n->extname = $3;
    5122              24 :                     n->action = $4;
    5123              24 :                     n->objtype = $5;
    5124              24 :                     n->object = (Node *) $6;
    5125 GIC          24 :                     $$ = (Node *) n;
    5126                 :                 }
    5127                 :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5128                 :                 {
    5129               4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5130 ECB             : 
    5131 GIC           4 :                     n->extname = $3;
    5132 CBC           4 :                     n->action = $4;
    5133 GIC           4 :                     n->objtype = OBJECT_AGGREGATE;
    5134               4 :                     n->object = (Node *) $6;
    5135               4 :                     $$ = (Node *) n;
    5136                 :                 }
    5137                 :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5138 ECB             :                 {
    5139 GIC           2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5140                 : 
    5141               2 :                     n->extname = $3;
    5142 CBC           2 :                     n->action = $4;
    5143 GIC           2 :                     n->objtype = OBJECT_CAST;
    5144               2 :                     n->object = (Node *) list_make2($7, $9);
    5145               2 :                     $$ = (Node *) n;
    5146 EUB             :                 }
    5147                 :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5148                 :                 {
    5149 UIC           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5150                 : 
    5151               0 :                     n->extname = $3;
    5152               0 :                     n->action = $4;
    5153 LBC           0 :                     n->objtype = OBJECT_DOMAIN;
    5154 UIC           0 :                     n->object = (Node *) $6;
    5155               0 :                     $$ = (Node *) n;
    5156                 :                 }
    5157                 :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5158                 :                 {
    5159 GIC          31 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5160                 : 
    5161              31 :                     n->extname = $3;
    5162              31 :                     n->action = $4;
    5163              31 :                     n->objtype = OBJECT_FUNCTION;
    5164              31 :                     n->object = (Node *) $6;
    5165 CBC          31 :                     $$ = (Node *) n;
    5166                 :                 }
    5167 ECB             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5168                 :                 {
    5169 CBC           9 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5170                 : 
    5171 GIC           9 :                     n->extname = $3;
    5172               9 :                     n->action = $4;
    5173               9 :                     n->objtype = OBJECT_OPERATOR;
    5174               9 :                     n->object = (Node *) $6;
    5175 CBC           9 :                     $$ = (Node *) n;
    5176                 :                 }
    5177 ECB             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5178                 :                 {
    5179 GIC           2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5180                 : 
    5181               2 :                     n->extname = $3;
    5182               2 :                     n->action = $4;
    5183 CBC           2 :                     n->objtype = OBJECT_OPCLASS;
    5184 GIC           2 :                     n->object = (Node *) lcons(makeString($9), $7);
    5185               2 :                     $$ = (Node *) n;
    5186                 :                 }
    5187                 :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5188                 :                 {
    5189               2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5190                 : 
    5191               2 :                     n->extname = $3;
    5192               2 :                     n->action = $4;
    5193               2 :                     n->objtype = OBJECT_OPFAMILY;
    5194               2 :                     n->object = (Node *) lcons(makeString($9), $7);
    5195               2 :                     $$ = (Node *) n;
    5196 ECB             :                 }
    5197                 :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5198                 :                 {
    5199 LBC           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5200 ECB             : 
    5201 LBC           0 :                     n->extname = $3;
    5202               0 :                     n->action = $4;
    5203 UIC           0 :                     n->objtype = OBJECT_PROCEDURE;
    5204               0 :                     n->object = (Node *) $6;
    5205               0 :                     $$ = (Node *) n;
    5206 ECB             :                 }
    5207                 :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5208                 :                 {
    5209 LBC           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5210 ECB             : 
    5211 LBC           0 :                     n->extname = $3;
    5212               0 :                     n->action = $4;
    5213 UIC           0 :                     n->objtype = OBJECT_ROUTINE;
    5214               0 :                     n->object = (Node *) $6;
    5215               0 :                     $$ = (Node *) n;
    5216 ECB             :                 }
    5217                 :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5218                 :                 {
    5219 CBC           2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5220 ECB             : 
    5221 CBC           2 :                     n->extname = $3;
    5222               2 :                     n->action = $4;
    5223 GIC           2 :                     n->objtype = OBJECT_TRANSFORM;
    5224               2 :                     n->object = (Node *) list_make2($7, makeString($9));
    5225               2 :                     $$ = (Node *) n;
    5226 ECB             :                 }
    5227                 :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5228                 :                 {
    5229 CBC           2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5230 ECB             : 
    5231 CBC           2 :                     n->extname = $3;
    5232               2 :                     n->action = $4;
    5233 GIC           2 :                     n->objtype = OBJECT_TYPE;
    5234               2 :                     n->object = (Node *) $6;
    5235               2 :                     $$ = (Node *) n;
    5236 EUB             :                 }
    5237                 :         ;
    5238                 : 
    5239                 : /*****************************************************************************
    5240                 :  *
    5241                 :  *      QUERY:
    5242                 :  *             CREATE FOREIGN DATA WRAPPER name options
    5243                 :  *
    5244                 :  *****************************************************************************/
    5245                 : 
    5246 ECB             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5247                 :                 {
    5248 CBC          94 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5249 ECB             : 
    5250 CBC          94 :                     n->fdwname = $5;
    5251              94 :                     n->func_options = $6;
    5252              94 :                     n->options = $7;
    5253 GIC          94 :                     $$ = (Node *) n;
    5254                 :                 }
    5255                 :         ;
    5256 ECB             : 
    5257                 : fdw_option:
    5258 CBC          27 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5259 LBC           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5260 CBC          22 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5261               3 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5262 ECB             :         ;
    5263                 : 
    5264                 : fdw_options:
    5265 GIC          43 :             fdw_option                          { $$ = list_make1($1); }
    5266 CBC           9 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5267                 :         ;
    5268 ECB             : 
    5269                 : opt_fdw_options:
    5270 CBC          25 :             fdw_options                         { $$ = $1; }
    5271             115 :             | /*EMPTY*/                         { $$ = NIL; }
    5272 ECB             :         ;
    5273                 : 
    5274                 : /*****************************************************************************
    5275                 :  *
    5276                 :  *      QUERY :
    5277                 :  *              ALTER FOREIGN DATA WRAPPER name options
    5278                 :  *
    5279                 :  ****************************************************************************/
    5280                 : 
    5281                 : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5282                 :                 {
    5283 GIC          43 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5284                 : 
    5285              43 :                     n->fdwname = $5;
    5286 GBC          43 :                     n->func_options = $6;
    5287 GIC          43 :                     n->options = $7;
    5288 GBC          43 :                     $$ = (Node *) n;
    5289 EUB             :                 }
    5290                 :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5291                 :                 {
    5292 GBC          18 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5293                 : 
    5294 GIC          18 :                     n->fdwname = $5;
    5295              18 :                     n->func_options = $6;
    5296 GBC          18 :                     n->options = NIL;
    5297 GIC          18 :                     $$ = (Node *) n;
    5298 EUB             :                 }
    5299                 :         ;
    5300                 : 
    5301                 : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5302                 : create_generic_options:
    5303 GIC         340 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5304           35067 :             | /*EMPTY*/                                 { $$ = NIL; }
    5305                 :         ;
    5306 ECB             : 
    5307                 : generic_option_list:
    5308                 :             generic_option_elem
    5309                 :                 {
    5310 CBC         340 :                     $$ = list_make1($1);
    5311 ECB             :                 }
    5312                 :             | generic_option_list ',' generic_option_elem
    5313                 :                 {
    5314 GIC         216 :                     $$ = lappend($1, $3);
    5315                 :                 }
    5316 ECB             :         ;
    5317                 : 
    5318                 : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5319                 : alter_generic_options:
    5320 CBC         235 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5321 ECB             :         ;
    5322                 : 
    5323                 : alter_generic_option_list:
    5324                 :             alter_generic_option_elem
    5325                 :                 {
    5326 GIC         235 :                     $$ = list_make1($1);
    5327                 :                 }
    5328                 :             | alter_generic_option_list ',' alter_generic_option_elem
    5329                 :                 {
    5330              83 :                     $$ = lappend($1, $3);
    5331                 :                 }
    5332                 :         ;
    5333                 : 
    5334                 : alter_generic_option_elem:
    5335 ECB             :             generic_option_elem
    5336                 :                 {
    5337 CBC          99 :                     $$ = $1;
    5338 ECB             :                 }
    5339                 :             | SET generic_option_elem
    5340                 :                 {
    5341 GIC          61 :                     $$ = $2;
    5342              61 :                     $$->defaction = DEFELEM_SET;
    5343                 :                 }
    5344                 :             | ADD_P generic_option_elem
    5345 ECB             :                 {
    5346 GBC          96 :                     $$ = $2;
    5347 CBC          96 :                     $$->defaction = DEFELEM_ADD;
    5348 ECB             :                 }
    5349                 :             | DROP generic_option_name
    5350                 :                 {
    5351 GIC          62 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5352 ECB             :                 }
    5353                 :         ;
    5354                 : 
    5355                 : generic_option_elem:
    5356                 :             generic_option_name generic_option_arg
    5357                 :                 {
    5358 CBC         812 :                     $$ = makeDefElem($1, $2, @1);
    5359                 :                 }
    5360                 :         ;
    5361                 : 
    5362                 : generic_option_name:
    5363 GIC         874 :                 ColLabel            { $$ = $1; }
    5364                 :         ;
    5365                 : 
    5366                 : /* We could use def_arg here, but the spec only requires string literals */
    5367                 : generic_option_arg:
    5368             812 :                 Sconst              { $$ = (Node *) makeString($1); }
    5369                 :         ;
    5370 ECB             : 
    5371                 : /*****************************************************************************
    5372                 :  *
    5373                 :  *      QUERY:
    5374                 :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5375                 :  *
    5376                 :  *****************************************************************************/
    5377                 : 
    5378                 : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5379                 :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5380                 :                 {
    5381 CBC         123 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5382 ECB             : 
    5383 CBC         123 :                     n->servername = $3;
    5384             123 :                     n->servertype = $4;
    5385 GIC         123 :                     n->version = $5;
    5386             123 :                     n->fdwname = $9;
    5387             123 :                     n->options = $10;
    5388             123 :                     n->if_not_exists = false;
    5389             123 :                     $$ = (Node *) n;
    5390 ECB             :                 }
    5391                 :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5392                 :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5393                 :                 {
    5394 GIC          12 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5395                 : 
    5396              12 :                     n->servername = $6;
    5397 CBC          12 :                     n->servertype = $7;
    5398 GIC          12 :                     n->version = $8;
    5399              12 :                     n->fdwname = $12;
    5400              12 :                     n->options = $13;
    5401 CBC          12 :                     n->if_not_exists = true;
    5402 GIC          12 :                     $$ = (Node *) n;
    5403                 :                 }
    5404                 :         ;
    5405                 : 
    5406                 : opt_type:
    5407 CBC           9 :             TYPE_P Sconst           { $$ = $2; }
    5408 GIC         126 :             | /*EMPTY*/             { $$ = NULL; }
    5409                 :         ;
    5410                 : 
    5411                 : 
    5412                 : foreign_server_version:
    5413 CBC          33 :             VERSION_P Sconst        { $$ = $2; }
    5414 UIC           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5415                 :         ;
    5416                 : 
    5417 ECB             : opt_foreign_server_version:
    5418 GIC           9 :             foreign_server_version  { $$ = $1; }
    5419             126 :             | /*EMPTY*/             { $$ = NULL; }
    5420                 :         ;
    5421                 : 
    5422                 : /*****************************************************************************
    5423                 :  *
    5424 ECB             :  *      QUERY :
    5425                 :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5426                 :  *
    5427                 :  ****************************************************************************/
    5428                 : 
    5429                 : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5430                 :                 {
    5431 GIC           3 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5432                 : 
    5433 CBC           3 :                     n->servername = $3;
    5434               3 :                     n->version = $4;
    5435 GIC           3 :                     n->options = $5;
    5436               3 :                     n->has_version = true;
    5437               3 :                     $$ = (Node *) n;
    5438 ECB             :                 }
    5439                 :             | ALTER SERVER name foreign_server_version
    5440                 :                 {
    5441 GIC          21 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5442                 : 
    5443              21 :                     n->servername = $3;
    5444              21 :                     n->version = $4;
    5445 CBC          21 :                     n->has_version = true;
    5446 GIC          21 :                     $$ = (Node *) n;
    5447                 :                 }
    5448                 :             | ALTER SERVER name alter_generic_options
    5449                 :                 {
    5450 CBC          83 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5451                 : 
    5452 GIC          83 :                     n->servername = $3;
    5453              83 :                     n->options = $4;
    5454              83 :                     $$ = (Node *) n;
    5455 ECB             :                 }
    5456                 :         ;
    5457                 : 
    5458                 : /*****************************************************************************
    5459                 :  *
    5460                 :  *      QUERY:
    5461                 :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5462                 :  *
    5463                 :  *****************************************************************************/
    5464                 : 
    5465                 : CreateForeignTableStmt:
    5466                 :         CREATE FOREIGN TABLE qualified_name
    5467                 :             '(' OptTableElementList ')'
    5468                 :             OptInherit SERVER name create_generic_options
    5469                 :                 {
    5470 CBC         179 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5471 ECB             : 
    5472 CBC         179 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5473             179 :                     n->base.relation = $4;
    5474             179 :                     n->base.tableElts = $6;
    5475             179 :                     n->base.inhRelations = $8;
    5476             179 :                     n->base.ofTypename = NULL;
    5477 GIC         179 :                     n->base.constraints = NIL;
    5478             179 :                     n->base.options = NIL;
    5479             179 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5480             179 :                     n->base.tablespacename = NULL;
    5481 CBC         179 :                     n->base.if_not_exists = false;
    5482                 :                     /* FDW-specific data */
    5483             179 :                     n->servername = $10;
    5484             179 :                     n->options = $11;
    5485             179 :                     $$ = (Node *) n;
    5486 ECB             :                 }
    5487                 :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5488                 :             '(' OptTableElementList ')'
    5489                 :             OptInherit SERVER name create_generic_options
    5490                 :                 {
    5491 UIC           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5492                 : 
    5493               0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5494 LBC           0 :                     n->base.relation = $7;
    5495               0 :                     n->base.tableElts = $9;
    5496 UIC           0 :                     n->base.inhRelations = $11;
    5497               0 :                     n->base.ofTypename = NULL;
    5498               0 :                     n->base.constraints = NIL;
    5499               0 :                     n->base.options = NIL;
    5500 LBC           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5501 UBC           0 :                     n->base.tablespacename = NULL;
    5502 UIC           0 :                     n->base.if_not_exists = true;
    5503                 :                     /* FDW-specific data */
    5504               0 :                     n->servername = $13;
    5505 LBC           0 :                     n->options = $14;
    5506               0 :                     $$ = (Node *) n;
    5507                 :                 }
    5508                 :         | CREATE FOREIGN TABLE qualified_name
    5509                 :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5510                 :             SERVER name create_generic_options
    5511                 :                 {
    5512 GIC          40 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5513                 : 
    5514              40 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5515              40 :                     n->base.relation = $4;
    5516              40 :                     n->base.inhRelations = list_make1($7);
    5517              40 :                     n->base.tableElts = $8;
    5518 CBC          40 :                     n->base.partbound = $9;
    5519 GIC          40 :                     n->base.ofTypename = NULL;
    5520 CBC          40 :                     n->base.constraints = NIL;
    5521              40 :                     n->base.options = NIL;
    5522              40 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5523              40 :                     n->base.tablespacename = NULL;
    5524              40 :                     n->base.if_not_exists = false;
    5525                 :                     /* FDW-specific data */
    5526 GIC          40 :                     n->servername = $11;
    5527              40 :                     n->options = $12;
    5528 CBC          40 :                     $$ = (Node *) n;
    5529                 :                 }
    5530 ECB             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5531                 :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5532                 :             SERVER name create_generic_options
    5533                 :                 {
    5534 UIC           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5535                 : 
    5536               0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5537 LBC           0 :                     n->base.relation = $7;
    5538 UIC           0 :                     n->base.inhRelations = list_make1($10);
    5539 LBC           0 :                     n->base.tableElts = $11;
    5540               0 :                     n->base.partbound = $12;
    5541               0 :                     n->base.ofTypename = NULL;
    5542 UIC           0 :                     n->base.constraints = NIL;
    5543               0 :                     n->base.options = NIL;
    5544               0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5545               0 :                     n->base.tablespacename = NULL;
    5546               0 :                     n->base.if_not_exists = true;
    5547                 :                     /* FDW-specific data */
    5548               0 :                     n->servername = $14;
    5549               0 :                     n->options = $15;
    5550               0 :                     $$ = (Node *) n;
    5551                 :                 }
    5552                 :         ;
    5553                 : 
    5554                 : /*****************************************************************************
    5555                 :  *
    5556                 :  *      QUERY:
    5557 ECB             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5558                 :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5559                 :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5560                 :  *
    5561                 :  ****************************************************************************/
    5562                 : 
    5563                 : ImportForeignSchemaStmt:
    5564                 :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5565                 :           FROM SERVER name INTO name create_generic_options
    5566                 :             {
    5567 CBC          22 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5568 ECB             : 
    5569 GIC          22 :                 n->server_name = $8;
    5570 CBC          22 :                 n->remote_schema = $4;
    5571              22 :                 n->local_schema = $10;
    5572              22 :                 n->list_type = $5->type;
    5573 GIC          22 :                 n->table_list = $5->table_names;
    5574              22 :                 n->options = $11;
    5575              22 :                 $$ = (Node *) n;
    5576                 :             }
    5577                 :         ;
    5578 EUB             : 
    5579                 : import_qualification_type:
    5580 GBC           5 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5581               7 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5582 EUB             :         ;
    5583                 : 
    5584                 : import_qualification:
    5585                 :         import_qualification_type '(' relation_expr_list ')'
    5586                 :             {
    5587 GBC          12 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5588 EUB             : 
    5589 GBC          12 :                 n->type = $1;
    5590 GIC          12 :                 n->table_names = $3;
    5591 GBC          12 :                 $$ = n;
    5592 EUB             :             }
    5593                 :         | /*EMPTY*/
    5594                 :             {
    5595 GIC          10 :                 ImportQual *n = (ImportQual *) palloc(sizeof(ImportQual));
    5596              10 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5597              10 :                 n->table_names = NIL;
    5598              10 :                 $$ = n;
    5599 ECB             :             }
    5600                 :         ;
    5601                 : 
    5602                 : /*****************************************************************************
    5603                 :  *
    5604                 :  *      QUERY:
    5605                 :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5606                 :  *
    5607                 :  *****************************************************************************/
    5608                 : 
    5609                 : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5610                 :                 {
    5611 CBC         115 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5612                 : 
    5613             115 :                     n->user = $5;
    5614             115 :                     n->servername = $7;
    5615             115 :                     n->options = $8;
    5616 GIC         115 :                     n->if_not_exists = false;
    5617             115 :                     $$ = (Node *) n;
    5618                 :                 }
    5619                 :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5620                 :                 {
    5621 GBC           3 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5622                 : 
    5623               3 :                     n->user = $8;
    5624               3 :                     n->servername = $10;
    5625               3 :                     n->options = $11;
    5626               3 :                     n->if_not_exists = true;
    5627               3 :                     $$ = (Node *) n;
    5628 EUB             :                 }
    5629                 :         ;
    5630                 : 
    5631                 : /* User mapping authorization identifier */
    5632 GBC         212 : auth_ident: RoleSpec            { $$ = $1; }
    5633              23 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5634                 :         ;
    5635 EUB             : 
    5636                 : /*****************************************************************************
    5637                 :  *
    5638                 :  *      QUERY :
    5639                 :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5640                 :  *
    5641                 :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5642                 :  * only pro forma; but the SQL standard doesn't show one.
    5643                 :  ****************************************************************************/
    5644                 : 
    5645                 : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5646                 :                 {
    5647 GIC          43 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5648                 : 
    5649              43 :                     n->user = $5;
    5650              43 :                     n->servername = $7;
    5651              43 :                     n->missing_ok = false;
    5652              43 :                     $$ = (Node *) n;
    5653                 :                 }
    5654 ECB             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5655                 :                 {
    5656 CBC          19 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5657 ECB             : 
    5658 CBC          19 :                     n->user = $7;
    5659              19 :                     n->servername = $9;
    5660              19 :                     n->missing_ok = true;
    5661              19 :                     $$ = (Node *) n;
    5662 ECB             :                 }
    5663                 :         ;
    5664                 : 
    5665                 : /*****************************************************************************
    5666                 :  *
    5667                 :  *      QUERY :
    5668                 :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5669                 :  *
    5670                 :  ****************************************************************************/
    5671                 : 
    5672                 : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5673                 :                 {
    5674 CBC          55 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5675                 : 
    5676              55 :                     n->user = $5;
    5677              55 :                     n->servername = $7;
    5678              55 :                     n->options = $8;
    5679 GIC          55 :                     $$ = (Node *) n;
    5680                 :                 }
    5681                 :         ;
    5682 ECB             : 
    5683                 : /*****************************************************************************
    5684                 :  *
    5685                 :  *      QUERIES:
    5686                 :  *              CREATE POLICY name ON table
    5687                 :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5688                 :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5689                 :  *                  [TO role, ...]
    5690                 :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5691                 :  *              ALTER POLICY name ON table [TO role, ...]
    5692                 :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5693                 :  *
    5694                 :  *****************************************************************************/
    5695                 : 
    5696                 : CreatePolicyStmt:
    5697                 :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5698                 :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5699                 :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5700                 :                 {
    5701 CBC         314 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5702 ECB             : 
    5703 CBC         314 :                     n->policy_name = $3;
    5704             314 :                     n->table = $5;
    5705 GIC         314 :                     n->permissive = $6;
    5706             314 :                     n->cmd_name = $7;
    5707             314 :                     n->roles = $8;
    5708 CBC         314 :                     n->qual = $9;
    5709 GIC         314 :                     n->with_check = $10;
    5710 CBC         314 :                     $$ = (Node *) n;
    5711 ECB             :                 }
    5712                 :         ;
    5713                 : 
    5714                 : AlterPolicyStmt:
    5715                 :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    5716                 :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5717                 :                 {
    5718 GIC          42 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    5719 ECB             : 
    5720 CBC          42 :                     n->policy_name = $3;
    5721 GIC          42 :                     n->table = $5;
    5722              42 :                     n->roles = $6;
    5723              42 :                     n->qual = $7;
    5724              42 :                     n->with_check = $8;
    5725              42 :                     $$ = (Node *) n;
    5726                 :                 }
    5727                 :         ;
    5728                 : 
    5729                 : RowSecurityOptionalExpr:
    5730             327 :             USING '(' a_expr ')'    { $$ = $3; }
    5731              29 :             | /* EMPTY */           { $$ = NULL; }
    5732                 :         ;
    5733                 : 
    5734 ECB             : RowSecurityOptionalWithCheck:
    5735 GIC          61 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    5736 CBC         295 :             | /* EMPTY */                   { $$ = NULL; }
    5737 ECB             :         ;
    5738                 : 
    5739                 : RowSecurityDefaultToRole:
    5740 GIC          56 :             TO role_list            { $$ = $2; }
    5741             258 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    5742                 :         ;
    5743 ECB             : 
    5744                 : RowSecurityOptionalToRole:
    5745 CBC           6 :             TO role_list            { $$ = $2; }
    5746              36 :             | /* EMPTY */           { $$ = NULL; }
    5747 ECB             :         ;
    5748                 : 
    5749                 : RowSecurityDefaultPermissive:
    5750                 :             AS IDENT
    5751                 :                 {
    5752 GIC          40 :                     if (strcmp($2, "permissive") == 0)
    5753               9 :                         $$ = true;
    5754              31 :                     else if (strcmp($2, "restrictive") == 0)
    5755              28 :                         $$ = false;
    5756                 :                     else
    5757               3 :                         ereport(ERROR,
    5758                 :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    5759                 :                                  errmsg("unrecognized row security option \"%s\"", $2),
    5760                 :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    5761 ECB             :                                  parser_errposition(@2)));
    5762                 : 
    5763                 :                 }
    5764 CBC         277 :             | /* EMPTY */           { $$ = true; }
    5765 ECB             :         ;
    5766                 : 
    5767                 : RowSecurityDefaultForCmd:
    5768 GIC         151 :             FOR row_security_cmd    { $$ = $2; }
    5769             163 :             | /* EMPTY */           { $$ = "all"; }
    5770                 :         ;
    5771                 : 
    5772                 : row_security_cmd:
    5773              22 :             ALL             { $$ = "all"; }
    5774              47 :         |   SELECT          { $$ = "select"; }
    5775              22 :         |   INSERT          { $$ = "insert"; }
    5776              39 :         |   UPDATE          { $$ = "update"; }
    5777              21 :         |   DELETE_P        { $$ = "delete"; }
    5778                 :         ;
    5779                 : 
    5780                 : /*****************************************************************************
    5781                 :  *
    5782                 :  *      QUERY:
    5783                 :  *             CREATE ACCESS METHOD name HANDLER handler_name
    5784                 :  *
    5785                 :  *****************************************************************************/
    5786                 : 
    5787                 : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    5788 ECB             :                 {
    5789 GIC          30 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    5790 ECB             : 
    5791 CBC          30 :                     n->amname = $4;
    5792              30 :                     n->handler_name = $8;
    5793              30 :                     n->amtype = $6;
    5794              30 :                     $$ = (Node *) n;
    5795 ECB             :                 }
    5796                 :         ;
    5797                 : 
    5798                 : am_type:
    5799 GIC          16 :             INDEX           { $$ = AMTYPE_INDEX; }
    5800              14 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    5801                 :         ;
    5802                 : 
    5803                 : /*****************************************************************************
    5804                 :  *
    5805 ECB             :  *      QUERIES :
    5806                 :  *              CREATE TRIGGER ...
    5807                 :  *
    5808                 :  *****************************************************************************/
    5809                 : 
    5810                 : CreateTrigStmt:
    5811                 :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    5812                 :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    5813                 :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    5814                 :                 {
    5815 GIC        1488 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    5816                 : 
    5817 CBC        1488 :                     n->replace = $2;
    5818            1488 :                     n->isconstraint = false;
    5819 GIC        1488 :                     n->trigname = $4;
    5820            1488 :                     n->relation = $8;
    5821            1488 :                     n->funcname = $14;
    5822 CBC        1488 :                     n->args = $16;
    5823            1488 :                     n->row = $10;
    5824 GIC        1488 :                     n->timing = $5;
    5825            1488 :                     n->events = intVal(linitial($6));
    5826            1488 :                     n->columns = (List *) lsecond($6);
    5827 CBC        1488 :                     n->whenClause = $11;
    5828            1488 :                     n->transitionRels = $9;
    5829 GIC        1488 :                     n->deferrable = false;
    5830            1488 :                     n->initdeferred = false;
    5831            1488 :                     n->constrrel = NULL;
    5832 CBC        1488 :                     $$ = (Node *) n;
    5833 ECB             :                 }
    5834                 :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    5835                 :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    5836                 :             FOR EACH ROW TriggerWhen
    5837                 :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    5838                 :                 {
    5839 CBC          27 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    5840 ECB             : 
    5841 CBC          27 :                     n->replace = $2;
    5842              27 :                     if (n->replace) /* not supported, see CreateTrigger */
    5843 UIC           0 :                         ereport(ERROR,
    5844 ECB             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5845                 :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported")));
    5846 GIC          27 :                     n->isconstraint = true;
    5847              27 :                     n->trigname = $5;
    5848              27 :                     n->relation = $9;
    5849              27 :                     n->funcname = $18;
    5850              27 :                     n->args = $20;
    5851 CBC          27 :                     n->row = true;
    5852 GIC          27 :                     n->timing = TRIGGER_TYPE_AFTER;
    5853              27 :                     n->events = intVal(linitial($7));
    5854              27 :                     n->columns = (List *) lsecond($7);
    5855 CBC          27 :                     n->whenClause = $15;
    5856              27 :                     n->transitionRels = NIL;
    5857 GIC          27 :                     processCASbits($11, @11, "TRIGGER",
    5858                 :                                    &n->deferrable, &n->initdeferred, NULL,
    5859                 :                                    NULL, yyscanner);
    5860 CBC          27 :                     n->constrrel = $10;
    5861              27 :                     $$ = (Node *) n;
    5862 ECB             :                 }
    5863                 :         ;
    5864                 : 
    5865                 : TriggerActionTime:
    5866 GIC         668 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    5867             760 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    5868              66 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    5869                 :         ;
    5870                 : 
    5871                 : TriggerEvents:
    5872                 :             TriggerOneEvent
    5873            1521 :                 { $$ = $1; }
    5874                 :             | TriggerEvents OR TriggerOneEvent
    5875                 :                 {
    5876 CBC         514 :                     int         events1 = intVal(linitial($1));
    5877 GIC         514 :                     int         events2 = intVal(linitial($3));
    5878 CBC         514 :                     List       *columns1 = (List *) lsecond($1);
    5879             514 :                     List       *columns2 = (List *) lsecond($3);
    5880 ECB             : 
    5881 CBC         514 :                     if (events1 & events2)
    5882 GIC           3 :                         parser_yyerror("duplicate trigger events specified");
    5883                 :                     /*
    5884                 :                      * concat'ing the columns lists loses information about
    5885                 :                      * which columns went with which event, but so long as
    5886 ECB             :                      * only UPDATE carries columns and we disallow multiple
    5887                 :                      * UPDATE items, it doesn't matter.  Command execution
    5888                 :                      * should just ignore the columns for non-UPDATE events.
    5889                 :                      */
    5890 GIC         511 :                     $$ = list_make2(makeInteger(events1 | events2),
    5891                 :                                     list_concat(columns1, columns2));
    5892                 :                 }
    5893                 :         ;
    5894                 : 
    5895                 : TriggerOneEvent:
    5896                 :             INSERT
    5897             747 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    5898                 :             | DELETE_P
    5899             417 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    5900                 :             | UPDATE
    5901             805 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    5902 ECB             :             | UPDATE OF columnList
    5903 GIC          47 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    5904 ECB             :             | TRUNCATE
    5905 CBC          19 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    5906 ECB             :         ;
    5907                 : 
    5908                 : TriggerReferencing:
    5909 CBC         212 :             REFERENCING TriggerTransitions          { $$ = $2; }
    5910            1276 :             | /*EMPTY*/                             { $$ = NIL; }
    5911 ECB             :         ;
    5912                 : 
    5913                 : TriggerTransitions:
    5914 CBC         212 :             TriggerTransition                       { $$ = list_make1($1); }
    5915              69 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    5916 ECB             :         ;
    5917                 : 
    5918                 : TriggerTransition:
    5919                 :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    5920                 :                 {
    5921 GIC         281 :                     TriggerTransition *n = makeNode(TriggerTransition);
    5922                 : 
    5923             281 :                     n->name = $4;
    5924             281 :                     n->isNew = $1;
    5925             281 :                     n->isTable = $2;
    5926 CBC         281 :                     $$ = (Node *) n;
    5927                 :                 }
    5928 ECB             :         ;
    5929                 : 
    5930 EUB             : TransitionOldOrNew:
    5931 GIC         153 :             NEW                                     { $$ = true; }
    5932             128 :             | OLD                                   { $$ = false; }
    5933 ECB             :         ;
    5934                 : 
    5935                 : TransitionRowOrTable:
    5936 CBC         281 :             TABLE                                   { $$ = true; }
    5937 ECB             :             /*
    5938                 :              * According to the standard, lack of a keyword here implies ROW.
    5939                 :              * Support for that would require prohibiting ROW entirely here,
    5940                 :              * reserving the keyword ROW, and/or requiring AS (instead of
    5941                 :              * allowing it to be optional, as the standard specifies) as the
    5942                 :              * next token.  Requiring ROW seems cleanest and easiest to
    5943                 :              * explain.
    5944                 :              */
    5945 UIC           0 :             | ROW                                   { $$ = false; }
    5946                 :         ;
    5947 ECB             : 
    5948                 : TransitionRelName:
    5949 GIC         281 :             ColId                                   { $$ = $1; }
    5950                 :         ;
    5951                 : 
    5952                 : TriggerForSpec:
    5953 ECB             :             FOR TriggerForOptEach TriggerForType
    5954                 :                 {
    5955 CBC        1388 :                     $$ = $3;
    5956                 :                 }
    5957                 :             | /* EMPTY */
    5958                 :                 {
    5959                 :                     /*
    5960 ECB             :                      * If ROW/STATEMENT not specified, default to
    5961                 :                      * STATEMENT, per SQL
    5962                 :                      */
    5963 CBC         100 :                     $$ = false;
    5964 ECB             :                 }
    5965                 :         ;
    5966                 : 
    5967                 : TriggerForOptEach:
    5968                 :             EACH
    5969                 :             | /*EMPTY*/
    5970                 :         ;
    5971                 : 
    5972                 : TriggerForType:
    5973 GIC        1005 :             ROW                                     { $$ = true; }
    5974             383 :             | STATEMENT                             { $$ = false; }
    5975                 :         ;
    5976                 : 
    5977 ECB             : TriggerWhen:
    5978 GIC          76 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    5979            1439 :             | /*EMPTY*/                             { $$ = NULL; }
    5980                 :         ;
    5981                 : 
    5982                 : FUNCTION_or_PROCEDURE:
    5983                 :             FUNCTION
    5984 ECB             :         |   PROCEDURE
    5985                 :         ;
    5986                 : 
    5987                 : TriggerFuncArgs:
    5988 CBC         287 :             TriggerFuncArg                          { $$ = list_make1($1); }
    5989 GIC         132 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    5990 CBC        1228 :             | /*EMPTY*/                             { $$ = NIL; }
    5991                 :         ;
    5992 ECB             : 
    5993                 : TriggerFuncArg:
    5994                 :             Iconst
    5995                 :                 {
    5996 CBC          51 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    5997 ECB             :                 }
    5998 UIC           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    5999 GIC         348 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6000              20 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6001 ECB             :         ;
    6002                 : 
    6003                 : OptConstrFromTable:
    6004 GIC           6 :             FROM qualified_name                     { $$ = $2; }
    6005              21 :             | /*EMPTY*/                             { $$ = NULL; }
    6006                 :         ;
    6007                 : 
    6008 ECB             : ConstraintAttributeSpec:
    6009                 :             /*EMPTY*/
    6010 CBC       35772 :                 { $$ = 0; }
    6011 ECB             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6012                 :                 {
    6013                 :                     /*
    6014                 :                      * We must complain about conflicting options.
    6015                 :                      * We could, but choose not to, complain about redundant
    6016                 :                      * options (ie, where $2's bit is already set in $1).
    6017                 :                      */
    6018 CBC         456 :                     int     newspec = $1 | $2;
    6019 ECB             : 
    6020                 :                     /* special message for this case */
    6021 GIC         456 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6022               3 :                         ereport(ERROR,
    6023 ECB             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6024                 :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6025                 :                                  parser_errposition(@2)));
    6026                 :                     /* generic message for other conflicts */
    6027 GIC         453 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6028             453 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED))
    6029 UIC           0 :                         ereport(ERROR,
    6030                 :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6031                 :                                  errmsg("conflicting constraint properties"),
    6032 EUB             :                                  parser_errposition(@2)));
    6033 GIC         453 :                     $$ = newspec;
    6034                 :                 }
    6035                 :         ;
    6036 ECB             : 
    6037                 : ConstraintAttributeElem:
    6038 GIC          18 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6039              64 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6040              15 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6041              48 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6042 CBC         258 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6043 GIC          53 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6044                 :         ;
    6045                 : 
    6046                 : 
    6047                 : /*****************************************************************************
    6048                 :  *
    6049                 :  *      QUERIES :
    6050 ECB             :  *              CREATE EVENT TRIGGER ...
    6051                 :  *              ALTER EVENT TRIGGER ...
    6052                 :  *
    6053                 :  *****************************************************************************/
    6054                 : 
    6055                 : CreateEventTrigStmt:
    6056                 :             CREATE EVENT TRIGGER name ON ColLabel
    6057                 :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6058                 :                 {
    6059 GIC          41 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6060 ECB             : 
    6061 CBC          41 :                     n->trigname = $4;
    6062 GIC          41 :                     n->eventname = $6;
    6063              41 :                     n->whenclause = NULL;
    6064              41 :                     n->funcname = $9;
    6065 CBC          41 :                     $$ = (Node *) n;
    6066 ECB             :                 }
    6067                 :           | CREATE EVENT TRIGGER name ON ColLabel
    6068                 :             WHEN event_trigger_when_list
    6069                 :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6070                 :                 {
    6071 GIC          39 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6072                 : 
    6073              39 :                     n->trigname = $4;
    6074              39 :                     n->eventname = $6;
    6075 CBC          39 :                     n->whenclause = $8;
    6076              39 :                     n->funcname = $11;
    6077              39 :                     $$ = (Node *) n;
    6078                 :                 }
    6079                 :         ;
    6080                 : 
    6081                 : event_trigger_when_list:
    6082                 :           event_trigger_when_item
    6083              39 :             { $$ = list_make1($1); }
    6084                 :         | event_trigger_when_list AND event_trigger_when_item
    6085 GBC           3 :             { $$ = lappend($1, $3); }
    6086 ECB             :         ;
    6087                 : 
    6088                 : event_trigger_when_item:
    6089                 :         ColId IN_P '(' event_trigger_value_list ')'
    6090 GIC          42 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6091 ECB             :         ;
    6092                 : 
    6093                 : event_trigger_value_list:
    6094                 :           SCONST
    6095 GIC          42 :             { $$ = list_make1(makeString($1)); }
    6096                 :         | event_trigger_value_list ',' SCONST
    6097 CBC          33 :             { $$ = lappend($1, makeString($3)); }
    6098                 :         ;
    6099                 : 
    6100                 : AlterEventTrigStmt:
    6101                 :             ALTER EVENT TRIGGER name enable_trigger
    6102                 :                 {
    6103 GIC          16 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6104                 : 
    6105 CBC          16 :                     n->trigname = $4;
    6106 GIC          16 :                     n->tgenabled = $5;
    6107              16 :                     $$ = (Node *) n;
    6108 ECB             :                 }
    6109                 :         ;
    6110                 : 
    6111                 : enable_trigger:
    6112 GIC           3 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6113               3 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6114 CBC           3 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6115               7 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6116 EUB             :         ;
    6117                 : 
    6118                 : /*****************************************************************************
    6119                 :  *
    6120 ECB             :  *      QUERY :
    6121                 :  *              CREATE ASSERTION ...
    6122                 :  *
    6123                 :  *****************************************************************************/
    6124                 : 
    6125                 : CreateAssertionStmt:
    6126                 :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6127                 :                 {
    6128 LBC           0 :                     ereport(ERROR,
    6129 ECB             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6130                 :                              errmsg("CREATE ASSERTION is not yet implemented")));
    6131                 : 
    6132                 :                     $$ = NULL;
    6133                 :                 }
    6134                 :         ;
    6135                 : 
    6136                 : 
    6137                 : /*****************************************************************************
    6138                 :  *
    6139                 :  *      QUERY :
    6140                 :  *              define (aggregate,operator,type)
    6141                 :  *
    6142                 :  *****************************************************************************/
    6143                 : 
    6144                 : DefineStmt:
    6145                 :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6146                 :                 {
    6147 GIC         268 :                     DefineStmt *n = makeNode(DefineStmt);
    6148 ECB             : 
    6149 CBC         268 :                     n->kind = OBJECT_AGGREGATE;
    6150             268 :                     n->oldstyle = false;
    6151             268 :                     n->replace = $2;
    6152             268 :                     n->defnames = $4;
    6153 GIC         268 :                     n->args = $5;
    6154             268 :                     n->definition = $6;
    6155             268 :                     $$ = (Node *) n;
    6156                 :                 }
    6157                 :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6158 ECB             :                 {
    6159                 :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6160 CBC         181 :                     DefineStmt *n = makeNode(DefineStmt);
    6161 ECB             : 
    6162 CBC         181 :                     n->kind = OBJECT_AGGREGATE;
    6163             181 :                     n->oldstyle = true;
    6164             181 :                     n->replace = $2;
    6165 GIC         181 :                     n->defnames = $4;
    6166             181 :                     n->args = NIL;
    6167             181 :                     n->definition = $5;
    6168             181 :                     $$ = (Node *) n;
    6169                 :                 }
    6170 ECB             :             | CREATE OPERATOR any_operator definition
    6171                 :                 {
    6172 CBC         745 :                     DefineStmt *n = makeNode(DefineStmt);
    6173                 : 
    6174 GIC         745 :                     n->kind = OBJECT_OPERATOR;
    6175             745 :                     n->oldstyle = false;
    6176             745 :                     n->defnames = $3;
    6177 CBC         745 :                     n->args = NIL;
    6178 GIC         745 :                     n->definition = $4;
    6179             745 :                     $$ = (Node *) n;
    6180                 :                 }
    6181                 :             | CREATE TYPE_P any_name definition
    6182 ECB             :                 {
    6183 GIC         103 :                     DefineStmt *n = makeNode(DefineStmt);
    6184 ECB             : 
    6185 GIC         103 :                     n->kind = OBJECT_TYPE;
    6186             103 :                     n->oldstyle = false;
    6187             103 :                     n->defnames = $3;
    6188             103 :                     n->args = NIL;
    6189             103 :                     n->definition = $4;
    6190 CBC         103 :                     $$ = (Node *) n;
    6191                 :                 }
    6192 ECB             :             | CREATE TYPE_P any_name
    6193                 :                 {
    6194                 :                     /* Shell type (identified by lack of definition) */
    6195 GIC          77 :                     DefineStmt *n = makeNode(DefineStmt);
    6196                 : 
    6197              77 :                     n->kind = OBJECT_TYPE;
    6198              77 :                     n->oldstyle = false;
    6199 CBC          77 :                     n->defnames = $3;
    6200              77 :                     n->args = NIL;
    6201              77 :                     n->definition = NIL;
    6202              77 :                     $$ = (Node *) n;
    6203                 :                 }
    6204                 :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6205                 :                 {
    6206 GIC         315 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6207                 : 
    6208                 :                     /* can't use qualified_name, sigh */
    6209             315 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6210             315 :                     n->coldeflist = $6;
    6211             315 :                     $$ = (Node *) n;
    6212                 :                 }
    6213                 :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6214                 :                 {
    6215 GBC          90 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6216                 : 
    6217 GIC          90 :                     n->typeName = $3;
    6218              90 :                     n->vals = $7;
    6219              90 :                     $$ = (Node *) n;
    6220                 :                 }
    6221                 :             | CREATE TYPE_P any_name AS RANGE definition
    6222                 :                 {
    6223              76 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6224                 : 
    6225              76 :                     n->typeName = $3;
    6226              76 :                     n->params = $6;
    6227              76 :                     $$ = (Node *) n;
    6228                 :                 }
    6229                 :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6230                 :                 {
    6231              20 :                     DefineStmt *n = makeNode(DefineStmt);
    6232                 : 
    6233              20 :                     n->kind = OBJECT_TSPARSER;
    6234 CBC          20 :                     n->args = NIL;
    6235 GIC          20 :                     n->defnames = $5;
    6236 CBC          20 :                     n->definition = $6;
    6237              20 :                     $$ = (Node *) n;
    6238 ECB             :                 }
    6239                 :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6240                 :                 {
    6241 CBC        8557 :                     DefineStmt *n = makeNode(DefineStmt);
    6242 ECB             : 
    6243 GIC        8557 :                     n->kind = OBJECT_TSDICTIONARY;
    6244            8557 :                     n->args = NIL;
    6245            8557 :                     n->defnames = $5;
    6246            8557 :                     n->definition = $6;
    6247 CBC        8557 :                     $$ = (Node *) n;
    6248                 :                 }
    6249 ECB             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6250                 :                 {
    6251 CBC         325 :                     DefineStmt *n = makeNode(DefineStmt);
    6252 ECB             : 
    6253 CBC         325 :                     n->kind = OBJECT_TSTEMPLATE;
    6254             325 :                     n->args = NIL;
    6255             325 :                     n->defnames = $5;
    6256 GIC         325 :                     n->definition = $6;
    6257             325 :                     $$ = (Node *) n;
    6258                 :                 }
    6259 ECB             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6260                 :                 {
    6261 CBC        8525 :                     DefineStmt *n = makeNode(DefineStmt);
    6262 ECB             : 
    6263 CBC        8525 :                     n->kind = OBJECT_TSCONFIGURATION;
    6264            8525 :                     n->args = NIL;
    6265            8525 :                     n->defnames = $5;
    6266            8525 :                     n->definition = $6;
    6267 GIC        8525 :                     $$ = (Node *) n;
    6268                 :                 }
    6269                 :             | CREATE COLLATION any_name definition
    6270 ECB             :                 {
    6271 GIC         132 :                     DefineStmt *n = makeNode(DefineStmt);
    6272 ECB             : 
    6273 CBC         132 :                     n->kind = OBJECT_COLLATION;
    6274             132 :                     n->args = NIL;
    6275             132 :                     n->defnames = $3;
    6276             132 :                     n->definition = $4;
    6277             132 :                     $$ = (Node *) n;
    6278                 :                 }
    6279                 :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6280                 :                 {
    6281 GIC          12 :                     DefineStmt *n = makeNode(DefineStmt);
    6282 ECB             : 
    6283 GIC          12 :                     n->kind = OBJECT_COLLATION;
    6284 CBC          12 :                     n->args = NIL;
    6285              12 :                     n->defnames = $6;
    6286              12 :                     n->definition = $7;
    6287              12 :                     n->if_not_exists = true;
    6288              12 :                     $$ = (Node *) n;
    6289 ECB             :                 }
    6290                 :             | CREATE COLLATION any_name FROM any_name
    6291                 :                 {
    6292 GIC          38 :                     DefineStmt *n = makeNode(DefineStmt);
    6293 ECB             : 
    6294 GIC          38 :                     n->kind = OBJECT_COLLATION;
    6295              38 :                     n->args = NIL;
    6296 CBC          38 :                     n->defnames = $3;
    6297              38 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6298              38 :                     $$ = (Node *) n;
    6299                 :                 }
    6300                 :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6301                 :                 {
    6302               3 :                     DefineStmt *n = makeNode(DefineStmt);
    6303                 : 
    6304               3 :                     n->kind = OBJECT_COLLATION;
    6305               3 :                     n->args = NIL;
    6306               3 :                     n->defnames = $6;
    6307 GIC           3 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6308               3 :                     n->if_not_exists = true;
    6309               3 :                     $$ = (Node *) n;
    6310 ECB             :                 }
    6311                 :         ;
    6312                 : 
    6313 CBC       19176 : definition: '(' def_list ')'                        { $$ = $2; }
    6314 ECB             :         ;
    6315                 : 
    6316 GIC       19176 : def_list:   def_elem                                { $$ = list_make1($1); }
    6317           18203 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6318 ECB             :         ;
    6319                 : 
    6320                 : def_elem:   ColLabel '=' def_arg
    6321                 :                 {
    6322 CBC       37218 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6323 ECB             :                 }
    6324                 :             | ColLabel
    6325                 :                 {
    6326 GIC         161 :                     $$ = makeDefElem($1, NULL, @1);
    6327                 :                 }
    6328 ECB             :         ;
    6329                 : 
    6330                 : /* Note: any simple identifier will be returned as a type name! */
    6331 CBC       27931 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6332            9026 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6333             572 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6334             593 :             | NumericOnly                   { $$ = (Node *) $1; }
    6335 GIC         888 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6336              64 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6337                 :         ;
    6338 ECB             : 
    6339 GIC         181 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6340 ECB             :         ;
    6341                 : 
    6342 CBC         181 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6343             646 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6344 ECB             :         ;
    6345                 : 
    6346                 : /*
    6347                 :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6348                 :  * the item names needed in old aggregate definitions are likely to become
    6349                 :  * SQL keywords.
    6350                 :  */
    6351                 : old_aggr_elem:  IDENT '=' def_arg
    6352                 :                 {
    6353 CBC         827 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6354 ECB             :                 }
    6355                 :         ;
    6356                 : 
    6357                 : opt_enum_val_list:
    6358 CBC          87 :         enum_val_list                           { $$ = $1; }
    6359 GIC           3 :         | /*EMPTY*/                             { $$ = NIL; }
    6360 ECB             :         ;
    6361                 : 
    6362                 : enum_val_list:  Sconst
    6363 CBC          87 :                 { $$ = list_make1(makeString($1)); }
    6364 ECB             :             | enum_val_list ',' Sconst
    6365 GIC        5182 :                 { $$ = lappend($1, makeString($3)); }
    6366                 :         ;
    6367                 : 
    6368 ECB             : /*****************************************************************************
    6369                 :  *
    6370                 :  *  ALTER TYPE enumtype ADD ...
    6371                 :  *
    6372                 :  *****************************************************************************/
    6373                 : 
    6374                 : AlterEnumStmt:
    6375                 :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6376                 :             {
    6377 GIC          71 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6378                 : 
    6379 CBC          71 :                 n->typeName = $3;
    6380 GIC          71 :                 n->oldVal = NULL;
    6381 CBC          71 :                 n->newVal = $7;
    6382              71 :                 n->newValNeighbor = NULL;
    6383              71 :                 n->newValIsAfter = true;
    6384              71 :                 n->skipIfNewValExists = $6;
    6385              71 :                 $$ = (Node *) n;
    6386                 :             }
    6387                 :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6388                 :             {
    6389              97 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6390                 : 
    6391              97 :                 n->typeName = $3;
    6392              97 :                 n->oldVal = NULL;
    6393              97 :                 n->newVal = $7;
    6394              97 :                 n->newValNeighbor = $9;
    6395              97 :                 n->newValIsAfter = false;
    6396              97 :                 n->skipIfNewValExists = $6;
    6397 GIC          97 :                 $$ = (Node *) n;
    6398                 :             }
    6399                 :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6400 ECB             :             {
    6401 GIC          11 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6402                 : 
    6403 CBC          11 :                 n->typeName = $3;
    6404              11 :                 n->oldVal = NULL;
    6405 GIC          11 :                 n->newVal = $7;
    6406              11 :                 n->newValNeighbor = $9;
    6407              11 :                 n->newValIsAfter = true;
    6408              11 :                 n->skipIfNewValExists = $6;
    6409 CBC          11 :                 $$ = (Node *) n;
    6410                 :             }
    6411                 :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6412                 :             {
    6413              12 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6414                 : 
    6415 GIC          12 :                 n->typeName = $3;
    6416              12 :                 n->oldVal = $6;
    6417              12 :                 n->newVal = $8;
    6418 CBC          12 :                 n->newValNeighbor = NULL;
    6419              12 :                 n->newValIsAfter = false;
    6420              12 :                 n->skipIfNewValExists = false;
    6421              12 :                 $$ = (Node *) n;
    6422 ECB             :             }
    6423                 :          ;
    6424                 : 
    6425 GIC           6 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6426 CBC         173 :         | /* EMPTY */                          { $$ = false; }
    6427                 :         ;
    6428                 : 
    6429 ECB             : 
    6430                 : /*****************************************************************************
    6431                 :  *
    6432                 :  *      QUERIES :
    6433                 :  *              CREATE OPERATOR CLASS ...
    6434                 :  *              CREATE OPERATOR FAMILY ...
    6435                 :  *              ALTER OPERATOR FAMILY ...
    6436                 :  *              DROP OPERATOR CLASS ...
    6437                 :  *              DROP OPERATOR FAMILY ...
    6438                 :  *
    6439                 :  *****************************************************************************/
    6440                 : 
    6441                 : CreateOpClassStmt:
    6442                 :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6443                 :             USING name opt_opfamily AS opclass_item_list
    6444                 :                 {
    6445 CBC         183 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6446 ECB             : 
    6447 GIC         183 :                     n->opclassname = $4;
    6448             183 :                     n->isDefault = $5;
    6449             183 :                     n->datatype = $8;
    6450 CBC         183 :                     n->amname = $10;
    6451 GIC         183 :                     n->opfamilyname = $11;
    6452 CBC         183 :                     n->items = $13;
    6453 GIC         183 :                     $$ = (Node *) n;
    6454                 :                 }
    6455                 :         ;
    6456                 : 
    6457                 : opclass_item_list:
    6458             376 :             opclass_item                            { $$ = list_make1($1); }
    6459            1484 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6460                 :         ;
    6461                 : 
    6462                 : opclass_item:
    6463                 :             OPERATOR Iconst any_operator opclass_purpose opt_recheck
    6464 ECB             :                 {
    6465 GIC         529 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6466 CBC         529 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6467 ECB             : 
    6468 CBC         529 :                     owa->objname = $3;
    6469             529 :                     owa->objargs = NIL;
    6470             529 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6471             529 :                     n->name = owa;
    6472             529 :                     n->number = $2;
    6473 GIC         529 :                     n->order_family = $4;
    6474             529 :                     $$ = (Node *) n;
    6475                 :                 }
    6476 ECB             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6477                 :               opt_recheck
    6478                 :                 {
    6479 CBC         493 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6480 ECB             : 
    6481 CBC         493 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6482             493 :                     n->name = $3;
    6483             493 :                     n->number = $2;
    6484             493 :                     n->order_family = $4;
    6485 GIC         493 :                     $$ = (Node *) n;
    6486                 :                 }
    6487                 :             | FUNCTION Iconst function_with_argtypes
    6488 ECB             :                 {
    6489 GIC         671 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6490 ECB             : 
    6491 CBC         671 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6492             671 :                     n->name = $3;
    6493             671 :                     n->number = $2;
    6494             671 :                     $$ = (Node *) n;
    6495 ECB             :                 }
    6496                 :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6497                 :                 {
    6498 GIC          68 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6499                 : 
    6500 CBC          68 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6501 GIC          68 :                     n->name = $6;
    6502 CBC          68 :                     n->number = $2;
    6503              68 :                     n->class_args = $4;
    6504              68 :                     $$ = (Node *) n;
    6505 ECB             :                 }
    6506                 :             | STORAGE Typename
    6507                 :                 {
    6508 CBC          99 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6509                 : 
    6510 GIC          99 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6511              99 :                     n->storedtype = $2;
    6512 CBC          99 :                     $$ = (Node *) n;
    6513 ECB             :                 }
    6514                 :         ;
    6515                 : 
    6516 GIC         141 : opt_default:    DEFAULT                     { $$ = true; }
    6517              74 :             | /*EMPTY*/                     { $$ = false; }
    6518                 :         ;
    6519                 : 
    6520              22 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6521             161 :             | /*EMPTY*/                     { $$ = NIL; }
    6522                 :         ;
    6523                 : 
    6524 UIC           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6525 GIC          36 :             | FOR ORDER BY any_name         { $$ = $4; }
    6526             986 :             | /*EMPTY*/                     { $$ = NIL; }
    6527                 :         ;
    6528                 : 
    6529                 : opt_recheck:    RECHECK
    6530                 :                 {
    6531                 :                     /*
    6532 ECB             :                      * RECHECK no longer does anything in opclass definitions,
    6533                 :                      * but we still accept it to ease porting of old database
    6534                 :                      * dumps.
    6535                 :                      */
    6536 LBC           0 :                     ereport(NOTICE,
    6537 ECB             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6538                 :                              errmsg("RECHECK is no longer required"),
    6539                 :                              errhint("Update your data type."),
    6540                 :                              parser_errposition(@1)));
    6541 UIC           0 :                     $$ = true;
    6542                 :                 }
    6543 GIC        1022 :             | /*EMPTY*/                     { $$ = false; }
    6544                 :         ;
    6545 ECB             : 
    6546                 : 
    6547                 : CreateOpFamilyStmt:
    6548                 :             CREATE OPERATOR FAMILY any_name USING name
    6549                 :                 {
    6550 GIC          74 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6551                 : 
    6552 CBC          74 :                     n->opfamilyname = $4;
    6553              74 :                     n->amname = $6;
    6554 GIC          74 :                     $$ = (Node *) n;
    6555 ECB             :                 }
    6556                 :         ;
    6557                 : 
    6558                 : AlterOpFamilyStmt:
    6559                 :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6560                 :                 {
    6561 CBC         193 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6562                 : 
    6563 GIC         193 :                     n->opfamilyname = $4;
    6564             193 :                     n->amname = $6;
    6565             193 :                     n->isDrop = false;
    6566 CBC         193 :                     n->items = $8;
    6567 GIC         193 :                     $$ = (Node *) n;
    6568 ECB             :                 }
    6569                 :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6570                 :                 {
    6571 CBC          30 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6572 ECB             : 
    6573 GIC          30 :                     n->opfamilyname = $4;
    6574              30 :                     n->amname = $6;
    6575              30 :                     n->isDrop = true;
    6576 CBC          30 :                     n->items = $8;
    6577 GIC          30 :                     $$ = (Node *) n;
    6578 ECB             :                 }
    6579                 :         ;
    6580                 : 
    6581                 : opclass_drop_list:
    6582 GIC          30 :             opclass_drop                            { $$ = list_make1($1); }
    6583              15 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6584                 :         ;
    6585 ECB             : 
    6586                 : opclass_drop:
    6587                 :             OPERATOR Iconst '(' type_list ')'
    6588                 :                 {
    6589 CBC          28 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6590 ECB             : 
    6591 CBC          28 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6592 GIC          28 :                     n->number = $2;
    6593              28 :                     n->class_args = $4;
    6594              28 :                     $$ = (Node *) n;
    6595 ECB             :                 }
    6596                 :             | FUNCTION Iconst '(' type_list ')'
    6597                 :                 {
    6598 CBC          17 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6599 ECB             : 
    6600 GIC          17 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6601              17 :                     n->number = $2;
    6602              17 :                     n->class_args = $4;
    6603 CBC          17 :                     $$ = (Node *) n;
    6604 ECB             :                 }
    6605                 :         ;
    6606                 : 
    6607                 : 
    6608                 : DropOpClassStmt:
    6609                 :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6610                 :                 {
    6611 GBC          19 :                     DropStmt *n = makeNode(DropStmt);
    6612 ECB             : 
    6613 CBC          19 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6614 GIC          19 :                     n->removeType = OBJECT_OPCLASS;
    6615              19 :                     n->behavior = $7;
    6616              19 :                     n->missing_ok = false;
    6617              19 :                     n->concurrent = false;
    6618              19 :                     $$ = (Node *) n;
    6619                 :                 }
    6620                 :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6621                 :                 {
    6622               9 :                     DropStmt *n = makeNode(DropStmt);
    6623 EUB             : 
    6624 GIC           9 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6625               9 :                     n->removeType = OBJECT_OPCLASS;
    6626               9 :                     n->behavior = $9;
    6627               9 :                     n->missing_ok = true;
    6628 GBC           9 :                     n->concurrent = false;
    6629 GIC           9 :                     $$ = (Node *) n;
    6630 ECB             :                 }
    6631                 :         ;
    6632                 : 
    6633                 : DropOpFamilyStmt:
    6634                 :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6635                 :                 {
    6636 GIC          55 :                     DropStmt *n = makeNode(DropStmt);
    6637 ECB             : 
    6638 GIC          55 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6639 CBC          55 :                     n->removeType = OBJECT_OPFAMILY;
    6640              55 :                     n->behavior = $7;
    6641              55 :                     n->missing_ok = false;
    6642 GIC          55 :                     n->concurrent = false;
    6643              55 :                     $$ = (Node *) n;
    6644                 :                 }
    6645                 :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6646                 :                 {
    6647               9 :                     DropStmt *n = makeNode(DropStmt);
    6648 ECB             : 
    6649 GIC           9 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6650 CBC           9 :                     n->removeType = OBJECT_OPFAMILY;
    6651               9 :                     n->behavior = $9;
    6652               9 :                     n->missing_ok = true;
    6653               9 :                     n->concurrent = false;
    6654               9 :                     $$ = (Node *) n;
    6655                 :                 }
    6656                 :         ;
    6657                 : 
    6658 ECB             : 
    6659                 : /*****************************************************************************
    6660                 :  *
    6661                 :  *      QUERY:
    6662                 :  *
    6663                 :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6664                 :  *      REASSIGN OWNED BY username [, username ...] TO username
    6665                 :  *
    6666                 :  *****************************************************************************/
    6667                 : DropOwnedStmt:
    6668                 :             DROP OWNED BY role_list opt_drop_behavior
    6669                 :                 {
    6670 CBC          69 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    6671                 : 
    6672 GIC          69 :                     n->roles = $4;
    6673              69 :                     n->behavior = $5;
    6674              69 :                     $$ = (Node *) n;
    6675                 :                 }
    6676 ECB             :         ;
    6677                 : 
    6678                 : ReassignOwnedStmt:
    6679                 :             REASSIGN OWNED BY role_list TO RoleSpec
    6680                 :                 {
    6681 CBC          19 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    6682                 : 
    6683 GIC          19 :                     n->roles = $4;
    6684              19 :                     n->newrole = $6;
    6685 CBC          19 :                     $$ = (Node *) n;
    6686                 :                 }
    6687 ECB             :         ;
    6688                 : 
    6689                 : /*****************************************************************************
    6690                 :  *
    6691                 :  *      QUERY:
    6692                 :  *
    6693                 :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    6694                 :  *           [ RESTRICT | CASCADE ]
    6695                 :  *
    6696                 :  *****************************************************************************/
    6697                 : 
    6698                 : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    6699                 :                 {
    6700 CBC         609 :                     DropStmt *n = makeNode(DropStmt);
    6701 ECB             : 
    6702 CBC         609 :                     n->removeType = $2;
    6703             609 :                     n->missing_ok = true;
    6704             609 :                     n->objects = $5;
    6705             609 :                     n->behavior = $6;
    6706 GIC         609 :                     n->concurrent = false;
    6707             609 :                     $$ = (Node *) n;
    6708                 :                 }
    6709 ECB             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    6710                 :                 {
    6711 CBC        6997 :                     DropStmt *n = makeNode(DropStmt);
    6712 ECB             : 
    6713 CBC        6997 :                     n->removeType = $2;
    6714            6997 :                     n->missing_ok = false;
    6715            6997 :                     n->objects = $3;
    6716            6997 :                     n->behavior = $4;
    6717 GIC        6997 :                     n->concurrent = false;
    6718            6997 :                     $$ = (Node *) n;
    6719                 :                 }
    6720                 :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    6721                 :                 {
    6722              39 :                     DropStmt *n = makeNode(DropStmt);
    6723 ECB             : 
    6724 GIC          39 :                     n->removeType = $2;
    6725 CBC          39 :                     n->missing_ok = true;
    6726              39 :                     n->objects = $5;
    6727              39 :                     n->behavior = $6;
    6728              39 :                     n->concurrent = false;
    6729              39 :                     $$ = (Node *) n;
    6730 ECB             :                 }
    6731                 :             | DROP drop_type_name name_list opt_drop_behavior
    6732                 :                 {
    6733 GIC         574 :                     DropStmt *n = makeNode(DropStmt);
    6734 ECB             : 
    6735 GIC         574 :                     n->removeType = $2;
    6736 CBC         574 :                     n->missing_ok = false;
    6737             574 :                     n->objects = $3;
    6738             574 :                     n->behavior = $4;
    6739             574 :                     n->concurrent = false;
    6740             574 :                     $$ = (Node *) n;
    6741 ECB             :                 }
    6742                 :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    6743                 :                 {
    6744 GIC         521 :                     DropStmt *n = makeNode(DropStmt);
    6745                 : 
    6746             521 :                     n->removeType = $2;
    6747             521 :                     n->objects = list_make1(lappend($5, makeString($3)));
    6748             521 :                     n->behavior = $6;
    6749             521 :                     n->missing_ok = false;
    6750             521 :                     n->concurrent = false;
    6751             521 :                     $$ = (Node *) n;
    6752                 :                 }
    6753                 :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    6754                 :                 {
    6755              24 :                     DropStmt *n = makeNode(DropStmt);
    6756                 : 
    6757 CBC          24 :                     n->removeType = $2;
    6758 GIC          24 :                     n->objects = list_make1(lappend($7, makeString($5)));
    6759 CBC          24 :                     n->behavior = $8;
    6760              24 :                     n->missing_ok = true;
    6761              24 :                     n->concurrent = false;
    6762 GIC          24 :                     $$ = (Node *) n;
    6763                 :                 }
    6764                 :             | DROP TYPE_P type_name_list opt_drop_behavior
    6765                 :                 {
    6766             253 :                     DropStmt *n = makeNode(DropStmt);
    6767                 : 
    6768 CBC         253 :                     n->removeType = OBJECT_TYPE;
    6769 GIC         253 :                     n->missing_ok = false;
    6770 CBC         253 :                     n->objects = $3;
    6771             253 :                     n->behavior = $4;
    6772             253 :                     n->concurrent = false;
    6773 GIC         253 :                     $$ = (Node *) n;
    6774                 :                 }
    6775                 :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    6776                 :                 {
    6777              11 :                     DropStmt *n = makeNode(DropStmt);
    6778                 : 
    6779              11 :                     n->removeType = OBJECT_TYPE;
    6780              11 :                     n->missing_ok = true;
    6781              11 :                     n->objects = $5;
    6782              11 :                     n->behavior = $6;
    6783              11 :                     n->concurrent = false;
    6784              11 :                     $$ = (Node *) n;
    6785                 :                 }
    6786                 :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    6787 ECB             :                 {
    6788 GIC         178 :                     DropStmt *n = makeNode(DropStmt);
    6789 ECB             : 
    6790 CBC         178 :                     n->removeType = OBJECT_DOMAIN;
    6791             178 :                     n->missing_ok = false;
    6792             178 :                     n->objects = $3;
    6793             178 :                     n->behavior = $4;
    6794             178 :                     n->concurrent = false;
    6795 GIC         178 :                     $$ = (Node *) n;
    6796                 :                 }
    6797                 :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    6798 ECB             :                 {
    6799 GIC           9 :                     DropStmt *n = makeNode(DropStmt);
    6800 ECB             : 
    6801 CBC           9 :                     n->removeType = OBJECT_DOMAIN;
    6802               9 :                     n->missing_ok = true;
    6803               9 :                     n->objects = $5;
    6804               9 :                     n->behavior = $6;
    6805               9 :                     n->concurrent = false;
    6806 GIC           9 :                     $$ = (Node *) n;
    6807                 :                 }
    6808                 :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    6809 ECB             :                 {
    6810 GIC          67 :                     DropStmt *n = makeNode(DropStmt);
    6811 ECB             : 
    6812 CBC          67 :                     n->removeType = OBJECT_INDEX;
    6813              67 :                     n->missing_ok = false;
    6814              67 :                     n->objects = $4;
    6815              67 :                     n->behavior = $5;
    6816              67 :                     n->concurrent = true;
    6817 GIC          67 :                     $$ = (Node *) n;
    6818                 :                 }
    6819                 :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    6820 ECB             :                 {
    6821 GIC           6 :                     DropStmt *n = makeNode(DropStmt);
    6822 ECB             : 
    6823 CBC           6 :                     n->removeType = OBJECT_INDEX;
    6824               6 :                     n->missing_ok = true;
    6825               6 :                     n->objects = $6;
    6826               6 :                     n->behavior = $7;
    6827               6 :                     n->concurrent = true;
    6828 GIC           6 :                     $$ = (Node *) n;
    6829                 :                 }
    6830                 :         ;
    6831 ECB             : 
    6832                 : /* object types taking any_name/any_name_list */
    6833                 : object_type_any_name:
    6834 CBC        6541 :             TABLE                                   { $$ = OBJECT_TABLE; }
    6835              97 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    6836             427 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    6837              59 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    6838             341 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    6839 GIC          85 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    6840              60 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    6841              28 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    6842 CBC          96 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    6843 GIC          10 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    6844 CBC        8499 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    6845             313 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    6846            8498 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    6847 ECB             :         ;
    6848                 : 
    6849                 : /*
    6850                 :  * object types taking name/name_list
    6851                 :  *
    6852                 :  * DROP handles some of them separately
    6853                 :  */
    6854                 : 
    6855                 : object_type_name:
    6856 CBC         353 :             drop_type_name                          { $$ = $1; }
    6857             609 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    6858              26 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    6859               5 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    6860 LBC           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    6861                 :         ;
    6862                 : 
    6863                 : drop_type_name:
    6864 CBC          23 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    6865 GIC          50 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    6866 CBC          50 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    6867              74 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    6868             332 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    6869             134 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    6870             238 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    6871              65 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    6872                 :         ;
    6873                 : 
    6874                 : /* object types attached to a table */
    6875 ECB             : object_type_name_on_any_name:
    6876 GIC          76 :             POLICY                                  { $$ = OBJECT_POLICY; }
    6877 CBC         122 :             | RULE                                  { $$ = OBJECT_RULE; }
    6878             373 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    6879 ECB             :         ;
    6880                 : 
    6881                 : any_name_list:
    6882 CBC       33271 :             any_name                                { $$ = list_make1($1); }
    6883 GIC        1782 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    6884                 :         ;
    6885                 : 
    6886 CBC      102341 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    6887 GIC        3829 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    6888 ECB             :         ;
    6889                 : 
    6890                 : attrs:      '.' attr_name
    6891 CBC       35320 :                     { $$ = list_make1(makeString($2)); }
    6892 ECB             :             | attrs '.' attr_name
    6893 CBC          24 :                     { $$ = lappend($1, makeString($3)); }
    6894                 :         ;
    6895                 : 
    6896                 : type_name_list:
    6897             451 :             Typename                                { $$ = list_make1($1); }
    6898 GIC          24 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    6899 ECB             :         ;
    6900                 : 
    6901                 : /*****************************************************************************
    6902                 :  *
    6903                 :  *      QUERY:
    6904                 :  *              truncate table relname1, relname2, ...
    6905                 :  *
    6906                 :  *****************************************************************************/
    6907                 : 
    6908                 : TruncateStmt:
    6909                 :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    6910                 :                 {
    6911 CBC         644 :                     TruncateStmt *n = makeNode(TruncateStmt);
    6912 ECB             : 
    6913 CBC         644 :                     n->relations = $3;
    6914             644 :                     n->restart_seqs = $4;
    6915             644 :                     n->behavior = $5;
    6916 GIC         644 :                     $$ = (Node *) n;
    6917                 :                 }
    6918                 :         ;
    6919                 : 
    6920                 : opt_restart_seqs:
    6921 CBC          12 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    6922              12 :             | RESTART IDENTITY_P        { $$ = true; }
    6923             620 :             | /* EMPTY */               { $$ = false; }
    6924 ECB             :         ;
    6925                 : 
    6926                 : /*****************************************************************************
    6927                 :  *
    6928                 :  * COMMENT ON <object> IS <text>
    6929                 :  *
    6930                 :  *****************************************************************************/
    6931                 : 
    6932                 : CommentStmt:
    6933                 :             COMMENT ON object_type_any_name any_name IS comment_text
    6934                 :                 {
    6935 GIC       17391 :                     CommentStmt *n = makeNode(CommentStmt);
    6936                 : 
    6937           17391 :                     n->objtype = $3;
    6938           17391 :                     n->object = (Node *) $4;
    6939           17391 :                     n->comment = $6;
    6940           17391 :                     $$ = (Node *) n;
    6941                 :                 }
    6942                 :             | COMMENT ON COLUMN any_name IS comment_text
    6943 ECB             :                 {
    6944 CBC          54 :                     CommentStmt *n = makeNode(CommentStmt);
    6945 ECB             : 
    6946 CBC          54 :                     n->objtype = OBJECT_COLUMN;
    6947 GBC          54 :                     n->object = (Node *) $4;
    6948 GIC          54 :                     n->comment = $6;
    6949              54 :                     $$ = (Node *) n;
    6950                 :                 }
    6951 ECB             :             | COMMENT ON object_type_name name IS comment_text
    6952                 :                 {
    6953 CBC         962 :                     CommentStmt *n = makeNode(CommentStmt);
    6954 ECB             : 
    6955 CBC         962 :                     n->objtype = $3;
    6956             962 :                     n->object = (Node *) makeString($4);
    6957             962 :                     n->comment = $6;
    6958             962 :                     $$ = (Node *) n;
    6959                 :                 }
    6960                 :             | COMMENT ON TYPE_P Typename IS comment_text
    6961                 :                 {
    6962 GIC          27 :                     CommentStmt *n = makeNode(CommentStmt);
    6963 ECB             : 
    6964 CBC          27 :                     n->objtype = OBJECT_TYPE;
    6965              27 :                     n->object = (Node *) $4;
    6966 GIC          27 :                     n->comment = $6;
    6967              27 :                     $$ = (Node *) n;
    6968                 :                 }
    6969 ECB             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    6970                 :                 {
    6971 GIC           4 :                     CommentStmt *n = makeNode(CommentStmt);
    6972                 : 
    6973 CBC           4 :                     n->objtype = OBJECT_DOMAIN;
    6974               4 :                     n->object = (Node *) $4;
    6975 GIC           4 :                     n->comment = $6;
    6976               4 :                     $$ = (Node *) n;
    6977                 :                 }
    6978 ECB             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    6979                 :                 {
    6980 CBC          20 :                     CommentStmt *n = makeNode(CommentStmt);
    6981                 : 
    6982 GIC          20 :                     n->objtype = OBJECT_AGGREGATE;
    6983              20 :                     n->object = (Node *) $4;
    6984 CBC          20 :                     n->comment = $6;
    6985              20 :                     $$ = (Node *) n;
    6986                 :                 }
    6987                 :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    6988                 :                 {
    6989 GIC          71 :                     CommentStmt *n = makeNode(CommentStmt);
    6990                 : 
    6991              71 :                     n->objtype = OBJECT_FUNCTION;
    6992              71 :                     n->object = (Node *) $4;
    6993              71 :                     n->comment = $6;
    6994              71 :                     $$ = (Node *) n;
    6995                 :                 }
    6996                 :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    6997                 :                 {
    6998 CBC           9 :                     CommentStmt *n = makeNode(CommentStmt);
    6999                 : 
    7000               9 :                     n->objtype = OBJECT_OPERATOR;
    7001               9 :                     n->object = (Node *) $4;
    7002               9 :                     n->comment = $6;
    7003               9 :                     $$ = (Node *) n;
    7004                 :                 }
    7005                 :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7006                 :                 {
    7007 GIC          52 :                     CommentStmt *n = makeNode(CommentStmt);
    7008 ECB             : 
    7009 CBC          52 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7010              52 :                     n->object = (Node *) lappend($6, makeString($4));
    7011 GIC          52 :                     n->comment = $8;
    7012              52 :                     $$ = (Node *) n;
    7013                 :                 }
    7014                 :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7015                 :                 {
    7016              19 :                     CommentStmt *n = makeNode(CommentStmt);
    7017                 : 
    7018              19 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7019                 :                     /*
    7020                 :                      * should use Typename not any_name in the production, but
    7021                 :                      * there's a shift/reduce conflict if we do that, so fix it
    7022 ECB             :                      * up here.
    7023                 :                      */
    7024 CBC          19 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7025              19 :                     n->comment = $9;
    7026              19 :                     $$ = (Node *) n;
    7027 ECB             :                 }
    7028                 :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7029                 :                 {
    7030 GIC          20 :                     CommentStmt *n = makeNode(CommentStmt);
    7031 ECB             : 
    7032 GIC          20 :                     n->objtype = $3;
    7033 CBC          20 :                     n->object = (Node *) lappend($6, makeString($4));
    7034              20 :                     n->comment = $8;
    7035              20 :                     $$ = (Node *) n;
    7036 ECB             :                 }
    7037                 :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7038                 :                 {
    7039 UIC           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7040 ECB             : 
    7041 UIC           0 :                     n->objtype = OBJECT_PROCEDURE;
    7042 LBC           0 :                     n->object = (Node *) $4;
    7043               0 :                     n->comment = $6;
    7044               0 :                     $$ = (Node *) n;
    7045 ECB             :                 }
    7046                 :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7047                 :                 {
    7048 UIC           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7049 ECB             : 
    7050 UIC           0 :                     n->objtype = OBJECT_ROUTINE;
    7051 LBC           0 :                     n->object = (Node *) $4;
    7052               0 :                     n->comment = $6;
    7053               0 :                     $$ = (Node *) n;
    7054 ECB             :                 }
    7055                 :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7056                 :                 {
    7057 GIC           7 :                     CommentStmt *n = makeNode(CommentStmt);
    7058 ECB             : 
    7059 GIC           7 :                     n->objtype = OBJECT_TRANSFORM;
    7060 CBC           7 :                     n->object = (Node *) list_make2($5, makeString($7));
    7061               7 :                     n->comment = $9;
    7062               7 :                     $$ = (Node *) n;
    7063 ECB             :                 }
    7064                 :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7065                 :                 {
    7066 UIC           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7067 ECB             : 
    7068 UIC           0 :                     n->objtype = OBJECT_OPCLASS;
    7069 LBC           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7070               0 :                     n->comment = $9;
    7071               0 :                     $$ = (Node *) n;
    7072 ECB             :                 }
    7073                 :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7074                 :                 {
    7075 UIC           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7076 ECB             : 
    7077 UIC           0 :                     n->objtype = OBJECT_OPFAMILY;
    7078 LBC           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7079               0 :                     n->comment = $9;
    7080               0 :                     $$ = (Node *) n;
    7081 ECB             :                 }
    7082                 :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7083                 :                 {
    7084 GIC          12 :                     CommentStmt *n = makeNode(CommentStmt);
    7085 ECB             : 
    7086 GIC          12 :                     n->objtype = OBJECT_LARGEOBJECT;
    7087 CBC          12 :                     n->object = (Node *) $5;
    7088              12 :                     n->comment = $7;
    7089              12 :                     $$ = (Node *) n;
    7090 ECB             :                 }
    7091                 :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7092                 :                 {
    7093 UIC           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7094 ECB             : 
    7095 UIC           0 :                     n->objtype = OBJECT_CAST;
    7096 LBC           0 :                     n->object = (Node *) list_make2($5, $7);
    7097               0 :                     n->comment = $10;
    7098               0 :                     $$ = (Node *) n;
    7099 ECB             :                 }
    7100                 :         ;
    7101                 : 
    7102                 : comment_text:
    7103 CBC       18599 :             Sconst                              { $$ = $1; }
    7104 GIC          49 :             | NULL_P                            { $$ = NULL; }
    7105 ECB             :         ;
    7106                 : 
    7107                 : 
    7108                 : /*****************************************************************************
    7109                 :  *
    7110                 :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7111                 :  *
    7112                 :  *  As with COMMENT ON, <object> can refer to various types of database
    7113                 :  *  objects (e.g. TABLE, COLUMN, etc.).
    7114                 :  *
    7115                 :  *****************************************************************************/
    7116                 : 
    7117                 : SecLabelStmt:
    7118                 :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7119                 :             IS security_label
    7120                 :                 {
    7121 CBC          24 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7122 ECB             : 
    7123 GIC          24 :                     n->provider = $3;
    7124              24 :                     n->objtype = $5;
    7125              24 :                     n->object = (Node *) $6;
    7126 GBC          24 :                     n->label = $8;
    7127 GIC          24 :                     $$ = (Node *) n;
    7128 EUB             :                 }
    7129                 :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7130                 :               IS security_label
    7131                 :                 {
    7132 GIC           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7133                 : 
    7134               2 :                     n->provider = $3;
    7135 GBC           2 :                     n->objtype = OBJECT_COLUMN;
    7136 GIC           2 :                     n->object = (Node *) $6;
    7137 GBC           2 :                     n->label = $8;
    7138               2 :                     $$ = (Node *) n;
    7139 EUB             :                 }
    7140                 :             | SECURITY LABEL opt_provider ON object_type_name name
    7141                 :               IS security_label
    7142                 :                 {
    7143 GIC          22 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7144 ECB             : 
    7145 GIC          22 :                     n->provider = $3;
    7146 CBC          22 :                     n->objtype = $5;
    7147              22 :                     n->object = (Node *) makeString($6);
    7148              22 :                     n->label = $8;
    7149              22 :                     $$ = (Node *) n;
    7150                 :                 }
    7151                 :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7152                 :               IS security_label
    7153 EUB             :                 {
    7154 UIC           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7155 EUB             : 
    7156 UBC           0 :                     n->provider = $3;
    7157               0 :                     n->objtype = OBJECT_TYPE;
    7158               0 :                     n->object = (Node *) $6;
    7159 UIC           0 :                     n->label = $8;
    7160               0 :                     $$ = (Node *) n;
    7161                 :                 }
    7162 EUB             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7163                 :               IS security_label
    7164                 :                 {
    7165 GBC           1 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7166 EUB             : 
    7167 GBC           1 :                     n->provider = $3;
    7168 GIC           1 :                     n->objtype = OBJECT_DOMAIN;
    7169               1 :                     n->object = (Node *) $6;
    7170               1 :                     n->label = $8;
    7171 CBC           1 :                     $$ = (Node *) n;
    7172                 :                 }
    7173 ECB             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7174                 :               IS security_label
    7175                 :                 {
    7176 LBC           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7177                 : 
    7178 UIC           0 :                     n->provider = $3;
    7179               0 :                     n->objtype = OBJECT_AGGREGATE;
    7180 UBC           0 :                     n->object = (Node *) $6;
    7181 UIC           0 :                     n->label = $8;
    7182 UBC           0 :                     $$ = (Node *) n;
    7183 EUB             :                 }
    7184                 :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7185                 :               IS security_label
    7186                 :                 {
    7187 GIC           1 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7188                 : 
    7189               1 :                     n->provider = $3;
    7190 CBC           1 :                     n->objtype = OBJECT_FUNCTION;
    7191               1 :                     n->object = (Node *) $6;
    7192 GIC           1 :                     n->label = $8;
    7193               1 :                     $$ = (Node *) n;
    7194                 :                 }
    7195                 :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7196                 :               IS security_label
    7197                 :                 {
    7198 UIC           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7199                 : 
    7200               0 :                     n->provider = $3;
    7201               0 :                     n->objtype = OBJECT_LARGEOBJECT;
    7202               0 :                     n->object = (Node *) $7;
    7203               0 :                     n->label = $9;
    7204               0 :                     $$ = (Node *) n;
    7205                 :                 }
    7206                 :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7207                 :               IS security_label
    7208 ECB             :                 {
    7209 UIC           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7210 ECB             : 
    7211 LBC           0 :                     n->provider = $3;
    7212               0 :                     n->objtype = OBJECT_PROCEDURE;
    7213               0 :                     n->object = (Node *) $6;
    7214               0 :                     n->label = $8;
    7215 UIC           0 :                     $$ = (Node *) n;
    7216                 :                 }
    7217                 :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7218                 :               IS security_label
    7219 ECB             :                 {
    7220 UIC           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7221 ECB             : 
    7222 LBC           0 :                     n->provider = $3;
    7223               0 :                     n->objtype = OBJECT_ROUTINE;
    7224               0 :                     n->object = (Node *) $6;
    7225               0 :                     n->label = $8;
    7226 UIC           0 :                     $$ = (Node *) n;
    7227                 :                 }
    7228                 :         ;
    7229                 : 
    7230 CBC          10 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7231 GIC          40 :                 | /* EMPTY */                   { $$ = NULL; }
    7232 ECB             :         ;
    7233                 : 
    7234 CBC          50 : security_label: Sconst              { $$ = $1; }
    7235 LBC           0 :                 | NULL_P            { $$ = NULL; }
    7236 ECB             :         ;
    7237                 : 
    7238                 : /*****************************************************************************
    7239                 :  *
    7240                 :  *      QUERY:
    7241 EUB             :  *          fetch/move
    7242                 :  *
    7243                 :  *****************************************************************************/
    7244                 : 
    7245                 : FetchStmt:  FETCH fetch_args
    7246                 :                 {
    7247 GBC        2792 :                     FetchStmt *n = (FetchStmt *) $2;
    7248                 : 
    7249 GIC        2792 :                     n->ismove = false;
    7250            2792 :                     $$ = (Node *) n;
    7251                 :                 }
    7252 ECB             :             | MOVE fetch_args
    7253                 :                 {
    7254 CBC          47 :                     FetchStmt *n = (FetchStmt *) $2;
    7255 ECB             : 
    7256 CBC          47 :                     n->ismove = true;
    7257              47 :                     $$ = (Node *) n;
    7258 ECB             :                 }
    7259                 :         ;
    7260                 : 
    7261                 : fetch_args: cursor_name
    7262                 :                 {
    7263 GBC          80 :                     FetchStmt *n = makeNode(FetchStmt);
    7264                 : 
    7265              80 :                     n->portalname = $1;
    7266              80 :                     n->direction = FETCH_FORWARD;
    7267              80 :                     n->howMany = 1;
    7268              80 :                     $$ = (Node *) n;
    7269 EUB             :                 }
    7270                 :             | from_in cursor_name
    7271                 :                 {
    7272 GIC          74 :                     FetchStmt *n = makeNode(FetchStmt);
    7273                 : 
    7274 CBC          74 :                     n->portalname = $2;
    7275 GIC          74 :                     n->direction = FETCH_FORWARD;
    7276 CBC          74 :                     n->howMany = 1;
    7277              74 :                     $$ = (Node *) n;
    7278 ECB             :                 }
    7279                 :             | NEXT opt_from_in cursor_name
    7280                 :                 {
    7281 GIC         127 :                     FetchStmt *n = makeNode(FetchStmt);
    7282                 : 
    7283             127 :                     n->portalname = $3;
    7284             127 :                     n->direction = FETCH_FORWARD;
    7285 GBC         127 :                     n->howMany = 1;
    7286 GIC         127 :                     $$ = (Node *) n;
    7287 EUB             :                 }
    7288                 :             | PRIOR opt_from_in cursor_name
    7289                 :                 {
    7290 GBC          15 :                     FetchStmt *n = makeNode(FetchStmt);
    7291 EUB             : 
    7292 GIC          15 :                     n->portalname = $3;
    7293              15 :                     n->direction = FETCH_BACKWARD;
    7294              15 :                     n->howMany = 1;
    7295              15 :                     $$ = (Node *) n;
    7296 EUB             :                 }
    7297                 :             | FIRST_P opt_from_in cursor_name
    7298                 :                 {
    7299 GBC          14 :                     FetchStmt *n = makeNode(FetchStmt);
    7300 EUB             : 
    7301 GBC          14 :                     n->portalname = $3;
    7302              14 :                     n->direction = FETCH_ABSOLUTE;
    7303 GIC          14 :                     n->howMany = 1;
    7304              14 :                     $$ = (Node *) n;
    7305                 :                 }
    7306                 :             | LAST_P opt_from_in cursor_name
    7307 EUB             :                 {
    7308 GIC           9 :                     FetchStmt *n = makeNode(FetchStmt);
    7309 EUB             : 
    7310 GBC           9 :                     n->portalname = $3;
    7311               9 :                     n->direction = FETCH_ABSOLUTE;
    7312               9 :                     n->howMany = -1;
    7313               9 :                     $$ = (Node *) n;
    7314                 :                 }
    7315                 :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7316                 :                 {
    7317 CBC          40 :                     FetchStmt *n = makeNode(FetchStmt);
    7318 ECB             : 
    7319 GIC          40 :                     n->portalname = $4;
    7320              40 :                     n->direction = FETCH_ABSOLUTE;
    7321 CBC          40 :                     n->howMany = $2;
    7322 GBC          40 :                     $$ = (Node *) n;
    7323                 :                 }
    7324                 :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7325                 :                 {
    7326 GIC          15 :                     FetchStmt *n = makeNode(FetchStmt);
    7327                 : 
    7328              15 :                     n->portalname = $4;
    7329              15 :                     n->direction = FETCH_RELATIVE;
    7330              15 :                     n->howMany = $2;
    7331              15 :                     $$ = (Node *) n;
    7332                 :                 }
    7333                 :             | SignedIconst opt_from_in cursor_name
    7334 ECB             :                 {
    7335 GIC        2030 :                     FetchStmt *n = makeNode(FetchStmt);
    7336 ECB             : 
    7337 CBC        2030 :                     n->portalname = $3;
    7338 GIC        2030 :                     n->direction = FETCH_FORWARD;
    7339            2030 :                     n->howMany = $1;
    7340            2030 :                     $$ = (Node *) n;
    7341 ECB             :                 }
    7342                 :             | ALL opt_from_in cursor_name
    7343                 :                 {
    7344 CBC         132 :                     FetchStmt *n = makeNode(FetchStmt);
    7345                 : 
    7346 GIC         132 :                     n->portalname = $3;
    7347             132 :                     n->direction = FETCH_FORWARD;
    7348             132 :                     n->howMany = FETCH_ALL;
    7349             132 :                     $$ = (Node *) n;
    7350 ECB             :                 }
    7351                 :             | FORWARD opt_from_in cursor_name
    7352                 :                 {
    7353 CBC           9 :                     FetchStmt *n = makeNode(FetchStmt);
    7354 ECB             : 
    7355 CBC           9 :                     n->portalname = $3;
    7356 GIC           9 :                     n->direction = FETCH_FORWARD;
    7357               9 :                     n->howMany = 1;
    7358               9 :                     $$ = (Node *) n;
    7359 ECB             :                 }
    7360                 :             | FORWARD SignedIconst opt_from_in cursor_name
    7361                 :                 {
    7362 CBC          76 :                     FetchStmt *n = makeNode(FetchStmt);
    7363 ECB             : 
    7364 CBC          76 :                     n->portalname = $4;
    7365 GIC          76 :                     n->direction = FETCH_FORWARD;
    7366              76 :                     n->howMany = $2;
    7367              76 :                     $$ = (Node *) n;
    7368 ECB             :                 }
    7369                 :             | FORWARD ALL opt_from_in cursor_name
    7370                 :                 {
    7371 CBC           7 :                     FetchStmt *n = makeNode(FetchStmt);
    7372 ECB             : 
    7373 CBC           7 :                     n->portalname = $4;
    7374 GIC           7 :                     n->direction = FETCH_FORWARD;
    7375               7 :                     n->howMany = FETCH_ALL;
    7376               7 :                     $$ = (Node *) n;
    7377 ECB             :                 }
    7378                 :             | BACKWARD opt_from_in cursor_name
    7379                 :                 {
    7380 CBC          39 :                     FetchStmt *n = makeNode(FetchStmt);
    7381 ECB             : 
    7382 CBC          39 :                     n->portalname = $3;
    7383 GIC          39 :                     n->direction = FETCH_BACKWARD;
    7384              39 :                     n->howMany = 1;
    7385              39 :                     $$ = (Node *) n;
    7386 ECB             :                 }
    7387                 :             | BACKWARD SignedIconst opt_from_in cursor_name
    7388                 :                 {
    7389 CBC         109 :                     FetchStmt *n = makeNode(FetchStmt);
    7390 ECB             : 
    7391 CBC         109 :                     n->portalname = $4;
    7392 GIC         109 :                     n->direction = FETCH_BACKWARD;
    7393             109 :                     n->howMany = $2;
    7394             109 :                     $$ = (Node *) n;
    7395 ECB             :                 }
    7396                 :             | BACKWARD ALL opt_from_in cursor_name
    7397                 :                 {
    7398 CBC          63 :                     FetchStmt *n = makeNode(FetchStmt);
    7399 ECB             : 
    7400 CBC          63 :                     n->portalname = $4;
    7401 GIC          63 :                     n->direction = FETCH_BACKWARD;
    7402              63 :                     n->howMany = FETCH_ALL;
    7403              63 :                     $$ = (Node *) n;
    7404 ECB             :                 }
    7405                 :         ;
    7406                 : 
    7407                 : from_in:    FROM
    7408                 :             | IN_P
    7409                 :         ;
    7410                 : 
    7411                 : opt_from_in:    from_in
    7412                 :             | /* EMPTY */
    7413                 :         ;
    7414                 : 
    7415                 : 
    7416                 : /*****************************************************************************
    7417                 :  *
    7418                 :  * GRANT and REVOKE statements
    7419                 :  *
    7420                 :  *****************************************************************************/
    7421                 : 
    7422                 : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7423                 :             opt_grant_grant_option opt_granted_by
    7424                 :                 {
    7425 CBC       24692 :                     GrantStmt *n = makeNode(GrantStmt);
    7426 ECB             : 
    7427 CBC       24692 :                     n->is_grant = true;
    7428 GIC       24692 :                     n->privileges = $2;
    7429           24692 :                     n->targtype = ($4)->targtype;
    7430           24692 :                     n->objtype = ($4)->objtype;
    7431 CBC       24692 :                     n->objects = ($4)->objs;
    7432 GIC       24692 :                     n->grantees = $6;
    7433 CBC       24692 :                     n->grant_option = $7;
    7434           24692 :                     n->grantor = $8;
    7435           24692 :                     $$ = (Node *) n;
    7436 ECB             :                 }
    7437                 :         ;
    7438                 : 
    7439                 : RevokeStmt:
    7440                 :             REVOKE privileges ON privilege_target
    7441                 :             FROM grantee_list opt_granted_by opt_drop_behavior
    7442                 :                 {
    7443 CBC       24123 :                     GrantStmt *n = makeNode(GrantStmt);
    7444 ECB             : 
    7445 CBC       24123 :                     n->is_grant = false;
    7446 GIC       24123 :                     n->grant_option = false;
    7447           24123 :                     n->privileges = $2;
    7448           24123 :                     n->targtype = ($4)->targtype;
    7449 CBC       24123 :                     n->objtype = ($4)->objtype;
    7450 GIC       24123 :                     n->objects = ($4)->objs;
    7451 CBC       24123 :                     n->grantees = $6;
    7452           24123 :                     n->grantor = $7;
    7453           24123 :                     n->behavior = $8;
    7454           24123 :                     $$ = (Node *) n;
    7455                 :                 }
    7456                 :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7457                 :             FROM grantee_list opt_granted_by opt_drop_behavior
    7458 ECB             :                 {
    7459 GIC           7 :                     GrantStmt *n = makeNode(GrantStmt);
    7460 ECB             : 
    7461 CBC           7 :                     n->is_grant = false;
    7462               7 :                     n->grant_option = true;
    7463               7 :                     n->privileges = $5;
    7464 GIC           7 :                     n->targtype = ($7)->targtype;
    7465               7 :                     n->objtype = ($7)->objtype;
    7466               7 :                     n->objects = ($7)->objs;
    7467 CBC           7 :                     n->grantees = $9;
    7468 GIC           7 :                     n->grantor = $10;
    7469 CBC           7 :                     n->behavior = $11;
    7470               7 :                     $$ = (Node *) n;
    7471 ECB             :                 }
    7472                 :         ;
    7473                 : 
    7474                 : 
    7475                 : /*
    7476                 :  * Privilege names are represented as strings; the validity of the privilege
    7477                 :  * names gets checked at execution.  This is a bit annoying but we have little
    7478                 :  * choice because of the syntactic conflict with lists of role names in
    7479                 :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7480                 :  * production any reserved keywords that need to be usable as privilege names.
    7481                 :  */
    7482                 : 
    7483                 : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7484                 : privileges: privilege_list
    7485 CBC       44212 :                 { $$ = $1; }
    7486                 :             | ALL
    7487            4628 :                 { $$ = NIL; }
    7488 ECB             :             | ALL PRIVILEGES
    7489 CBC          59 :                 { $$ = NIL; }
    7490 ECB             :             | ALL '(' columnList ')'
    7491                 :                 {
    7492 GIC           9 :                     AccessPriv *n = makeNode(AccessPriv);
    7493                 : 
    7494               9 :                     n->priv_name = NULL;
    7495               9 :                     n->cols = $3;
    7496               9 :                     $$ = list_make1(n);
    7497                 :                 }
    7498                 :             | ALL PRIVILEGES '(' columnList ')'
    7499                 :                 {
    7500 UIC           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7501                 : 
    7502               0 :                     n->priv_name = NULL;
    7503               0 :                     n->cols = $4;
    7504               0 :                     $$ = list_make1(n);
    7505                 :                 }
    7506                 :         ;
    7507                 : 
    7508 GIC       45406 : privilege_list: privilege                           { $$ = list_make1($1); }
    7509            1015 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7510                 :         ;
    7511                 : 
    7512 ECB             : privilege:  SELECT opt_column_list
    7513                 :             {
    7514 CBC       20430 :                 AccessPriv *n = makeNode(AccessPriv);
    7515 ECB             : 
    7516 CBC       20430 :                 n->priv_name = pstrdup($1);
    7517           20430 :                 n->cols = $2;
    7518           20430 :                 $$ = n;
    7519 ECB             :             }
    7520                 :         | REFERENCES opt_column_list
    7521                 :             {
    7522 CBC           7 :                 AccessPriv *n = makeNode(AccessPriv);
    7523                 : 
    7524 GIC           7 :                 n->priv_name = pstrdup($1);
    7525               7 :                 n->cols = $2;
    7526               7 :                 $$ = n;
    7527                 :             }
    7528                 :         | CREATE opt_column_list
    7529                 :             {
    7530 CBC         651 :                 AccessPriv *n = makeNode(AccessPriv);
    7531                 : 
    7532             651 :                 n->priv_name = pstrdup($1);
    7533             651 :                 n->cols = $2;
    7534             651 :                 $$ = n;
    7535 ECB             :             }
    7536                 :         | ALTER SYSTEM_P
    7537                 :             {
    7538 CBC          12 :                 AccessPriv *n = makeNode(AccessPriv);
    7539              12 :                 n->priv_name = pstrdup("alter system");
    7540              12 :                 n->cols = NIL;
    7541              12 :                 $$ = n;
    7542                 :             }
    7543                 :         | ColId opt_column_list
    7544                 :             {
    7545 GIC       25321 :                 AccessPriv *n = makeNode(AccessPriv);
    7546 ECB             : 
    7547 GIC       25321 :                 n->priv_name = $1;
    7548 CBC       25321 :                 n->cols = $2;
    7549           25321 :                 $$ = n;
    7550 ECB             :             }
    7551                 :         ;
    7552                 : 
    7553                 : parameter_name_list:
    7554                 :         parameter_name
    7555                 :             {
    7556 CBC          38 :                 $$ = list_make1(makeString($1));
    7557 ECB             :             }
    7558                 :         | parameter_name_list ',' parameter_name
    7559                 :             {
    7560 GIC          25 :                 $$ = lappend($1, makeString($3));
    7561                 :             }
    7562                 :         ;
    7563                 : 
    7564                 : parameter_name:
    7565                 :         ColId
    7566                 :             {
    7567              63 :                 $$ = $1;
    7568                 :             }
    7569                 :         | parameter_name '.' ColId
    7570                 :             {
    7571              16 :                 $$ = psprintf("%s.%s", $1, $3);
    7572 ECB             :             }
    7573                 :         ;
    7574                 : 
    7575                 : 
    7576                 : /* Don't bother trying to fold the first two rules into one using
    7577                 :  * opt_table.  You're going to get conflicts.
    7578                 :  */
    7579                 : privilege_target:
    7580                 :             qualified_name_list
    7581                 :                 {
    7582 CBC       24380 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7583 ECB             : 
    7584 GIC       24380 :                     n->targtype = ACL_TARGET_OBJECT;
    7585           24380 :                     n->objtype = OBJECT_TABLE;
    7586           24380 :                     n->objs = $1;
    7587 GBC       24380 :                     $$ = n;
    7588                 :                 }
    7589 EUB             :             | TABLE qualified_name_list
    7590                 :                 {
    7591 GBC         687 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7592                 : 
    7593 GIC         687 :                     n->targtype = ACL_TARGET_OBJECT;
    7594             687 :                     n->objtype = OBJECT_TABLE;
    7595 CBC         687 :                     n->objs = $2;
    7596             687 :                     $$ = n;
    7597                 :                 }
    7598                 :             | SEQUENCE qualified_name_list
    7599                 :                 {
    7600 GIC           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7601 ECB             : 
    7602 GIC           6 :                     n->targtype = ACL_TARGET_OBJECT;
    7603 CBC           6 :                     n->objtype = OBJECT_SEQUENCE;
    7604               6 :                     n->objs = $2;
    7605               6 :                     $$ = n;
    7606                 :                 }
    7607                 :             | FOREIGN DATA_P WRAPPER name_list
    7608                 :                 {
    7609              46 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7610                 : 
    7611              46 :                     n->targtype = ACL_TARGET_OBJECT;
    7612              46 :                     n->objtype = OBJECT_FDW;
    7613              46 :                     n->objs = $4;
    7614 GIC          46 :                     $$ = n;
    7615                 :                 }
    7616                 :             | FOREIGN SERVER name_list
    7617 ECB             :                 {
    7618 GIC          38 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7619 ECB             : 
    7620 CBC          38 :                     n->targtype = ACL_TARGET_OBJECT;
    7621              38 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7622 GIC          38 :                     n->objs = $3;
    7623              38 :                     $$ = n;
    7624                 :                 }
    7625 ECB             :             | FUNCTION function_with_argtypes_list
    7626                 :                 {
    7627 CBC       22165 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7628 ECB             : 
    7629 GIC       22165 :                     n->targtype = ACL_TARGET_OBJECT;
    7630           22165 :                     n->objtype = OBJECT_FUNCTION;
    7631           22165 :                     n->objs = $2;
    7632 CBC       22165 :                     $$ = n;
    7633                 :                 }
    7634 ECB             :             | PROCEDURE function_with_argtypes_list
    7635                 :                 {
    7636 CBC          18 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7637                 : 
    7638 GIC          18 :                     n->targtype = ACL_TARGET_OBJECT;
    7639              18 :                     n->objtype = OBJECT_PROCEDURE;
    7640              18 :                     n->objs = $2;
    7641              18 :                     $$ = n;
    7642                 :                 }
    7643 ECB             :             | ROUTINE function_with_argtypes_list
    7644                 :                 {
    7645 UIC           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7646                 : 
    7647 LBC           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7648 UIC           0 :                     n->objtype = OBJECT_ROUTINE;
    7649               0 :                     n->objs = $2;
    7650               0 :                     $$ = n;
    7651                 :                 }
    7652                 :             | DATABASE name_list
    7653                 :                 {
    7654 CBC         655 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7655                 : 
    7656 GIC         655 :                     n->targtype = ACL_TARGET_OBJECT;
    7657             655 :                     n->objtype = OBJECT_DATABASE;
    7658 CBC         655 :                     n->objs = $2;
    7659 GIC         655 :                     $$ = n;
    7660                 :                 }
    7661                 :             | DOMAIN_P any_name_list
    7662                 :                 {
    7663              10 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7664                 : 
    7665              10 :                     n->targtype = ACL_TARGET_OBJECT;
    7666              10 :                     n->objtype = OBJECT_DOMAIN;
    7667              10 :                     n->objs = $2;
    7668              10 :                     $$ = n;
    7669 ECB             :                 }
    7670                 :             | LANGUAGE name_list
    7671                 :                 {
    7672 CBC          21 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7673 ECB             : 
    7674 CBC          21 :                     n->targtype = ACL_TARGET_OBJECT;
    7675 GIC          21 :                     n->objtype = OBJECT_LANGUAGE;
    7676              21 :                     n->objs = $2;
    7677              21 :                     $$ = n;
    7678 ECB             :                 }
    7679                 :             | LARGE_P OBJECT_P NumericOnly_list
    7680                 :                 {
    7681 CBC          40 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7682 ECB             : 
    7683 CBC          40 :                     n->targtype = ACL_TARGET_OBJECT;
    7684 GIC          40 :                     n->objtype = OBJECT_LARGEOBJECT;
    7685              40 :                     n->objs = $3;
    7686              40 :                     $$ = n;
    7687 ECB             :                 }
    7688                 :             | PARAMETER parameter_name_list
    7689                 :                 {
    7690 CBC          38 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7691              38 :                     n->targtype = ACL_TARGET_OBJECT;
    7692              38 :                     n->objtype = OBJECT_PARAMETER_ACL;
    7693 GIC          38 :                     n->objs = $2;
    7694              38 :                     $$ = n;
    7695                 :                 }
    7696 ECB             :             | SCHEMA name_list
    7697                 :                 {
    7698 CBC         666 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7699 ECB             : 
    7700 CBC         666 :                     n->targtype = ACL_TARGET_OBJECT;
    7701             666 :                     n->objtype = OBJECT_SCHEMA;
    7702 GIC         666 :                     n->objs = $2;
    7703             666 :                     $$ = n;
    7704                 :                 }
    7705 ECB             :             | TABLESPACE name_list
    7706                 :                 {
    7707 LBC           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7708 ECB             : 
    7709 LBC           0 :                     n->targtype = ACL_TARGET_OBJECT;
    7710               0 :                     n->objtype = OBJECT_TABLESPACE;
    7711 UIC           0 :                     n->objs = $2;
    7712               0 :                     $$ = n;
    7713                 :                 }
    7714 ECB             :             | TYPE_P any_name_list
    7715                 :                 {
    7716 CBC          43 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7717 ECB             : 
    7718 CBC          43 :                     n->targtype = ACL_TARGET_OBJECT;
    7719              43 :                     n->objtype = OBJECT_TYPE;
    7720 GIC          43 :                     n->objs = $2;
    7721              43 :                     $$ = n;
    7722                 :                 }
    7723 ECB             :             | ALL TABLES IN_P SCHEMA name_list
    7724                 :                 {
    7725 CBC           6 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7726 ECB             : 
    7727 CBC           6 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7728               6 :                     n->objtype = OBJECT_TABLE;
    7729 GIC           6 :                     n->objs = $5;
    7730               6 :                     $$ = n;
    7731                 :                 }
    7732 EUB             :             | ALL SEQUENCES IN_P SCHEMA name_list
    7733                 :                 {
    7734 UBC           0 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7735 EUB             : 
    7736 UBC           0 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7737               0 :                     n->objtype = OBJECT_SEQUENCE;
    7738 UIC           0 :                     n->objs = $5;
    7739               0 :                     $$ = n;
    7740                 :                 }
    7741 ECB             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    7742                 :                 {
    7743 CBC           3 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7744 ECB             : 
    7745 CBC           3 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7746               3 :                     n->objtype = OBJECT_FUNCTION;
    7747 GIC           3 :                     n->objs = $5;
    7748               3 :                     $$ = n;
    7749                 :                 }
    7750 ECB             :             | ALL PROCEDURES IN_P SCHEMA name_list
    7751                 :                 {
    7752 CBC           3 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7753 ECB             : 
    7754 CBC           3 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7755               3 :                     n->objtype = OBJECT_PROCEDURE;
    7756 GIC           3 :                     n->objs = $5;
    7757               3 :                     $$ = n;
    7758                 :                 }
    7759 ECB             :             | ALL ROUTINES IN_P SCHEMA name_list
    7760                 :                 {
    7761 CBC           3 :                     PrivTarget *n = (PrivTarget *) palloc(sizeof(PrivTarget));
    7762 ECB             : 
    7763 CBC           3 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    7764               3 :                     n->objtype = OBJECT_ROUTINE;
    7765 GIC           3 :                     n->objs = $5;
    7766               3 :                     $$ = n;
    7767                 :                 }
    7768 ECB             :         ;
    7769                 : 
    7770                 : 
    7771                 : grantee_list:
    7772 CBC       48902 :             grantee                                 { $$ = list_make1($1); }
    7773              33 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    7774                 :         ;
    7775                 : 
    7776                 : grantee:
    7777           48923 :             RoleSpec                                { $$ = $1; }
    7778              12 :             | GROUP_P RoleSpec                      { $$ = $2; }
    7779 ECB             :         ;
    7780                 : 
    7781                 : 
    7782                 : opt_grant_grant_option:
    7783 GIC          43 :             WITH GRANT OPTION { $$ = true; }
    7784           24699 :             | /*EMPTY*/ { $$ = false; }
    7785 ECB             :         ;
    7786                 : 
    7787                 : /*****************************************************************************
    7788                 :  *
    7789                 :  * GRANT and REVOKE ROLE statements
    7790                 :  *
    7791                 :  *****************************************************************************/
    7792                 : 
    7793                 : GrantRoleStmt:
    7794                 :             GRANT privilege_list TO role_list opt_granted_by
    7795                 :                 {
    7796 GBC        1058 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7797 EUB             : 
    7798 GBC        1058 :                     n->is_grant = true;
    7799            1058 :                     n->granted_roles = $2;
    7800 GIC        1058 :                     n->grantee_roles = $4;
    7801 GNC        1058 :                     n->opt = NIL;
    7802            1058 :                     n->grantor = $5;
    7803            1058 :                     $$ = (Node *) n;
    7804                 :                 }
    7805                 :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    7806                 :                 {
    7807              57 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7808                 : 
    7809              57 :                     n->is_grant = true;
    7810              57 :                     n->granted_roles = $2;
    7811              57 :                     n->grantee_roles = $4;
    7812              57 :                     n->opt = $6;
    7813              57 :                     n->grantor = $7;
    7814 CBC          57 :                     $$ = (Node *) n;
    7815                 :                 }
    7816 ECB             :         ;
    7817                 : 
    7818                 : RevokeRoleStmt:
    7819                 :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    7820                 :                 {
    7821 GIC          46 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7822                 : 
    7823 CBC          46 :                     n->is_grant = false;
    7824 GNC          46 :                     n->opt = NIL;
    7825 CBC          46 :                     n->granted_roles = $2;
    7826              46 :                     n->grantee_roles = $4;
    7827 GNC          46 :                     n->grantor = $5;
    7828 CBC          46 :                     n->behavior = $6;
    7829              46 :                     $$ = (Node *) n;
    7830                 :                 }
    7831                 :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    7832                 :                 {
    7833 GBC          33 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    7834                 :                     DefElem *opt;
    7835                 : 
    7836 GNC          33 :                     opt = makeDefElem(pstrdup($2),
    7837              33 :                                       (Node *) makeBoolean(false), @2);
    7838 GBC          33 :                     n->is_grant = false;
    7839 GNC          33 :                     n->opt = list_make1(opt);
    7840 GBC          33 :                     n->granted_roles = $5;
    7841              33 :                     n->grantee_roles = $7;
    7842 GNC          33 :                     n->grantor = $8;
    7843 GIC          33 :                     n->behavior = $9;
    7844              33 :                     $$ = (Node *) n;
    7845                 :                 }
    7846 ECB             :         ;
    7847                 : 
    7848                 : grant_role_opt_list:
    7849 GNC          16 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    7850              57 :             | grant_role_opt                        { $$ = list_make1($1); }
    7851                 :         ;
    7852                 : 
    7853                 : grant_role_opt:
    7854                 :         ColLabel grant_role_opt_value
    7855                 :             {
    7856              73 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    7857                 :             }
    7858                 :         ;
    7859                 : 
    7860                 : grant_role_opt_value:
    7861              36 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    7862              15 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    7863              22 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    7864 ECB             :         ;
    7865                 : 
    7866 GIC          48 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    7867           49968 :             | /*EMPTY*/                                 { $$ = NULL; }
    7868                 :         ;
    7869 ECB             : 
    7870                 : /*****************************************************************************
    7871                 :  *
    7872                 :  * ALTER DEFAULT PRIVILEGES statement
    7873                 :  *
    7874                 :  *****************************************************************************/
    7875                 : 
    7876                 : AlterDefaultPrivilegesStmt:
    7877                 :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    7878                 :                 {
    7879 GIC          80 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    7880 ECB             : 
    7881 CBC          80 :                     n->options = $4;
    7882              80 :                     n->action = (GrantStmt *) $5;
    7883              80 :                     $$ = (Node *) n;
    7884                 :                 }
    7885                 :         ;
    7886                 : 
    7887                 : DefACLOptionList:
    7888 GIC          61 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    7889 CBC          80 :             | /* EMPTY */                           { $$ = NIL; }
    7890 ECB             :         ;
    7891                 : 
    7892                 : DefACLOption:
    7893                 :             IN_P SCHEMA name_list
    7894                 :                 {
    7895 CBC          27 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    7896                 :                 }
    7897                 :             | FOR ROLE role_list
    7898                 :                 {
    7899 GIC          34 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    7900 ECB             :                 }
    7901                 :             | FOR USER role_list
    7902                 :                 {
    7903 UIC           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    7904                 :                 }
    7905                 :         ;
    7906                 : 
    7907                 : /*
    7908                 :  * This should match GRANT/REVOKE, except that individual target objects
    7909                 :  * are not mentioned and we only allow a subset of object types.
    7910                 :  */
    7911                 : DefACLAction:
    7912                 :             GRANT privileges ON defacl_privilege_target TO grantee_list
    7913 ECB             :             opt_grant_grant_option
    7914                 :                 {
    7915 CBC          50 :                     GrantStmt *n = makeNode(GrantStmt);
    7916 ECB             : 
    7917 CBC          50 :                     n->is_grant = true;
    7918              50 :                     n->privileges = $2;
    7919              50 :                     n->targtype = ACL_TARGET_DEFAULTS;
    7920              50 :                     n->objtype = $4;
    7921 GIC          50 :                     n->objects = NIL;
    7922              50 :                     n->grantees = $6;
    7923              50 :                     n->grant_option = $7;
    7924 CBC          50 :                     $$ = (Node *) n;
    7925                 :                 }
    7926 ECB             :             | REVOKE privileges ON defacl_privilege_target
    7927                 :             FROM grantee_list opt_drop_behavior
    7928                 :                 {
    7929 CBC          30 :                     GrantStmt *n = makeNode(GrantStmt);
    7930 ECB             : 
    7931 CBC          30 :                     n->is_grant = false;
    7932 GIC          30 :                     n->grant_option = false;
    7933              30 :                     n->privileges = $2;
    7934              30 :                     n->targtype = ACL_TARGET_DEFAULTS;
    7935              30 :                     n->objtype = $4;
    7936              30 :                     n->objects = NIL;
    7937              30 :                     n->grantees = $6;
    7938 CBC          30 :                     n->behavior = $7;
    7939 GIC          30 :                     $$ = (Node *) n;
    7940 ECB             :                 }
    7941                 :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    7942                 :             FROM grantee_list opt_drop_behavior
    7943                 :                 {
    7944 LBC           0 :                     GrantStmt *n = makeNode(GrantStmt);
    7945 ECB             : 
    7946 LBC           0 :                     n->is_grant = false;
    7947 UIC           0 :                     n->grant_option = true;
    7948               0 :                     n->privileges = $5;
    7949               0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    7950 LBC           0 :                     n->objtype = $7;
    7951 UIC           0 :                     n->objects = NIL;
    7952               0 :                     n->grantees = $9;
    7953 LBC           0 :                     n->behavior = $10;
    7954               0 :                     $$ = (Node *) n;
    7955 ECB             :                 }
    7956                 :         ;
    7957                 : 
    7958                 : defacl_privilege_target:
    7959 CBC          39 :             TABLES          { $$ = OBJECT_TABLE; }
    7960               8 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    7961               3 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    7962 GIC           3 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    7963               9 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    7964              18 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    7965                 :         ;
    7966 ECB             : 
    7967                 : 
    7968                 : /*****************************************************************************
    7969                 :  *
    7970                 :  *      QUERY: CREATE INDEX
    7971                 :  *
    7972                 :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    7973                 :  * willing to make TABLESPACE a fully reserved word.
    7974                 :  *****************************************************************************/
    7975                 : 
    7976                 : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    7977                 :             ON relation_expr access_method_clause '(' index_params ')'
    7978                 :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    7979                 :                 {
    7980 CBC        2820 :                     IndexStmt *n = makeNode(IndexStmt);
    7981                 : 
    7982 GIC        2820 :                     n->unique = $2;
    7983 CBC        2820 :                     n->concurrent = $4;
    7984            2820 :                     n->idxname = $5;
    7985 GIC        2820 :                     n->relation = $7;
    7986            2820 :                     n->accessMethod = $8;
    7987            2820 :                     n->indexParams = $10;
    7988            2820 :                     n->indexIncludingParams = $12;
    7989            2820 :                     n->nulls_not_distinct = !$13;
    7990            2820 :                     n->options = $14;
    7991            2820 :                     n->tableSpace = $15;
    7992            2820 :                     n->whereClause = $16;
    7993            2820 :                     n->excludeOpNames = NIL;
    7994            2820 :                     n->idxcomment = NULL;
    7995            2820 :                     n->indexOid = InvalidOid;
    7996 GNC        2820 :                     n->oldNumber = InvalidRelFileNumber;
    7997 GIC        2820 :                     n->oldCreateSubid = InvalidSubTransactionId;
    7998 GNC        2820 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    7999 CBC        2820 :                     n->primary = false;
    8000            2820 :                     n->isconstraint = false;
    8001 GIC        2820 :                     n->deferrable = false;
    8002            2820 :                     n->initdeferred = false;
    8003            2820 :                     n->transformed = false;
    8004            2820 :                     n->if_not_exists = false;
    8005 CBC        2820 :                     n->reset_default_tblspc = false;
    8006            2820 :                     $$ = (Node *) n;
    8007                 :                 }
    8008                 :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8009                 :             ON relation_expr access_method_clause '(' index_params ')'
    8010                 :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8011                 :                 {
    8012               9 :                     IndexStmt *n = makeNode(IndexStmt);
    8013                 : 
    8014 GIC           9 :                     n->unique = $2;
    8015               9 :                     n->concurrent = $4;
    8016 CBC           9 :                     n->idxname = $8;
    8017 GIC           9 :                     n->relation = $10;
    8018               9 :                     n->accessMethod = $11;
    8019               9 :                     n->indexParams = $13;
    8020 GBC           9 :                     n->indexIncludingParams = $15;
    8021 GIC           9 :                     n->nulls_not_distinct = !$16;
    8022               9 :                     n->options = $17;
    8023               9 :                     n->tableSpace = $18;
    8024               9 :                     n->whereClause = $19;
    8025               9 :                     n->excludeOpNames = NIL;
    8026               9 :                     n->idxcomment = NULL;
    8027               9 :                     n->indexOid = InvalidOid;
    8028 GNC           9 :                     n->oldNumber = InvalidRelFileNumber;
    8029 GIC           9 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8030 GNC           9 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8031 GIC           9 :                     n->primary = false;
    8032 CBC           9 :                     n->isconstraint = false;
    8033 GIC           9 :                     n->deferrable = false;
    8034 CBC           9 :                     n->initdeferred = false;
    8035               9 :                     n->transformed = false;
    8036               9 :                     n->if_not_exists = true;
    8037               9 :                     n->reset_default_tblspc = false;
    8038               9 :                     $$ = (Node *) n;
    8039 ECB             :                 }
    8040                 :         ;
    8041                 : 
    8042                 : opt_unique:
    8043 GIC         528 :             UNIQUE                                  { $$ = true; }
    8044            2304 :             | /*EMPTY*/                             { $$ = false; }
    8045                 :         ;
    8046 ECB             : 
    8047                 : access_method_clause:
    8048 GIC        1273 :             USING name                              { $$ = $2; }
    8049            1632 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8050                 :         ;
    8051 EUB             : 
    8052 GIC        3457 : index_params:   index_elem                          { $$ = list_make1($1); }
    8053 GBC         918 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8054 EUB             :         ;
    8055                 : 
    8056                 : 
    8057                 : index_elem_options:
    8058                 :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8059                 :         {
    8060 GBC        4587 :             $$ = makeNode(IndexElem);
    8061            4587 :             $$->name = NULL;
    8062 GIC        4587 :             $$->expr = NULL;
    8063            4587 :             $$->indexcolname = NULL;
    8064            4587 :             $$->collation = $1;
    8065            4587 :             $$->opclass = $2;
    8066 CBC        4587 :             $$->opclassopts = NIL;
    8067            4587 :             $$->ordering = $3;
    8068            4587 :             $$->nulls_ordering = $4;
    8069 ECB             :         }
    8070                 :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8071                 :         {
    8072 GIC          66 :             $$ = makeNode(IndexElem);
    8073              66 :             $$->name = NULL;
    8074              66 :             $$->expr = NULL;
    8075              66 :             $$->indexcolname = NULL;
    8076              66 :             $$->collation = $1;
    8077              66 :             $$->opclass = $2;
    8078              66 :             $$->opclassopts = $3;
    8079              66 :             $$->ordering = $4;
    8080              66 :             $$->nulls_ordering = $5;
    8081                 :         }
    8082                 :     ;
    8083                 : 
    8084                 : /*
    8085                 :  * Index attributes can be either simple column references, or arbitrary
    8086                 :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8087 ECB             :  * an expression that's just a function call to be written without parens.
    8088                 :  */
    8089                 : index_elem: ColId index_elem_options
    8090                 :                 {
    8091 CBC        4266 :                     $$ = $2;
    8092            4266 :                     $$->name = $1;
    8093 ECB             :                 }
    8094                 :             | func_expr_windowless index_elem_options
    8095                 :                 {
    8096 CBC         164 :                     $$ = $2;
    8097             164 :                     $$->expr = $1;
    8098 ECB             :                 }
    8099                 :             | '(' a_expr ')' index_elem_options
    8100                 :                 {
    8101 CBC         223 :                     $$ = $4;
    8102             223 :                     $$->expr = $2;
    8103 ECB             :                 }
    8104                 :         ;
    8105                 : 
    8106 CBC         105 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8107            2724 :              |      /* EMPTY */                     { $$ = NIL; }
    8108 ECB             :         ;
    8109                 : 
    8110 CBC         105 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8111              82 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8112 ECB             :         ;
    8113                 : 
    8114 GIC          92 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8115            6946 :             | /*EMPTY*/                             { $$ = NIL; }
    8116                 :         ;
    8117                 : 
    8118 ECB             : 
    8119 CBC         955 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8120            1462 :             | DESC                          { $$ = SORTBY_DESC; }
    8121           43811 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8122 ECB             :         ;
    8123                 : 
    8124 CBC         135 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8125             658 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8126           45545 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8127 ECB             :         ;
    8128                 : 
    8129                 : 
    8130                 : /*****************************************************************************
    8131                 :  *
    8132                 :  *      QUERY:
    8133                 :  *              create [or replace] function <fname>
    8134                 :  *                      [(<type-1> { , <type-n>})]
    8135                 :  *                      returns <type-r>
    8136                 :  *                      as <filename or code in language as appropriate>
    8137                 :  *                      language <lang> [with parameters]
    8138                 :  *
    8139                 :  *****************************************************************************/
    8140                 : 
    8141                 : CreateFunctionStmt:
    8142                 :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8143                 :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8144                 :                 {
    8145 GIC       34962 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8146                 : 
    8147 CBC       34962 :                     n->is_procedure = false;
    8148           34962 :                     n->replace = $2;
    8149 GIC       34962 :                     n->funcname = $4;
    8150           34962 :                     n->parameters = $5;
    8151           34962 :                     n->returnType = $7;
    8152 CBC       34962 :                     n->options = $8;
    8153           34962 :                     n->sql_body = $9;
    8154 GIC       34962 :                     $$ = (Node *) n;
    8155                 :                 }
    8156 ECB             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8157                 :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8158                 :                 {
    8159 GIC          88 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8160                 : 
    8161              88 :                     n->is_procedure = false;
    8162              88 :                     n->replace = $2;
    8163              88 :                     n->funcname = $4;
    8164 CBC          88 :                     n->parameters = mergeTableFuncParameters($5, $9);
    8165              88 :                     n->returnType = TableFuncTypeName($9);
    8166              88 :                     n->returnType->location = @7;
    8167              88 :                     n->options = $11;
    8168              88 :                     n->sql_body = $12;
    8169              88 :                     $$ = (Node *) n;
    8170 ECB             :                 }
    8171                 :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8172                 :               opt_createfunc_opt_list opt_routine_body
    8173                 :                 {
    8174 GIC         229 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8175                 : 
    8176 CBC         229 :                     n->is_procedure = false;
    8177             229 :                     n->replace = $2;
    8178             229 :                     n->funcname = $4;
    8179             229 :                     n->parameters = $5;
    8180             229 :                     n->returnType = NULL;
    8181             229 :                     n->options = $6;
    8182             229 :                     n->sql_body = $7;
    8183             229 :                     $$ = (Node *) n;
    8184 ECB             :                 }
    8185                 :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8186                 :               opt_createfunc_opt_list opt_routine_body
    8187                 :                 {
    8188 GIC         151 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8189                 : 
    8190             151 :                     n->is_procedure = true;
    8191             151 :                     n->replace = $2;
    8192             151 :                     n->funcname = $4;
    8193             151 :                     n->parameters = $5;
    8194             151 :                     n->returnType = NULL;
    8195 CBC         151 :                     n->options = $6;
    8196             151 :                     n->sql_body = $7;
    8197 GIC         151 :                     $$ = (Node *) n;
    8198                 :                 }
    8199                 :         ;
    8200 ECB             : 
    8201                 : opt_or_replace:
    8202 GIC       25152 :             OR REPLACE                              { $$ = true; }
    8203           13633 :             | /*EMPTY*/                             { $$ = false; }
    8204                 :         ;
    8205 ECB             : 
    8206 CBC       14758 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8207 GIC       10588 :             | '(' ')'                               { $$ = NIL; }
    8208                 :         ;
    8209                 : 
    8210 ECB             : func_args_list:
    8211 CBC       14758 :             func_arg                                { $$ = list_make1($1); }
    8212 GIC        9924 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8213                 :         ;
    8214 ECB             : 
    8215                 : function_with_argtypes_list:
    8216 GIC       23869 :             function_with_argtypes                  { $$ = list_make1($1); }
    8217                 :             | function_with_argtypes_list ',' function_with_argtypes
    8218 CBC          33 :                                                     { $$ = lappend($1, $3); }
    8219 ECB             :         ;
    8220                 : 
    8221                 : function_with_argtypes:
    8222                 :             func_name func_args
    8223                 :                 {
    8224 CBC       25346 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8225 ECB             : 
    8226 GIC       25346 :                     n->objname = $1;
    8227           25346 :                     n->objargs = extractArgTypes($2);
    8228 CBC       25346 :                     n->objfuncargs = $2;
    8229           25346 :                     $$ = n;
    8230 ECB             :                 }
    8231                 :             /*
    8232                 :              * Because of reduce/reduce conflicts, we can't use func_name
    8233                 :              * below, but we can write it out the long way, which actually
    8234                 :              * allows more cases.
    8235                 :              */
    8236                 :             | type_func_name_keyword
    8237                 :                 {
    8238 UIC           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8239                 : 
    8240               0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8241               0 :                     n->args_unspecified = true;
    8242               0 :                     $$ = n;
    8243                 :                 }
    8244                 :             | ColId
    8245                 :                 {
    8246 GIC         136 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8247                 : 
    8248             136 :                     n->objname = list_make1(makeString($1));
    8249 CBC         136 :                     n->args_unspecified = true;
    8250 GIC         136 :                     $$ = n;
    8251 ECB             :                 }
    8252                 :             | ColId indirection
    8253                 :                 {
    8254 CBC          14 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8255 ECB             : 
    8256 CBC          14 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8257 ECB             :                                                   yyscanner);
    8258 CBC          14 :                     n->args_unspecified = true;
    8259 GIC          14 :                     $$ = n;
    8260                 :                 }
    8261                 :         ;
    8262                 : 
    8263 ECB             : /*
    8264                 :  * func_args_with_defaults is separate because we only want to accept
    8265                 :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8266                 :  */
    8267                 : func_args_with_defaults:
    8268 CBC       33230 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8269            2200 :         | '(' ')'                                   { $$ = NIL; }
    8270 ECB             :         ;
    8271                 : 
    8272                 : func_args_with_defaults_list:
    8273 CBC       33230 :         func_arg_with_default                       { $$ = list_make1($1); }
    8274                 :         | func_args_with_defaults_list ',' func_arg_with_default
    8275 GIC       57608 :                                                     { $$ = lappend($1, $3); }
    8276                 :         ;
    8277                 : 
    8278 ECB             : /*
    8279                 :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8280                 :  * param_name first; accept both since it's likely people will try both
    8281                 :  * anyway.  Don't bother trying to save productions by letting arg_class
    8282                 :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8283                 :  *
    8284                 :  * We can catch over-specified arguments here if we want to,
    8285                 :  * but for now better to silently swallow typmod, etc.
    8286                 :  * - thomas 2000-03-22
    8287                 :  */
    8288                 : func_arg:
    8289                 :             arg_class param_name func_type
    8290                 :                 {
    8291 GIC       20414 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8292 ECB             : 
    8293 GIC       20414 :                     n->name = $2;
    8294 CBC       20414 :                     n->argType = $3;
    8295           20414 :                     n->mode = $1;
    8296           20414 :                     n->defexpr = NULL;
    8297           20414 :                     $$ = n;
    8298 ECB             :                 }
    8299                 :             | param_name arg_class func_type
    8300                 :                 {
    8301 CBC         162 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8302                 : 
    8303 GIC         162 :                     n->name = $1;
    8304             162 :                     n->argType = $3;
    8305             162 :                     n->mode = $2;
    8306 CBC         162 :                     n->defexpr = NULL;
    8307             162 :                     $$ = n;
    8308                 :                 }
    8309                 :             | param_name func_type
    8310 ECB             :                 {
    8311 CBC       30544 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8312                 : 
    8313 GIC       30544 :                     n->name = $1;
    8314           30544 :                     n->argType = $2;
    8315 CBC       30544 :                     n->mode = FUNC_PARAM_DEFAULT;
    8316           30544 :                     n->defexpr = NULL;
    8317 GIC       30544 :                     $$ = n;
    8318                 :                 }
    8319                 :             | arg_class func_type
    8320 ECB             :                 {
    8321 GIC         416 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8322 ECB             : 
    8323 GIC         416 :                     n->name = NULL;
    8324             416 :                     n->argType = $2;
    8325             416 :                     n->mode = $1;
    8326             416 :                     n->defexpr = NULL;
    8327             416 :                     $$ = n;
    8328 ECB             :                 }
    8329                 :             | func_type
    8330                 :                 {
    8331 CBC       64430 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8332 ECB             : 
    8333 CBC       64430 :                     n->name = NULL;
    8334 GIC       64430 :                     n->argType = $1;
    8335           64430 :                     n->mode = FUNC_PARAM_DEFAULT;
    8336           64430 :                     n->defexpr = NULL;
    8337           64430 :                     $$ = n;
    8338                 :                 }
    8339                 :         ;
    8340                 : 
    8341                 : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8342 GBC        6618 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8343 GIC       12992 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8344 GBC          79 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8345 UBC           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8346 GBC        1303 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8347                 :         ;
    8348                 : 
    8349                 : /*
    8350 ECB             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8351                 :  */
    8352                 : param_name: type_function_name
    8353                 :         ;
    8354                 : 
    8355                 : func_return:
    8356                 :             func_type
    8357                 :                 {
    8358                 :                     /* We can catch over-specified results here if we want to,
    8359                 :                      * but for now better to silently swallow typmod, etc.
    8360                 :                      * - thomas 2000-03-22
    8361                 :                      */
    8362 CBC       34962 :                     $$ = $1;
    8363 ECB             :                 }
    8364                 :         ;
    8365                 : 
    8366                 : /*
    8367                 :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8368                 :  * but that causes reduce/reduce conflicts.  type_function_name
    8369                 :  * is next best choice.
    8370                 :  */
    8371 GIC      179535 : func_type:  Typename                                { $$ = $1; }
    8372 ECB             :             | type_function_name attrs '%' TYPE_P
    8373                 :                 {
    8374 GIC           9 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8375               9 :                     $$->pct_type = true;
    8376               9 :                     $$->location = @1;
    8377 ECB             :                 }
    8378                 :             | SETOF type_function_name attrs '%' TYPE_P
    8379                 :                 {
    8380 GIC           3 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8381               3 :                     $$->pct_type = true;
    8382               3 :                     $$->setof = true;
    8383               3 :                     $$->location = @2;
    8384                 :                 }
    8385                 :         ;
    8386                 : 
    8387                 : func_arg_with_default:
    8388                 :         func_arg
    8389                 :                 {
    8390           73908 :                     $$ = $1;
    8391                 :                 }
    8392                 :         | func_arg DEFAULT a_expr
    8393                 :                 {
    8394           16832 :                     $$ = $1;
    8395 CBC       16832 :                     $$->defexpr = $3;
    8396                 :                 }
    8397 ECB             :         | func_arg '=' a_expr
    8398                 :                 {
    8399 CBC          98 :                     $$ = $1;
    8400              98 :                     $$->defexpr = $3;
    8401 ECB             :                 }
    8402                 :         ;
    8403                 : 
    8404                 : /* Aggregate args can be most things that function args can be */
    8405                 : aggr_arg:   func_arg
    8406                 :                 {
    8407 CBC         446 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8408              30 :                           $1->mode == FUNC_PARAM_IN ||
    8409              30 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8410 LBC           0 :                         ereport(ERROR,
    8411 ECB             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8412                 :                                  errmsg("aggregates cannot have output arguments"),
    8413                 :                                  parser_errposition(@1)));
    8414 GIC         446 :                     $$ = $1;
    8415 ECB             :                 }
    8416                 :         ;
    8417                 : 
    8418                 : /*
    8419                 :  * The SQL standard offers no guidance on how to declare aggregate argument
    8420                 :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8421                 :  *
    8422                 :  * (*)                                  - normal agg with no args
    8423                 :  * (aggr_arg,...)                       - normal agg with args
    8424                 :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8425                 :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8426                 :  *
    8427                 :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8428                 :  *
    8429                 :  * An additional restriction is that if the direct-args list ends in a
    8430                 :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8431                 :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8432                 :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8433                 :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8434                 :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8435                 :  * in cases such as DROP AGGREGATE.
    8436                 :  *
    8437                 :  * The return value of this production is a two-element list, in which the
    8438                 :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8439                 :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8440                 :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8441                 :  * of argument declarations before the ORDER BY.  (If this number is equal
    8442                 :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8443                 :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8444                 :  * on existing aggregates, we can just apply extractArgTypes to the first
    8445                 :  * sublist.
    8446                 :  */
    8447                 : aggr_args:  '(' '*' ')'
    8448                 :                 {
    8449 GBC          68 :                     $$ = list_make2(NIL, makeInteger(-1));
    8450 ECB             :                 }
    8451                 :             | '(' aggr_args_list ')'
    8452                 :                 {
    8453 GIC         362 :                     $$ = list_make2($2, makeInteger(-1));
    8454                 :                 }
    8455                 :             | '(' ORDER BY aggr_args_list ')'
    8456                 :                 {
    8457               3 :                     $$ = list_make2($4, makeInteger(0));
    8458                 :                 }
    8459                 :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8460                 :                 {
    8461                 :                     /* this is the only case requiring consistency checking */
    8462              16 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8463                 :                 }
    8464                 :         ;
    8465                 : 
    8466 ECB             : aggr_args_list:
    8467 GIC         397 :             aggr_arg                                { $$ = list_make1($1); }
    8468              49 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8469                 :         ;
    8470                 : 
    8471                 : aggregate_with_argtypes:
    8472                 :             func_name aggr_args
    8473                 :                 {
    8474             181 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8475 ECB             : 
    8476 GIC         181 :                     n->objname = $1;
    8477             181 :                     n->objargs = extractAggrArgTypes($2);
    8478 CBC         181 :                     n->objfuncargs = (List *) linitial($2);
    8479             181 :                     $$ = n;
    8480 ECB             :                 }
    8481                 :         ;
    8482                 : 
    8483                 : aggregate_with_argtypes_list:
    8484 CBC          52 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8485 ECB             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8486 LBC           0 :                                                     { $$ = lappend($1, $3); }
    8487 ECB             :         ;
    8488                 : 
    8489                 : opt_createfunc_opt_list:
    8490                 :             createfunc_opt_list
    8491 GIC          19 :             | /*EMPTY*/ { $$ = NIL; }
    8492                 :     ;
    8493                 : 
    8494 ECB             : createfunc_opt_list:
    8495                 :             /* Must be at least one to prevent conflict */
    8496 GIC       35411 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8497          115146 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8498 ECB             :     ;
    8499                 : 
    8500                 : /*
    8501                 :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8502                 :  */
    8503                 : common_func_opt_item:
    8504                 :             CALLED ON NULL_P INPUT_P
    8505                 :                 {
    8506 GIC         318 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8507                 :                 }
    8508                 :             | RETURNS NULL_P ON NULL_P INPUT_P
    8509                 :                 {
    8510            2736 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8511 ECB             :                 }
    8512                 :             | STRICT_P
    8513                 :                 {
    8514 GBC       22354 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8515                 :                 }
    8516                 :             | IMMUTABLE
    8517                 :                 {
    8518 CBC       17682 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8519                 :                 }
    8520                 :             | STABLE
    8521                 :                 {
    8522 GIC        7704 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8523                 :                 }
    8524                 :             | VOLATILE
    8525                 :                 {
    8526            3427 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8527                 :                 }
    8528                 :             | EXTERNAL SECURITY DEFINER
    8529                 :                 {
    8530 UIC           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8531                 :                 }
    8532                 :             | EXTERNAL SECURITY INVOKER
    8533                 :                 {
    8534               0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8535                 :                 }
    8536                 :             | SECURITY DEFINER
    8537                 :                 {
    8538 GIC          19 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8539                 :                 }
    8540                 :             | SECURITY INVOKER
    8541                 :                 {
    8542               6 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8543                 :                 }
    8544                 :             | LEAKPROOF
    8545                 :                 {
    8546              23 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8547                 :                 }
    8548                 :             | NOT LEAKPROOF
    8549                 :                 {
    8550               6 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8551                 :                 }
    8552                 :             | COST NumericOnly
    8553 ECB             :                 {
    8554 GIC       13654 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8555                 :                 }
    8556                 :             | ROWS NumericOnly
    8557 ECB             :                 {
    8558 GIC        1519 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8559                 :                 }
    8560                 :             | SUPPORT any_name
    8561 ECB             :                 {
    8562 GIC           9 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8563                 :                 }
    8564                 :             | FunctionSetResetClause
    8565                 :                 {
    8566 ECB             :                     /* we abuse the normal content of a DefElem here */
    8567 GIC          53 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8568                 :                 }
    8569                 :             | PARALLEL ColId
    8570                 :                 {
    8571 CBC       27504 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8572 ECB             :                 }
    8573                 :         ;
    8574                 : 
    8575                 : createfunc_opt_item:
    8576                 :             AS func_as
    8577                 :                 {
    8578 CBC       18389 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8579                 :                 }
    8580 ECB             :             | LANGUAGE NonReservedWord_or_Sconst
    8581                 :                 {
    8582 CBC       35402 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8583 ECB             :                 }
    8584                 :             | TRANSFORM transform_type_list
    8585                 :                 {
    8586 GIC          58 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8587                 :                 }
    8588 ECB             :             | WINDOW
    8589                 :                 {
    8590 GBC          10 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8591                 :                 }
    8592                 :             | common_func_opt_item
    8593                 :                 {
    8594 GIC       96698 :                     $$ = $1;
    8595 ECB             :                 }
    8596                 :         ;
    8597                 : 
    8598 GIC       16780 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8599                 :             | Sconst ',' Sconst
    8600 ECB             :                 {
    8601 CBC        1609 :                     $$ = list_make2(makeString($1), makeString($3));
    8602                 :                 }
    8603                 :         ;
    8604                 : 
    8605                 : ReturnStmt: RETURN a_expr
    8606                 :                 {
    8607 GIC       14888 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8608                 : 
    8609           14888 :                     r->returnval = (Node *) $2;
    8610 CBC       14888 :                     $$ = (Node *) r;
    8611                 :                 }
    8612                 :         ;
    8613                 : 
    8614 ECB             : opt_routine_body:
    8615                 :             ReturnStmt
    8616                 :                 {
    8617 GIC       14885 :                     $$ = $1;
    8618 ECB             :                 }
    8619                 :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8620                 :                 {
    8621                 :                     /*
    8622                 :                      * A compound statement is stored as a single-item list
    8623                 :                      * containing the list of statements as its member.  That
    8624                 :                      * way, the parse analysis code can tell apart an empty
    8625                 :                      * body from no body at all.
    8626                 :                      */
    8627 GIC        2159 :                     $$ = (Node *) list_make1($3);
    8628                 :                 }
    8629                 :             | /*EMPTY*/
    8630 ECB             :                 {
    8631 GIC       18386 :                     $$ = NULL;
    8632                 :                 }
    8633                 :         ;
    8634 EUB             : 
    8635                 : routine_body_stmt_list:
    8636                 :             routine_body_stmt_list routine_body_stmt ';'
    8637                 :                 {
    8638                 :                     /* As in stmtmulti, discard empty statements */
    8639 GIC        2167 :                     if ($2 != NULL)
    8640            2158 :                         $$ = lappend($1, $2);
    8641                 :                     else
    8642 CBC           9 :                         $$ = $1;
    8643                 :                 }
    8644                 :             | /*EMPTY*/
    8645                 :                 {
    8646            2159 :                     $$ = NIL;
    8647                 :                 }
    8648                 :         ;
    8649                 : 
    8650 ECB             : routine_body_stmt:
    8651                 :             stmt
    8652                 :             | ReturnStmt
    8653                 :         ;
    8654                 : 
    8655                 : transform_type_list:
    8656 GIC          58 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    8657               2 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    8658 ECB             :         ;
    8659                 : 
    8660                 : opt_definition:
    8661 GIC         248 :             WITH definition                         { $$ = $2; }
    8662 CBC        4151 :             | /*EMPTY*/                             { $$ = NIL; }
    8663                 :         ;
    8664                 : 
    8665                 : table_func_column:  param_name func_type
    8666 ECB             :                 {
    8667 GIC         176 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8668                 : 
    8669             176 :                     n->name = $1;
    8670             176 :                     n->argType = $2;
    8671 CBC         176 :                     n->mode = FUNC_PARAM_TABLE;
    8672 GIC         176 :                     n->defexpr = NULL;
    8673             176 :                     $$ = n;
    8674                 :                 }
    8675 ECB             :         ;
    8676                 : 
    8677                 : table_func_column_list:
    8678                 :             table_func_column
    8679                 :                 {
    8680 GIC          88 :                     $$ = list_make1($1);
    8681                 :                 }
    8682 ECB             :             | table_func_column_list ',' table_func_column
    8683                 :                 {
    8684 GIC          88 :                     $$ = lappend($1, $3);
    8685                 :                 }
    8686 ECB             :         ;
    8687                 : 
    8688                 : /*****************************************************************************
    8689                 :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    8690                 :  *
    8691                 :  * RENAME and OWNER subcommands are already provided by the generic
    8692                 :  * ALTER infrastructure, here we just specify alterations that can
    8693                 :  * only be applied to functions.
    8694                 :  *
    8695                 :  *****************************************************************************/
    8696                 : AlterFunctionStmt:
    8697                 :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    8698                 :                 {
    8699 GIC         307 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8700                 : 
    8701             307 :                     n->objtype = OBJECT_FUNCTION;
    8702 CBC         307 :                     n->func = $3;
    8703 GIC         307 :                     n->actions = $4;
    8704             307 :                     $$ = (Node *) n;
    8705 ECB             :                 }
    8706                 :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    8707                 :                 {
    8708 GIC           9 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8709                 : 
    8710               9 :                     n->objtype = OBJECT_PROCEDURE;
    8711 CBC           9 :                     n->func = $3;
    8712 GIC           9 :                     n->actions = $4;
    8713 CBC           9 :                     $$ = (Node *) n;
    8714 ECB             :                 }
    8715                 :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    8716                 :                 {
    8717 UIC           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    8718                 : 
    8719               0 :                     n->objtype = OBJECT_ROUTINE;
    8720               0 :                     n->func = $3;
    8721 LBC           0 :                     n->actions = $4;
    8722 UIC           0 :                     $$ = (Node *) n;
    8723                 :                 }
    8724                 :         ;
    8725                 : 
    8726                 : alterfunc_opt_list:
    8727                 :             /* At least one option must be specified */
    8728 GIC         316 :             common_func_opt_item                    { $$ = list_make1($1); }
    8729 UIC           0 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    8730                 :         ;
    8731 ECB             : 
    8732                 : /* Ignored, merely for SQL compliance */
    8733                 : opt_restrict:
    8734                 :             RESTRICT
    8735                 :             | /* EMPTY */
    8736                 :         ;
    8737                 : 
    8738                 : 
    8739                 : /*****************************************************************************
    8740                 :  *
    8741                 :  *      QUERY:
    8742                 :  *
    8743                 :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8744                 :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8745                 :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    8746                 :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    8747                 :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    8748                 :  *
    8749                 :  *****************************************************************************/
    8750                 : 
    8751                 : RemoveFuncStmt:
    8752                 :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    8753                 :                 {
    8754 GIC        1475 :                     DropStmt *n = makeNode(DropStmt);
    8755                 : 
    8756            1475 :                     n->removeType = OBJECT_FUNCTION;
    8757            1475 :                     n->objects = $3;
    8758            1475 :                     n->behavior = $4;
    8759            1475 :                     n->missing_ok = false;
    8760 CBC        1475 :                     n->concurrent = false;
    8761            1475 :                     $$ = (Node *) n;
    8762                 :                 }
    8763                 :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8764                 :                 {
    8765             130 :                     DropStmt *n = makeNode(DropStmt);
    8766 ECB             : 
    8767 GIC         130 :                     n->removeType = OBJECT_FUNCTION;
    8768             130 :                     n->objects = $5;
    8769             130 :                     n->behavior = $6;
    8770             130 :                     n->missing_ok = true;
    8771 CBC         130 :                     n->concurrent = false;
    8772 GIC         130 :                     $$ = (Node *) n;
    8773 ECB             :                 }
    8774                 :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    8775                 :                 {
    8776 CBC          69 :                     DropStmt *n = makeNode(DropStmt);
    8777 ECB             : 
    8778 GIC          69 :                     n->removeType = OBJECT_PROCEDURE;
    8779              69 :                     n->objects = $3;
    8780              69 :                     n->behavior = $4;
    8781              69 :                     n->missing_ok = false;
    8782              69 :                     n->concurrent = false;
    8783              69 :                     $$ = (Node *) n;
    8784 ECB             :                 }
    8785                 :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8786                 :                 {
    8787 GIC           3 :                     DropStmt *n = makeNode(DropStmt);
    8788 ECB             : 
    8789 GIC           3 :                     n->removeType = OBJECT_PROCEDURE;
    8790               3 :                     n->objects = $5;
    8791               3 :                     n->behavior = $6;
    8792               3 :                     n->missing_ok = true;
    8793               3 :                     n->concurrent = false;
    8794               3 :                     $$ = (Node *) n;
    8795                 :                 }
    8796                 :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    8797                 :                 {
    8798               6 :                     DropStmt *n = makeNode(DropStmt);
    8799                 : 
    8800               6 :                     n->removeType = OBJECT_ROUTINE;
    8801               6 :                     n->objects = $3;
    8802               6 :                     n->behavior = $4;
    8803 CBC           6 :                     n->missing_ok = false;
    8804 GIC           6 :                     n->concurrent = false;
    8805 CBC           6 :                     $$ = (Node *) n;
    8806 ECB             :                 }
    8807                 :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    8808                 :                 {
    8809 GIC           3 :                     DropStmt *n = makeNode(DropStmt);
    8810                 : 
    8811               3 :                     n->removeType = OBJECT_ROUTINE;
    8812 CBC           3 :                     n->objects = $5;
    8813 GIC           3 :                     n->behavior = $6;
    8814 CBC           3 :                     n->missing_ok = true;
    8815               3 :                     n->concurrent = false;
    8816               3 :                     $$ = (Node *) n;
    8817 ECB             :                 }
    8818                 :         ;
    8819                 : 
    8820                 : RemoveAggrStmt:
    8821 EUB             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    8822                 :                 {
    8823 GBC          37 :                     DropStmt *n = makeNode(DropStmt);
    8824 EUB             : 
    8825 GBC          37 :                     n->removeType = OBJECT_AGGREGATE;
    8826              37 :                     n->objects = $3;
    8827 GIC          37 :                     n->behavior = $4;
    8828              37 :                     n->missing_ok = false;
    8829              37 :                     n->concurrent = false;
    8830              37 :                     $$ = (Node *) n;
    8831                 :                 }
    8832 ECB             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    8833 EUB             :                 {
    8834 GIC          15 :                     DropStmt *n = makeNode(DropStmt);
    8835                 : 
    8836              15 :                     n->removeType = OBJECT_AGGREGATE;
    8837              15 :                     n->objects = $5;
    8838              15 :                     n->behavior = $6;
    8839              15 :                     n->missing_ok = true;
    8840              15 :                     n->concurrent = false;
    8841              15 :                     $$ = (Node *) n;
    8842                 :                 }
    8843                 :         ;
    8844                 : 
    8845                 : RemoveOperStmt:
    8846                 :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    8847                 :                 {
    8848              82 :                     DropStmt *n = makeNode(DropStmt);
    8849                 : 
    8850              82 :                     n->removeType = OBJECT_OPERATOR;
    8851              82 :                     n->objects = $3;
    8852              82 :                     n->behavior = $4;
    8853              82 :                     n->missing_ok = false;
    8854              82 :                     n->concurrent = false;
    8855              82 :                     $$ = (Node *) n;
    8856                 :                 }
    8857                 :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    8858 ECB             :                 {
    8859 GIC          15 :                     DropStmt *n = makeNode(DropStmt);
    8860 ECB             : 
    8861 CBC          15 :                     n->removeType = OBJECT_OPERATOR;
    8862              15 :                     n->objects = $5;
    8863              15 :                     n->behavior = $6;
    8864              15 :                     n->missing_ok = true;
    8865              15 :                     n->concurrent = false;
    8866 GIC          15 :                     $$ = (Node *) n;
    8867                 :                 }
    8868                 :         ;
    8869 ECB             : 
    8870                 : oper_argtypes:
    8871                 :             '(' Typename ')'
    8872                 :                 {
    8873 CBC           6 :                    ereport(ERROR,
    8874 ECB             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    8875                 :                             errmsg("missing argument"),
    8876                 :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    8877                 :                             parser_errposition(@3)));
    8878                 :                 }
    8879                 :             | '(' Typename ',' Typename ')'
    8880 CBC         876 :                     { $$ = list_make2($2, $4); }
    8881                 :             | '(' NONE ',' Typename ')'                 /* left unary */
    8882              16 :                     { $$ = list_make2(NULL, $4); }
    8883 ECB             :             | '(' Typename ',' NONE ')'                 /* right unary */
    8884 CBC           6 :                     { $$ = list_make2($2, NULL); }
    8885 ECB             :         ;
    8886                 : 
    8887                 : any_operator:
    8888                 :             all_Op
    8889 GIC        8920 :                     { $$ = list_make1(makeString($1)); }
    8890                 :             | ColId '.' any_operator
    8891 CBC        6709 :                     { $$ = lcons(makeString($1), $3); }
    8892                 :         ;
    8893 ECB             : 
    8894                 : operator_with_argtypes_list:
    8895 CBC          97 :             operator_with_argtypes                  { $$ = list_make1($1); }
    8896 ECB             :             | operator_with_argtypes_list ',' operator_with_argtypes
    8897 LBC           0 :                                                     { $$ = lappend($1, $3); }
    8898 ECB             :         ;
    8899                 : 
    8900                 : operator_with_argtypes:
    8901                 :             any_operator oper_argtypes
    8902                 :                 {
    8903 GIC         898 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8904 ECB             : 
    8905 CBC         898 :                     n->objname = $1;
    8906             898 :                     n->objargs = $2;
    8907             898 :                     $$ = n;
    8908 ECB             :                 }
    8909                 :         ;
    8910                 : 
    8911                 : /*****************************************************************************
    8912                 :  *
    8913                 :  *      DO <anonymous code block> [ LANGUAGE language ]
    8914                 :  *
    8915                 :  * We use a DefElem list for future extensibility, and to allow flexibility
    8916                 :  * in the clause order.
    8917                 :  *
    8918                 :  *****************************************************************************/
    8919                 : 
    8920                 : DoStmt: DO dostmt_opt_list
    8921                 :                 {
    8922 GIC         507 :                     DoStmt *n = makeNode(DoStmt);
    8923                 : 
    8924             507 :                     n->args = $2;
    8925             507 :                     $$ = (Node *) n;
    8926                 :                 }
    8927 ECB             :         ;
    8928                 : 
    8929                 : dostmt_opt_list:
    8930 CBC         507 :             dostmt_opt_item                     { $$ = list_make1($1); }
    8931              95 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    8932 ECB             :         ;
    8933                 : 
    8934                 : dostmt_opt_item:
    8935                 :             Sconst
    8936                 :                 {
    8937 GIC         507 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    8938 ECB             :                 }
    8939                 :             | LANGUAGE NonReservedWord_or_Sconst
    8940                 :                 {
    8941 CBC          95 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8942 ECB             :                 }
    8943                 :         ;
    8944                 : 
    8945                 : /*****************************************************************************
    8946                 :  *
    8947                 :  *      CREATE CAST / DROP CAST
    8948                 :  *
    8949                 :  *****************************************************************************/
    8950                 : 
    8951                 : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    8952                 :                     WITH FUNCTION function_with_argtypes cast_context
    8953                 :                 {
    8954 CBC          51 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    8955 ECB             : 
    8956 CBC          51 :                     n->sourcetype = $4;
    8957              51 :                     n->targettype = $6;
    8958              51 :                     n->func = $10;
    8959              51 :                     n->context = (CoercionContext) $11;
    8960 GIC          51 :                     n->inout = false;
    8961              51 :                     $$ = (Node *) n;
    8962                 :                 }
    8963 ECB             :             | CREATE CAST '(' Typename AS Typename ')'
    8964                 :                     WITHOUT FUNCTION cast_context
    8965                 :                 {
    8966 CBC          81 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    8967 ECB             : 
    8968 CBC          81 :                     n->sourcetype = $4;
    8969              81 :                     n->targettype = $6;
    8970              81 :                     n->func = NULL;
    8971 GIC          81 :                     n->context = (CoercionContext) $10;
    8972              81 :                     n->inout = false;
    8973              81 :                     $$ = (Node *) n;
    8974                 :                 }
    8975                 :             | CREATE CAST '(' Typename AS Typename ')'
    8976                 :                     WITH INOUT cast_context
    8977 ECB             :                 {
    8978 GIC           3 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    8979                 : 
    8980               3 :                     n->sourcetype = $4;
    8981               3 :                     n->targettype = $6;
    8982               3 :                     n->func = NULL;
    8983               3 :                     n->context = (CoercionContext) $10;
    8984 CBC           3 :                     n->inout = true;
    8985 GIC           3 :                     $$ = (Node *) n;
    8986 ECB             :                 }
    8987                 :         ;
    8988                 : 
    8989 GIC          15 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    8990              29 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    8991              91 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    8992                 :         ;
    8993 ECB             : 
    8994                 : 
    8995                 : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    8996                 :                 {
    8997 GIC          27 :                     DropStmt *n = makeNode(DropStmt);
    8998                 : 
    8999 CBC          27 :                     n->removeType = OBJECT_CAST;
    9000 GIC          27 :                     n->objects = list_make1(list_make2($5, $7));
    9001 GBC          27 :                     n->behavior = $9;
    9002 GIC          27 :                     n->missing_ok = $3;
    9003              27 :                     n->concurrent = false;
    9004              27 :                     $$ = (Node *) n;
    9005                 :                 }
    9006                 :         ;
    9007 ECB             : 
    9008 GIC          18 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9009 CBC          16 :         | /*EMPTY*/                             { $$ = false; }
    9010 ECB             :         ;
    9011                 : 
    9012                 : 
    9013                 : /*****************************************************************************
    9014                 :  *
    9015                 :  *      CREATE TRANSFORM / DROP TRANSFORM
    9016                 :  *
    9017                 :  *****************************************************************************/
    9018                 : 
    9019                 : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9020                 :                 {
    9021 GIC          25 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9022                 : 
    9023              25 :                     n->replace = $2;
    9024              25 :                     n->type_name = $5;
    9025              25 :                     n->lang = $7;
    9026 CBC          25 :                     n->fromsql = linitial($9);
    9027 GIC          25 :                     n->tosql = lsecond($9);
    9028 CBC          25 :                     $$ = (Node *) n;
    9029 ECB             :                 }
    9030                 :         ;
    9031                 : 
    9032                 : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9033                 :                 {
    9034 CBC          22 :                     $$ = list_make2($5, $11);
    9035 ECB             :                 }
    9036                 :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9037                 :                 {
    9038 UIC           0 :                     $$ = list_make2($11, $5);
    9039                 :                 }
    9040                 :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9041 ECB             :                 {
    9042 GIC           2 :                     $$ = list_make2($5, NULL);
    9043                 :                 }
    9044                 :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9045 ECB             :                 {
    9046 GIC           1 :                     $$ = list_make2(NULL, $5);
    9047                 :                 }
    9048                 :         ;
    9049                 : 
    9050                 : 
    9051                 : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9052                 :                 {
    9053               7 :                     DropStmt *n = makeNode(DropStmt);
    9054                 : 
    9055               7 :                     n->removeType = OBJECT_TRANSFORM;
    9056               7 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9057               7 :                     n->behavior = $8;
    9058 CBC           7 :                     n->missing_ok = $3;
    9059 GIC           7 :                     $$ = (Node *) n;
    9060 ECB             :                 }
    9061                 :         ;
    9062                 : 
    9063                 : 
    9064                 : /*****************************************************************************
    9065                 :  *
    9066                 :  *      QUERY:
    9067                 :  *
    9068                 :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9069                 :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9070                 :  *****************************************************************************/
    9071                 : 
    9072                 : ReindexStmt:
    9073                 :             REINDEX opt_reindex_option_list reindex_target_relation opt_concurrently qualified_name
    9074                 :                 {
    9075 CBC         373 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9076 ECB             : 
    9077 GNC         373 :                     n->kind = $3;
    9078             373 :                     n->relation = $5;
    9079 GIC         373 :                     n->name = NULL;
    9080 GNC         373 :                     n->params = $2;
    9081             373 :                     if ($4)
    9082 GIC         218 :                         n->params = lappend(n->params,
    9083 GNC         218 :                                             makeDefElem("concurrently", NULL, @4));
    9084 GIC         373 :                     $$ = (Node *) n;
    9085 ECB             :                 }
    9086                 :             | REINDEX opt_reindex_option_list SCHEMA opt_concurrently name
    9087                 :                 {
    9088 CBC          37 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9089 ECB             : 
    9090 GNC          37 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9091 GIC          37 :                     n->relation = NULL;
    9092 GNC          37 :                     n->name = $5;
    9093              37 :                     n->params = $2;
    9094              37 :                     if ($4)
    9095 CBC          11 :                         n->params = lappend(n->params,
    9096 GNC          11 :                                             makeDefElem("concurrently", NULL, @4));
    9097 GIC          37 :                     $$ = (Node *) n;
    9098                 :                 }
    9099                 :             | REINDEX opt_reindex_option_list reindex_target_all opt_concurrently opt_single_name
    9100                 :                 {
    9101              27 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9102 ECB             : 
    9103 GNC          27 :                     n->kind = $3;
    9104 GIC          27 :                     n->relation = NULL;
    9105 GNC          27 :                     n->name = $5;
    9106              27 :                     n->params = $2;
    9107              27 :                     if ($4)
    9108 GIC           5 :                         n->params = lappend(n->params,
    9109 GNC           5 :                                             makeDefElem("concurrently", NULL, @4));
    9110 GIC          27 :                     $$ = (Node *) n;
    9111                 :                 }
    9112                 :         ;
    9113                 : reindex_target_relation:
    9114             160 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9115 CBC         213 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9116 ECB             :         ;
    9117                 : reindex_target_all:
    9118 GNC          12 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9119 CBC          15 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9120                 :         ;
    9121                 : opt_reindex_option_list:
    9122 GNC          78 :             '(' utility_option_list ')'             { $$ = $2; }
    9123             359 :             | /* EMPTY */                           { $$ = NULL; }
    9124                 :         ;
    9125                 : 
    9126                 : /*****************************************************************************
    9127                 :  *
    9128                 :  * ALTER TABLESPACE
    9129 ECB             :  *
    9130                 :  *****************************************************************************/
    9131                 : 
    9132                 : AlterTblSpcStmt:
    9133 EUB             :             ALTER TABLESPACE name SET reloptions
    9134                 :                 {
    9135 GIC           6 :                     AlterTableSpaceOptionsStmt *n =
    9136               6 :                         makeNode(AlterTableSpaceOptionsStmt);
    9137 ECB             : 
    9138 GIC           6 :                     n->tablespacename = $3;
    9139               6 :                     n->options = $5;
    9140               6 :                     n->isReset = false;
    9141 CBC           6 :                     $$ = (Node *) n;
    9142                 :                 }
    9143                 :             | ALTER TABLESPACE name RESET reloptions
    9144                 :                 {
    9145 GIC           6 :                     AlterTableSpaceOptionsStmt *n =
    9146               6 :                         makeNode(AlterTableSpaceOptionsStmt);
    9147                 : 
    9148 CBC           6 :                     n->tablespacename = $3;
    9149 GIC           6 :                     n->options = $5;
    9150 CBC           6 :                     n->isReset = true;
    9151               6 :                     $$ = (Node *) n;
    9152 ECB             :                 }
    9153                 :         ;
    9154                 : 
    9155                 : /*****************************************************************************
    9156                 :  *
    9157                 :  * ALTER THING name RENAME TO newname
    9158                 :  *
    9159                 :  *****************************************************************************/
    9160                 : 
    9161                 : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9162                 :                 {
    9163 GIC          21 :                     RenameStmt *n = makeNode(RenameStmt);
    9164                 : 
    9165              21 :                     n->renameType = OBJECT_AGGREGATE;
    9166              21 :                     n->object = (Node *) $3;
    9167              21 :                     n->newname = $6;
    9168              21 :                     n->missing_ok = false;
    9169              21 :                     $$ = (Node *) n;
    9170 ECB             :                 }
    9171                 :             | ALTER COLLATION any_name RENAME TO name
    9172                 :                 {
    9173 CBC          18 :                     RenameStmt *n = makeNode(RenameStmt);
    9174 ECB             : 
    9175 CBC          18 :                     n->renameType = OBJECT_COLLATION;
    9176              18 :                     n->object = (Node *) $3;
    9177              18 :                     n->newname = $6;
    9178              18 :                     n->missing_ok = false;
    9179              18 :                     $$ = (Node *) n;
    9180                 :                 }
    9181                 :             | ALTER CONVERSION_P any_name RENAME TO name
    9182                 :                 {
    9183              12 :                     RenameStmt *n = makeNode(RenameStmt);
    9184                 : 
    9185              12 :                     n->renameType = OBJECT_CONVERSION;
    9186              12 :                     n->object = (Node *) $3;
    9187              12 :                     n->newname = $6;
    9188              12 :                     n->missing_ok = false;
    9189              12 :                     $$ = (Node *) n;
    9190 ECB             :                 }
    9191                 :             | ALTER DATABASE name RENAME TO name
    9192                 :                 {
    9193 UIC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9194                 : 
    9195               0 :                     n->renameType = OBJECT_DATABASE;
    9196 LBC           0 :                     n->subname = $3;
    9197 UIC           0 :                     n->newname = $6;
    9198 LBC           0 :                     n->missing_ok = false;
    9199               0 :                     $$ = (Node *) n;
    9200 ECB             :                 }
    9201                 :             | ALTER DOMAIN_P any_name RENAME TO name
    9202                 :                 {
    9203 CBC           3 :                     RenameStmt *n = makeNode(RenameStmt);
    9204 ECB             : 
    9205 CBC           3 :                     n->renameType = OBJECT_DOMAIN;
    9206 GIC           3 :                     n->object = (Node *) $3;
    9207               3 :                     n->newname = $6;
    9208               3 :                     n->missing_ok = false;
    9209 CBC           3 :                     $$ = (Node *) n;
    9210 ECB             :                 }
    9211                 :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9212                 :                 {
    9213 CBC           3 :                     RenameStmt *n = makeNode(RenameStmt);
    9214 ECB             : 
    9215 GIC           3 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9216               3 :                     n->object = (Node *) $3;
    9217 CBC           3 :                     n->subname = $6;
    9218               3 :                     n->newname = $8;
    9219 GIC           3 :                     $$ = (Node *) n;
    9220                 :                 }
    9221                 :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9222                 :                 {
    9223              12 :                     RenameStmt *n = makeNode(RenameStmt);
    9224                 : 
    9225              12 :                     n->renameType = OBJECT_FDW;
    9226              12 :                     n->object = (Node *) makeString($5);
    9227              12 :                     n->newname = $8;
    9228              12 :                     n->missing_ok = false;
    9229              12 :                     $$ = (Node *) n;
    9230 ECB             :                 }
    9231                 :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9232                 :                 {
    9233 CBC          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9234 ECB             : 
    9235 CBC          12 :                     n->renameType = OBJECT_FUNCTION;
    9236              12 :                     n->object = (Node *) $3;
    9237 GIC          12 :                     n->newname = $6;
    9238              12 :                     n->missing_ok = false;
    9239              12 :                     $$ = (Node *) n;
    9240 ECB             :                 }
    9241                 :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9242                 :                 {
    9243 LBC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9244 ECB             : 
    9245 LBC           0 :                     n->renameType = OBJECT_ROLE;
    9246               0 :                     n->subname = $3;
    9247 UIC           0 :                     n->newname = $6;
    9248               0 :                     n->missing_ok = false;
    9249               0 :                     $$ = (Node *) n;
    9250                 :                 }
    9251                 :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9252                 :                 {
    9253 GIC           9 :                     RenameStmt *n = makeNode(RenameStmt);
    9254                 : 
    9255               9 :                     n->renameType = OBJECT_LANGUAGE;
    9256               9 :                     n->object = (Node *) makeString($4);
    9257               9 :                     n->newname = $7;
    9258 CBC           9 :                     n->missing_ok = false;
    9259 GIC           9 :                     $$ = (Node *) n;
    9260 ECB             :                 }
    9261                 :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9262                 :                 {
    9263 CBC          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9264 ECB             : 
    9265 GIC          12 :                     n->renameType = OBJECT_OPCLASS;
    9266              12 :                     n->object = (Node *) lcons(makeString($6), $4);
    9267              12 :                     n->newname = $9;
    9268 CBC          12 :                     n->missing_ok = false;
    9269 GIC          12 :                     $$ = (Node *) n;
    9270 ECB             :                 }
    9271                 :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9272                 :                 {
    9273 CBC          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9274 ECB             : 
    9275 GIC          12 :                     n->renameType = OBJECT_OPFAMILY;
    9276              12 :                     n->object = (Node *) lcons(makeString($6), $4);
    9277              12 :                     n->newname = $9;
    9278 CBC          12 :                     n->missing_ok = false;
    9279 GIC          12 :                     $$ = (Node *) n;
    9280 ECB             :                 }
    9281                 :             | ALTER POLICY name ON qualified_name RENAME TO name
    9282                 :                 {
    9283 CBC           9 :                     RenameStmt *n = makeNode(RenameStmt);
    9284 ECB             : 
    9285 GIC           9 :                     n->renameType = OBJECT_POLICY;
    9286               9 :                     n->relation = $5;
    9287               9 :                     n->subname = $3;
    9288 GBC           9 :                     n->newname = $8;
    9289 GIC           9 :                     n->missing_ok = false;
    9290 GBC           9 :                     $$ = (Node *) n;
    9291 EUB             :                 }
    9292                 :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9293                 :                 {
    9294 UBC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9295                 : 
    9296 UIC           0 :                     n->renameType = OBJECT_POLICY;
    9297               0 :                     n->relation = $7;
    9298 LBC           0 :                     n->subname = $5;
    9299 UIC           0 :                     n->newname = $10;
    9300 LBC           0 :                     n->missing_ok = true;
    9301               0 :                     $$ = (Node *) n;
    9302 ECB             :                 }
    9303                 :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9304                 :                 {
    9305 UIC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9306                 : 
    9307               0 :                     n->renameType = OBJECT_PROCEDURE;
    9308 LBC           0 :                     n->object = (Node *) $3;
    9309 UIC           0 :                     n->newname = $6;
    9310 LBC           0 :                     n->missing_ok = false;
    9311               0 :                     $$ = (Node *) n;
    9312 ECB             :                 }
    9313                 :             | ALTER PUBLICATION name RENAME TO name
    9314                 :                 {
    9315 GIC           9 :                     RenameStmt *n = makeNode(RenameStmt);
    9316                 : 
    9317               9 :                     n->renameType = OBJECT_PUBLICATION;
    9318 CBC           9 :                     n->object = (Node *) makeString($3);
    9319 GIC           9 :                     n->newname = $6;
    9320 CBC           9 :                     n->missing_ok = false;
    9321               9 :                     $$ = (Node *) n;
    9322 ECB             :                 }
    9323                 :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9324                 :                 {
    9325 GIC          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9326                 : 
    9327              12 :                     n->renameType = OBJECT_ROUTINE;
    9328 CBC          12 :                     n->object = (Node *) $3;
    9329 GIC          12 :                     n->newname = $6;
    9330 CBC          12 :                     n->missing_ok = false;
    9331              12 :                     $$ = (Node *) n;
    9332 ECB             :                 }
    9333                 :             | ALTER SCHEMA name RENAME TO name
    9334                 :                 {
    9335 GIC          10 :                     RenameStmt *n = makeNode(RenameStmt);
    9336                 : 
    9337              10 :                     n->renameType = OBJECT_SCHEMA;
    9338 GBC          10 :                     n->subname = $3;
    9339 GIC          10 :                     n->newname = $6;
    9340 GBC          10 :                     n->missing_ok = false;
    9341              10 :                     $$ = (Node *) n;
    9342 EUB             :                 }
    9343                 :             | ALTER SERVER name RENAME TO name
    9344                 :                 {
    9345 GIC          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9346                 : 
    9347              12 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9348 CBC          12 :                     n->object = (Node *) makeString($3);
    9349 GIC          12 :                     n->newname = $6;
    9350 CBC          12 :                     n->missing_ok = false;
    9351              12 :                     $$ = (Node *) n;
    9352 ECB             :                 }
    9353                 :             | ALTER SUBSCRIPTION name RENAME TO name
    9354                 :                 {
    9355 GIC          19 :                     RenameStmt *n = makeNode(RenameStmt);
    9356                 : 
    9357              19 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9358 CBC          19 :                     n->object = (Node *) makeString($3);
    9359 GIC          19 :                     n->newname = $6;
    9360 CBC          19 :                     n->missing_ok = false;
    9361              19 :                     $$ = (Node *) n;
    9362 ECB             :                 }
    9363                 :             | ALTER TABLE relation_expr RENAME TO name
    9364                 :                 {
    9365 GIC         143 :                     RenameStmt *n = makeNode(RenameStmt);
    9366                 : 
    9367             143 :                     n->renameType = OBJECT_TABLE;
    9368 CBC         143 :                     n->relation = $3;
    9369 GIC         143 :                     n->subname = NULL;
    9370 CBC         143 :                     n->newname = $6;
    9371             143 :                     n->missing_ok = false;
    9372             143 :                     $$ = (Node *) n;
    9373 ECB             :                 }
    9374                 :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9375                 :                 {
    9376 UIC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9377                 : 
    9378 LBC           0 :                     n->renameType = OBJECT_TABLE;
    9379 UIC           0 :                     n->relation = $5;
    9380 LBC           0 :                     n->subname = NULL;
    9381               0 :                     n->newname = $8;
    9382               0 :                     n->missing_ok = true;
    9383               0 :                     $$ = (Node *) n;
    9384 ECB             :                 }
    9385                 :             | ALTER SEQUENCE qualified_name RENAME TO name
    9386                 :                 {
    9387 GIC           1 :                     RenameStmt *n = makeNode(RenameStmt);
    9388                 : 
    9389 GBC           1 :                     n->renameType = OBJECT_SEQUENCE;
    9390 GIC           1 :                     n->relation = $3;
    9391 GBC           1 :                     n->subname = NULL;
    9392               1 :                     n->newname = $6;
    9393               1 :                     n->missing_ok = false;
    9394               1 :                     $$ = (Node *) n;
    9395 EUB             :                 }
    9396                 :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9397                 :                 {
    9398 UIC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9399                 : 
    9400 UBC           0 :                     n->renameType = OBJECT_SEQUENCE;
    9401 UIC           0 :                     n->relation = $5;
    9402 UBC           0 :                     n->subname = NULL;
    9403               0 :                     n->newname = $8;
    9404               0 :                     n->missing_ok = true;
    9405               0 :                     $$ = (Node *) n;
    9406 EUB             :                 }
    9407                 :             | ALTER VIEW qualified_name RENAME TO name
    9408                 :                 {
    9409 GIC           3 :                     RenameStmt *n = makeNode(RenameStmt);
    9410 ECB             : 
    9411 GIC           3 :                     n->renameType = OBJECT_VIEW;
    9412 CBC           3 :                     n->relation = $3;
    9413               3 :                     n->subname = NULL;
    9414               3 :                     n->newname = $6;
    9415               3 :                     n->missing_ok = false;
    9416               3 :                     $$ = (Node *) n;
    9417                 :                 }
    9418                 :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9419                 :                 {
    9420 LBC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9421                 : 
    9422               0 :                     n->renameType = OBJECT_VIEW;
    9423               0 :                     n->relation = $5;
    9424               0 :                     n->subname = NULL;
    9425               0 :                     n->newname = $8;
    9426               0 :                     n->missing_ok = true;
    9427 UIC           0 :                     $$ = (Node *) n;
    9428                 :                 }
    9429                 :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9430 ECB             :                 {
    9431 UIC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9432 ECB             : 
    9433 LBC           0 :                     n->renameType = OBJECT_MATVIEW;
    9434               0 :                     n->relation = $4;
    9435               0 :                     n->subname = NULL;
    9436               0 :                     n->newname = $7;
    9437 UIC           0 :                     n->missing_ok = false;
    9438               0 :                     $$ = (Node *) n;
    9439                 :                 }
    9440 ECB             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9441                 :                 {
    9442 LBC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9443 ECB             : 
    9444 LBC           0 :                     n->renameType = OBJECT_MATVIEW;
    9445               0 :                     n->relation = $6;
    9446               0 :                     n->subname = NULL;
    9447 UIC           0 :                     n->newname = $9;
    9448               0 :                     n->missing_ok = true;
    9449               0 :                     $$ = (Node *) n;
    9450 ECB             :                 }
    9451                 :             | ALTER INDEX qualified_name RENAME TO name
    9452                 :                 {
    9453 CBC          96 :                     RenameStmt *n = makeNode(RenameStmt);
    9454 ECB             : 
    9455 CBC          96 :                     n->renameType = OBJECT_INDEX;
    9456              96 :                     n->relation = $3;
    9457 GIC          96 :                     n->subname = NULL;
    9458              96 :                     n->newname = $6;
    9459              96 :                     n->missing_ok = false;
    9460 CBC          96 :                     $$ = (Node *) n;
    9461                 :                 }
    9462 ECB             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9463                 :                 {
    9464 CBC           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9465 ECB             : 
    9466 CBC           6 :                     n->renameType = OBJECT_INDEX;
    9467               6 :                     n->relation = $5;
    9468 GIC           6 :                     n->subname = NULL;
    9469               6 :                     n->newname = $8;
    9470               6 :                     n->missing_ok = true;
    9471 GBC           6 :                     $$ = (Node *) n;
    9472                 :                 }
    9473 EUB             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9474                 :                 {
    9475 GBC           3 :                     RenameStmt *n = makeNode(RenameStmt);
    9476 EUB             : 
    9477 GBC           3 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9478               3 :                     n->relation = $4;
    9479 GIC           3 :                     n->subname = NULL;
    9480               3 :                     n->newname = $7;
    9481               3 :                     n->missing_ok = false;
    9482 CBC           3 :                     $$ = (Node *) n;
    9483                 :                 }
    9484 ECB             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9485                 :                 {
    9486 CBC           3 :                     RenameStmt *n = makeNode(RenameStmt);
    9487 ECB             : 
    9488 CBC           3 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9489               3 :                     n->relation = $6;
    9490 GIC           3 :                     n->subname = NULL;
    9491               3 :                     n->newname = $9;
    9492               3 :                     n->missing_ok = true;
    9493 GBC           3 :                     $$ = (Node *) n;
    9494                 :                 }
    9495 EUB             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9496                 :                 {
    9497 GBC         116 :                     RenameStmt *n = makeNode(RenameStmt);
    9498 EUB             : 
    9499 GBC         116 :                     n->renameType = OBJECT_COLUMN;
    9500             116 :                     n->relationType = OBJECT_TABLE;
    9501 GIC         116 :                     n->relation = $3;
    9502             116 :                     n->subname = $6;
    9503             116 :                     n->newname = $8;
    9504 CBC         116 :                     n->missing_ok = false;
    9505 GIC         116 :                     $$ = (Node *) n;
    9506 ECB             :                 }
    9507                 :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9508                 :                 {
    9509 CBC          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9510 ECB             : 
    9511 CBC          12 :                     n->renameType = OBJECT_COLUMN;
    9512 GIC          12 :                     n->relationType = OBJECT_TABLE;
    9513              12 :                     n->relation = $5;
    9514              12 :                     n->subname = $8;
    9515 GBC          12 :                     n->newname = $10;
    9516 GIC          12 :                     n->missing_ok = true;
    9517 GBC          12 :                     $$ = (Node *) n;
    9518 EUB             :                 }
    9519                 :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9520                 :                 {
    9521 GBC           3 :                     RenameStmt *n = makeNode(RenameStmt);
    9522 EUB             : 
    9523 GIC           3 :                     n->renameType = OBJECT_COLUMN;
    9524               3 :                     n->relationType = OBJECT_VIEW;
    9525               3 :                     n->relation = $3;
    9526 GBC           3 :                     n->subname = $6;
    9527 GIC           3 :                     n->newname = $8;
    9528 GBC           3 :                     n->missing_ok = false;
    9529               3 :                     $$ = (Node *) n;
    9530 EUB             :                 }
    9531                 :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9532                 :                 {
    9533 UBC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9534                 : 
    9535 UIC           0 :                     n->renameType = OBJECT_COLUMN;
    9536               0 :                     n->relationType = OBJECT_VIEW;
    9537 UBC           0 :                     n->relation = $5;
    9538 UIC           0 :                     n->subname = $8;
    9539 UBC           0 :                     n->newname = $10;
    9540               0 :                     n->missing_ok = true;
    9541               0 :                     $$ = (Node *) n;
    9542 EUB             :                 }
    9543                 :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9544                 :                 {
    9545 UIC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9546                 : 
    9547               0 :                     n->renameType = OBJECT_COLUMN;
    9548 LBC           0 :                     n->relationType = OBJECT_MATVIEW;
    9549 UIC           0 :                     n->relation = $4;
    9550 LBC           0 :                     n->subname = $7;
    9551               0 :                     n->newname = $9;
    9552               0 :                     n->missing_ok = false;
    9553               0 :                     $$ = (Node *) n;
    9554 ECB             :                 }
    9555                 :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9556                 :                 {
    9557 UIC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9558                 : 
    9559 LBC           0 :                     n->renameType = OBJECT_COLUMN;
    9560 UIC           0 :                     n->relationType = OBJECT_MATVIEW;
    9561 LBC           0 :                     n->relation = $6;
    9562               0 :                     n->subname = $9;
    9563               0 :                     n->newname = $11;
    9564               0 :                     n->missing_ok = true;
    9565               0 :                     $$ = (Node *) n;
    9566 ECB             :                 }
    9567                 :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9568                 :                 {
    9569 GIC          33 :                     RenameStmt *n = makeNode(RenameStmt);
    9570 ECB             : 
    9571 GIC          33 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9572 CBC          33 :                     n->relation = $3;
    9573              33 :                     n->subname = $6;
    9574              33 :                     n->newname = $8;
    9575              33 :                     n->missing_ok = false;
    9576              33 :                     $$ = (Node *) n;
    9577 ECB             :                 }
    9578                 :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9579                 :                 {
    9580 GIC           3 :                     RenameStmt *n = makeNode(RenameStmt);
    9581 ECB             : 
    9582 GIC           3 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9583 CBC           3 :                     n->relation = $5;
    9584               3 :                     n->subname = $8;
    9585               3 :                     n->newname = $10;
    9586               3 :                     n->missing_ok = true;
    9587               3 :                     $$ = (Node *) n;
    9588 ECB             :                 }
    9589                 :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9590                 :                 {
    9591 GIC           3 :                     RenameStmt *n = makeNode(RenameStmt);
    9592 ECB             : 
    9593 GIC           3 :                     n->renameType = OBJECT_COLUMN;
    9594 CBC           3 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9595               3 :                     n->relation = $4;
    9596               3 :                     n->subname = $7;
    9597               3 :                     n->newname = $9;
    9598               3 :                     n->missing_ok = false;
    9599               3 :                     $$ = (Node *) n;
    9600 ECB             :                 }
    9601                 :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9602                 :                 {
    9603 GIC           3 :                     RenameStmt *n = makeNode(RenameStmt);
    9604 ECB             : 
    9605 GIC           3 :                     n->renameType = OBJECT_COLUMN;
    9606 CBC           3 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9607               3 :                     n->relation = $6;
    9608               3 :                     n->subname = $9;
    9609               3 :                     n->newname = $11;
    9610               3 :                     n->missing_ok = true;
    9611               3 :                     $$ = (Node *) n;
    9612 ECB             :                 }
    9613                 :             | ALTER RULE name ON qualified_name RENAME TO name
    9614                 :                 {
    9615 GIC          17 :                     RenameStmt *n = makeNode(RenameStmt);
    9616 ECB             : 
    9617 GIC          17 :                     n->renameType = OBJECT_RULE;
    9618 CBC          17 :                     n->relation = $5;
    9619              17 :                     n->subname = $3;
    9620              17 :                     n->newname = $8;
    9621              17 :                     n->missing_ok = false;
    9622              17 :                     $$ = (Node *) n;
    9623 ECB             :                 }
    9624                 :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9625                 :                 {
    9626 GIC          20 :                     RenameStmt *n = makeNode(RenameStmt);
    9627                 : 
    9628 GBC          20 :                     n->renameType = OBJECT_TRIGGER;
    9629 GIC          20 :                     n->relation = $5;
    9630 GBC          20 :                     n->subname = $3;
    9631              20 :                     n->newname = $8;
    9632              20 :                     n->missing_ok = false;
    9633              20 :                     $$ = (Node *) n;
    9634 EUB             :                 }
    9635                 :             | ALTER EVENT TRIGGER name RENAME TO name
    9636                 :                 {
    9637 GIC           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9638                 : 
    9639               6 :                     n->renameType = OBJECT_EVENT_TRIGGER;
    9640 GBC           6 :                     n->object = (Node *) makeString($4);
    9641 GIC           6 :                     n->newname = $7;
    9642 GBC           6 :                     $$ = (Node *) n;
    9643 EUB             :                 }
    9644                 :             | ALTER ROLE RoleId RENAME TO RoleId
    9645                 :                 {
    9646 GBC          15 :                     RenameStmt *n = makeNode(RenameStmt);
    9647 EUB             : 
    9648 GBC          15 :                     n->renameType = OBJECT_ROLE;
    9649 GIC          15 :                     n->subname = $3;
    9650              15 :                     n->newname = $6;
    9651              15 :                     n->missing_ok = false;
    9652 GBC          15 :                     $$ = (Node *) n;
    9653                 :                 }
    9654 EUB             :             | ALTER USER RoleId RENAME TO RoleId
    9655                 :                 {
    9656 UBC           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9657 EUB             : 
    9658 UBC           0 :                     n->renameType = OBJECT_ROLE;
    9659               0 :                     n->subname = $3;
    9660               0 :                     n->newname = $6;
    9661 UIC           0 :                     n->missing_ok = false;
    9662               0 :                     $$ = (Node *) n;
    9663                 :                 }
    9664 ECB             :             | ALTER TABLESPACE name RENAME TO name
    9665                 :                 {
    9666 CBC           3 :                     RenameStmt *n = makeNode(RenameStmt);
    9667 ECB             : 
    9668 CBC           3 :                     n->renameType = OBJECT_TABLESPACE;
    9669               3 :                     n->subname = $3;
    9670               3 :                     n->newname = $6;
    9671               3 :                     n->missing_ok = false;
    9672 GIC           3 :                     $$ = (Node *) n;
    9673                 :                 }
    9674                 :             | ALTER STATISTICS any_name RENAME TO name
    9675 ECB             :                 {
    9676 GIC          15 :                     RenameStmt *n = makeNode(RenameStmt);
    9677 ECB             : 
    9678 CBC          15 :                     n->renameType = OBJECT_STATISTIC_EXT;
    9679              15 :                     n->object = (Node *) $3;
    9680              15 :                     n->newname = $6;
    9681              15 :                     n->missing_ok = false;
    9682              15 :                     $$ = (Node *) n;
    9683                 :                 }
    9684                 :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
    9685                 :                 {
    9686               6 :                     RenameStmt *n = makeNode(RenameStmt);
    9687                 : 
    9688               6 :                     n->renameType = OBJECT_TSPARSER;
    9689               6 :                     n->object = (Node *) $5;
    9690               6 :                     n->newname = $8;
    9691               6 :                     n->missing_ok = false;
    9692               6 :                     $$ = (Node *) n;
    9693 ECB             :                 }
    9694                 :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
    9695                 :                 {
    9696 GIC          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9697                 : 
    9698 CBC          12 :                     n->renameType = OBJECT_TSDICTIONARY;
    9699 GIC          12 :                     n->object = (Node *) $5;
    9700 CBC          12 :                     n->newname = $8;
    9701              12 :                     n->missing_ok = false;
    9702              12 :                     $$ = (Node *) n;
    9703 ECB             :                 }
    9704                 :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
    9705                 :                 {
    9706 CBC           6 :                     RenameStmt *n = makeNode(RenameStmt);
    9707                 : 
    9708 GIC           6 :                     n->renameType = OBJECT_TSTEMPLATE;
    9709               6 :                     n->object = (Node *) $5;
    9710 CBC           6 :                     n->newname = $8;
    9711 GIC           6 :                     n->missing_ok = false;
    9712 CBC           6 :                     $$ = (Node *) n;
    9713 ECB             :                 }
    9714                 :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
    9715                 :                 {
    9716 CBC          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9717 ECB             : 
    9718 GIC          12 :                     n->renameType = OBJECT_TSCONFIGURATION;
    9719              12 :                     n->object = (Node *) $5;
    9720              12 :                     n->newname = $8;
    9721 CBC          12 :                     n->missing_ok = false;
    9722 GIC          12 :                     $$ = (Node *) n;
    9723 ECB             :                 }
    9724                 :             | ALTER TYPE_P any_name RENAME TO name
    9725                 :                 {
    9726 CBC          13 :                     RenameStmt *n = makeNode(RenameStmt);
    9727 ECB             : 
    9728 CBC          13 :                     n->renameType = OBJECT_TYPE;
    9729 GIC          13 :                     n->object = (Node *) $3;
    9730              13 :                     n->newname = $6;
    9731              13 :                     n->missing_ok = false;
    9732 CBC          13 :                     $$ = (Node *) n;
    9733                 :                 }
    9734 ECB             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
    9735                 :                 {
    9736 CBC          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9737 ECB             : 
    9738 GIC          12 :                     n->renameType = OBJECT_ATTRIBUTE;
    9739              12 :                     n->relationType = OBJECT_TYPE;
    9740              12 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    9741 CBC          12 :                     n->subname = $6;
    9742 GIC          12 :                     n->newname = $8;
    9743 CBC          12 :                     n->behavior = $9;
    9744              12 :                     n->missing_ok = false;
    9745              12 :                     $$ = (Node *) n;
    9746 ECB             :                 }
    9747                 :         ;
    9748                 : 
    9749                 : opt_column: COLUMN
    9750                 :             | /*EMPTY*/
    9751 EUB             :         ;
    9752                 : 
    9753 GBC          73 : opt_set_data: SET DATA_P                            { $$ = 1; }
    9754             376 :             | /*EMPTY*/                             { $$ = 0; }
    9755 EUB             :         ;
    9756                 : 
    9757                 : /*****************************************************************************
    9758                 :  *
    9759                 :  * ALTER THING name DEPENDS ON EXTENSION name
    9760                 :  *
    9761 ECB             :  *****************************************************************************/
    9762                 : 
    9763                 : AlterObjectDependsStmt:
    9764                 :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9765                 :                 {
    9766 CBC           6 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9767 ECB             : 
    9768 GIC           6 :                     n->objectType = OBJECT_FUNCTION;
    9769               6 :                     n->object = (Node *) $3;
    9770               6 :                     n->extname = makeString($8);
    9771 CBC           6 :                     n->remove = $4;
    9772 GIC           6 :                     $$ = (Node *) n;
    9773 ECB             :                 }
    9774                 :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9775                 :                 {
    9776 LBC           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9777 ECB             : 
    9778 UIC           0 :                     n->objectType = OBJECT_PROCEDURE;
    9779               0 :                     n->object = (Node *) $3;
    9780               0 :                     n->extname = makeString($8);
    9781 LBC           0 :                     n->remove = $4;
    9782 UIC           0 :                     $$ = (Node *) n;
    9783 ECB             :                 }
    9784                 :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
    9785                 :                 {
    9786 LBC           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9787 ECB             : 
    9788 UIC           0 :                     n->objectType = OBJECT_ROUTINE;
    9789               0 :                     n->object = (Node *) $3;
    9790               0 :                     n->extname = makeString($8);
    9791 LBC           0 :                     n->remove = $4;
    9792 UIC           0 :                     $$ = (Node *) n;
    9793 ECB             :                 }
    9794                 :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
    9795                 :                 {
    9796 CBC           5 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9797 ECB             : 
    9798 GIC           5 :                     n->objectType = OBJECT_TRIGGER;
    9799               5 :                     n->relation = $5;
    9800               5 :                     n->object = (Node *) list_make1(makeString($3));
    9801 CBC           5 :                     n->extname = makeString($10);
    9802 GIC           5 :                     n->remove = $6;
    9803 CBC           5 :                     $$ = (Node *) n;
    9804 ECB             :                 }
    9805                 :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
    9806                 :                 {
    9807 CBC           5 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9808                 : 
    9809 GIC           5 :                     n->objectType = OBJECT_MATVIEW;
    9810               5 :                     n->relation = $4;
    9811 CBC           5 :                     n->extname = makeString($9);
    9812 GIC           5 :                     n->remove = $5;
    9813 CBC           5 :                     $$ = (Node *) n;
    9814 ECB             :                 }
    9815                 :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
    9816                 :                 {
    9817 CBC           7 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
    9818                 : 
    9819 GIC           7 :                     n->objectType = OBJECT_INDEX;
    9820               7 :                     n->relation = $3;
    9821 CBC           7 :                     n->extname = makeString($8);
    9822 GIC           7 :                     n->remove = $4;
    9823 CBC           7 :                     $$ = (Node *) n;
    9824 ECB             :                 }
    9825                 :         ;
    9826                 : 
    9827 CBC           4 : opt_no:     NO              { $$ = true; }
    9828 GIC          19 :             | /* EMPTY */   { $$ = false;   }
    9829                 :         ;
    9830                 : 
    9831 ECB             : /*****************************************************************************
    9832                 :  *
    9833                 :  * ALTER THING name SET SCHEMA name
    9834                 :  *
    9835                 :  *****************************************************************************/
    9836                 : 
    9837                 : AlterObjectSchemaStmt:
    9838                 :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
    9839                 :                 {
    9840 CBC          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9841                 : 
    9842 GIC          12 :                     n->objectType = OBJECT_AGGREGATE;
    9843              12 :                     n->object = (Node *) $3;
    9844              12 :                     n->newschema = $6;
    9845              12 :                     n->missing_ok = false;
    9846              12 :                     $$ = (Node *) n;
    9847                 :                 }
    9848 ECB             :             | ALTER COLLATION any_name SET SCHEMA name
    9849                 :                 {
    9850 GIC           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9851                 : 
    9852               6 :                     n->objectType = OBJECT_COLLATION;
    9853               6 :                     n->object = (Node *) $3;
    9854               6 :                     n->newschema = $6;
    9855               6 :                     n->missing_ok = false;
    9856               6 :                     $$ = (Node *) n;
    9857                 :                 }
    9858                 :             | ALTER CONVERSION_P any_name SET SCHEMA name
    9859                 :                 {
    9860              12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9861 ECB             : 
    9862 GIC          12 :                     n->objectType = OBJECT_CONVERSION;
    9863 CBC          12 :                     n->object = (Node *) $3;
    9864              12 :                     n->newschema = $6;
    9865              12 :                     n->missing_ok = false;
    9866              12 :                     $$ = (Node *) n;
    9867 ECB             :                 }
    9868                 :             | ALTER DOMAIN_P any_name SET SCHEMA name
    9869                 :                 {
    9870 GIC           3 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9871 EUB             : 
    9872 GIC           3 :                     n->objectType = OBJECT_DOMAIN;
    9873 GBC           3 :                     n->object = (Node *) $3;
    9874               3 :                     n->newschema = $6;
    9875               3 :                     n->missing_ok = false;
    9876               3 :                     $$ = (Node *) n;
    9877 EUB             :                 }
    9878                 :             | ALTER EXTENSION name SET SCHEMA name
    9879                 :                 {
    9880 GIC           3 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9881 EUB             : 
    9882 GIC           3 :                     n->objectType = OBJECT_EXTENSION;
    9883 GBC           3 :                     n->object = (Node *) makeString($3);
    9884               3 :                     n->newschema = $6;
    9885               3 :                     n->missing_ok = false;
    9886               3 :                     $$ = (Node *) n;
    9887 EUB             :                 }
    9888                 :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
    9889                 :                 {
    9890 GIC          19 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9891 ECB             : 
    9892 GIC          19 :                     n->objectType = OBJECT_FUNCTION;
    9893 CBC          19 :                     n->object = (Node *) $3;
    9894              19 :                     n->newschema = $6;
    9895              19 :                     n->missing_ok = false;
    9896              19 :                     $$ = (Node *) n;
    9897 ECB             :                 }
    9898                 :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
    9899                 :                 {
    9900 GIC           9 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9901                 : 
    9902 CBC           9 :                     n->objectType = OBJECT_OPERATOR;
    9903 GIC           9 :                     n->object = (Node *) $3;
    9904 CBC           9 :                     n->newschema = $6;
    9905               9 :                     n->missing_ok = false;
    9906               9 :                     $$ = (Node *) n;
    9907 ECB             :                 }
    9908                 :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
    9909                 :                 {
    9910 GIC          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9911                 : 
    9912 CBC          12 :                     n->objectType = OBJECT_OPCLASS;
    9913 GIC          12 :                     n->object = (Node *) lcons(makeString($6), $4);
    9914 CBC          12 :                     n->newschema = $9;
    9915              12 :                     n->missing_ok = false;
    9916              12 :                     $$ = (Node *) n;
    9917 ECB             :                 }
    9918                 :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
    9919                 :                 {
    9920 GIC          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9921                 : 
    9922 CBC          12 :                     n->objectType = OBJECT_OPFAMILY;
    9923              12 :                     n->object = (Node *) lcons(makeString($6), $4);
    9924 GIC          12 :                     n->newschema = $9;
    9925              12 :                     n->missing_ok = false;
    9926              12 :                     $$ = (Node *) n;
    9927                 :                 }
    9928                 :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
    9929                 :                 {
    9930 UIC           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9931                 : 
    9932               0 :                     n->objectType = OBJECT_PROCEDURE;
    9933               0 :                     n->object = (Node *) $3;
    9934               0 :                     n->newschema = $6;
    9935 LBC           0 :                     n->missing_ok = false;
    9936 UIC           0 :                     $$ = (Node *) n;
    9937 ECB             :                 }
    9938                 :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
    9939                 :                 {
    9940 LBC           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9941 ECB             : 
    9942 UIC           0 :                     n->objectType = OBJECT_ROUTINE;
    9943               0 :                     n->object = (Node *) $3;
    9944               0 :                     n->newschema = $6;
    9945 LBC           0 :                     n->missing_ok = false;
    9946 UIC           0 :                     $$ = (Node *) n;
    9947 ECB             :                 }
    9948                 :             | ALTER TABLE relation_expr SET SCHEMA name
    9949                 :                 {
    9950 CBC          33 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9951 ECB             : 
    9952 GIC          33 :                     n->objectType = OBJECT_TABLE;
    9953              33 :                     n->relation = $3;
    9954              33 :                     n->newschema = $6;
    9955 CBC          33 :                     n->missing_ok = false;
    9956 GIC          33 :                     $$ = (Node *) n;
    9957 ECB             :                 }
    9958                 :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
    9959                 :                 {
    9960 CBC           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9961 ECB             : 
    9962 GIC           6 :                     n->objectType = OBJECT_TABLE;
    9963               6 :                     n->relation = $5;
    9964               6 :                     n->newschema = $8;
    9965 CBC           6 :                     n->missing_ok = true;
    9966 GIC           6 :                     $$ = (Node *) n;
    9967 ECB             :                 }
    9968                 :             | ALTER STATISTICS any_name SET SCHEMA name
    9969                 :                 {
    9970 CBC           9 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9971 ECB             : 
    9972 GIC           9 :                     n->objectType = OBJECT_STATISTIC_EXT;
    9973               9 :                     n->object = (Node *) $3;
    9974               9 :                     n->newschema = $6;
    9975 CBC           9 :                     n->missing_ok = false;
    9976 GIC           9 :                     $$ = (Node *) n;
    9977 ECB             :                 }
    9978                 :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
    9979                 :                 {
    9980 CBC           9 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9981 ECB             : 
    9982 GIC           9 :                     n->objectType = OBJECT_TSPARSER;
    9983               9 :                     n->object = (Node *) $5;
    9984               9 :                     n->newschema = $8;
    9985 CBC           9 :                     n->missing_ok = false;
    9986 GIC           9 :                     $$ = (Node *) n;
    9987 ECB             :                 }
    9988                 :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
    9989                 :                 {
    9990 CBC          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
    9991 ECB             : 
    9992 GIC          12 :                     n->objectType = OBJECT_TSDICTIONARY;
    9993              12 :                     n->object = (Node *) $5;
    9994              12 :                     n->newschema = $8;
    9995 CBC          12 :                     n->missing_ok = false;
    9996 GIC          12 :                     $$ = (Node *) n;
    9997 ECB             :                 }
    9998                 :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
    9999                 :                 {
   10000 CBC           9 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10001 ECB             : 
   10002 GIC           9 :                     n->objectType = OBJECT_TSTEMPLATE;
   10003               9 :                     n->object = (Node *) $5;
   10004               9 :                     n->newschema = $8;
   10005 CBC           9 :                     n->missing_ok = false;
   10006 GIC           9 :                     $$ = (Node *) n;
   10007 ECB             :                 }
   10008                 :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10009                 :                 {
   10010 CBC          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10011 ECB             : 
   10012 GIC          12 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10013              12 :                     n->object = (Node *) $5;
   10014              12 :                     n->newschema = $8;
   10015 CBC          12 :                     n->missing_ok = false;
   10016 GIC          12 :                     $$ = (Node *) n;
   10017 ECB             :                 }
   10018                 :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10019                 :                 {
   10020 CBC           1 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10021 ECB             : 
   10022 GIC           1 :                     n->objectType = OBJECT_SEQUENCE;
   10023               1 :                     n->relation = $3;
   10024               1 :                     n->newschema = $6;
   10025 GBC           1 :                     n->missing_ok = false;
   10026 GIC           1 :                     $$ = (Node *) n;
   10027 EUB             :                 }
   10028                 :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10029                 :                 {
   10030 UBC           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10031 EUB             : 
   10032 UIC           0 :                     n->objectType = OBJECT_SEQUENCE;
   10033               0 :                     n->relation = $5;
   10034               0 :                     n->newschema = $8;
   10035 UBC           0 :                     n->missing_ok = true;
   10036 UIC           0 :                     $$ = (Node *) n;
   10037 EUB             :                 }
   10038                 :             | ALTER VIEW qualified_name SET SCHEMA name
   10039                 :                 {
   10040 UBC           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10041 EUB             : 
   10042 UIC           0 :                     n->objectType = OBJECT_VIEW;
   10043               0 :                     n->relation = $3;
   10044               0 :                     n->newschema = $6;
   10045 LBC           0 :                     n->missing_ok = false;
   10046 UIC           0 :                     $$ = (Node *) n;
   10047 ECB             :                 }
   10048                 :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10049                 :                 {
   10050 LBC           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10051 ECB             : 
   10052 UIC           0 :                     n->objectType = OBJECT_VIEW;
   10053               0 :                     n->relation = $5;
   10054               0 :                     n->newschema = $8;
   10055 LBC           0 :                     n->missing_ok = true;
   10056 UIC           0 :                     $$ = (Node *) n;
   10057 ECB             :                 }
   10058                 :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10059                 :                 {
   10060 CBC           3 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10061 ECB             : 
   10062 GIC           3 :                     n->objectType = OBJECT_MATVIEW;
   10063               3 :                     n->relation = $4;
   10064               3 :                     n->newschema = $7;
   10065 CBC           3 :                     n->missing_ok = false;
   10066 GIC           3 :                     $$ = (Node *) n;
   10067 ECB             :                 }
   10068                 :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10069                 :                 {
   10070 LBC           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10071 ECB             : 
   10072 UIC           0 :                     n->objectType = OBJECT_MATVIEW;
   10073               0 :                     n->relation = $6;
   10074               0 :                     n->newschema = $9;
   10075 LBC           0 :                     n->missing_ok = true;
   10076 UIC           0 :                     $$ = (Node *) n;
   10077 ECB             :                 }
   10078                 :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10079                 :                 {
   10080 CBC           3 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10081 ECB             : 
   10082 GIC           3 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10083               3 :                     n->relation = $4;
   10084               3 :                     n->newschema = $7;
   10085 CBC           3 :                     n->missing_ok = false;
   10086 GIC           3 :                     $$ = (Node *) n;
   10087 ECB             :                 }
   10088                 :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10089                 :                 {
   10090 CBC           3 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10091 ECB             : 
   10092 GIC           3 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10093               3 :                     n->relation = $6;
   10094               3 :                     n->newschema = $9;
   10095 CBC           3 :                     n->missing_ok = true;
   10096 GIC           3 :                     $$ = (Node *) n;
   10097 ECB             :                 }
   10098                 :             | ALTER TYPE_P any_name SET SCHEMA name
   10099                 :                 {
   10100 CBC           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10101 ECB             : 
   10102 GIC           6 :                     n->objectType = OBJECT_TYPE;
   10103               6 :                     n->object = (Node *) $3;
   10104               6 :                     n->newschema = $6;
   10105 CBC           6 :                     n->missing_ok = false;
   10106 GIC           6 :                     $$ = (Node *) n;
   10107 ECB             :                 }
   10108                 :         ;
   10109                 : 
   10110                 : /*****************************************************************************
   10111                 :  *
   10112                 :  * ALTER OPERATOR name SET define
   10113                 :  *
   10114                 :  *****************************************************************************/
   10115                 : 
   10116                 : AlterOperatorStmt:
   10117                 :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10118                 :                 {
   10119 CBC         258 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10120 ECB             : 
   10121 CBC         258 :                     n->opername = $3;
   10122 GIC         258 :                     n->options = $6;
   10123             258 :                     $$ = (Node *) n;
   10124                 :                 }
   10125 EUB             :         ;
   10126                 : 
   10127 GBC         288 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10128             251 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10129 EUB             :         ;
   10130                 : 
   10131                 : operator_def_elem: ColLabel '=' NONE
   10132 GIC          15 :                         { $$ = makeDefElem($1, NULL, @1); }
   10133                 :                    | ColLabel '=' operator_def_arg
   10134             524 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10135 EUB             :         ;
   10136                 : 
   10137                 : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10138                 : operator_def_arg:
   10139 GBC         512 :             func_type                       { $$ = (Node *) $1; }
   10140 UBC           0 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10141 GBC          12 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10142 UIC           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10143               0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10144                 :         ;
   10145 EUB             : 
   10146                 : /*****************************************************************************
   10147                 :  *
   10148                 :  * ALTER TYPE name SET define
   10149                 :  *
   10150                 :  * We repurpose ALTER OPERATOR's version of "definition" here
   10151                 :  *
   10152                 :  *****************************************************************************/
   10153                 : 
   10154                 : AlterTypeStmt:
   10155 ECB             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10156                 :                 {
   10157 CBC          30 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10158 ECB             : 
   10159 CBC          30 :                     n->typeName = $3;
   10160              30 :                     n->options = $6;
   10161              30 :                     $$ = (Node *) n;
   10162                 :                 }
   10163                 :         ;
   10164                 : 
   10165 EUB             : /*****************************************************************************
   10166                 :  *
   10167                 :  * ALTER THING name OWNER TO newname
   10168                 :  *
   10169                 :  *****************************************************************************/
   10170                 : 
   10171                 : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10172                 :                 {
   10173 GIC          71 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10174                 : 
   10175 CBC          71 :                     n->objectType = OBJECT_AGGREGATE;
   10176 GIC          71 :                     n->object = (Node *) $3;
   10177 CBC          71 :                     n->newowner = $6;
   10178              71 :                     $$ = (Node *) n;
   10179 ECB             :                 }
   10180                 :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10181                 :                 {
   10182 GIC          13 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10183                 : 
   10184              13 :                     n->objectType = OBJECT_COLLATION;
   10185 CBC          13 :                     n->object = (Node *) $3;
   10186 GIC          13 :                     n->newowner = $6;
   10187 CBC          13 :                     $$ = (Node *) n;
   10188 ECB             :                 }
   10189                 :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10190                 :                 {
   10191 CBC          12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10192                 : 
   10193 GIC          12 :                     n->objectType = OBJECT_CONVERSION;
   10194              12 :                     n->object = (Node *) $3;
   10195 CBC          12 :                     n->newowner = $6;
   10196 GIC          12 :                     $$ = (Node *) n;
   10197 ECB             :                 }
   10198                 :             | ALTER DATABASE name OWNER TO RoleSpec
   10199                 :                 {
   10200 CBC          18 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10201 ECB             : 
   10202 GIC          18 :                     n->objectType = OBJECT_DATABASE;
   10203              18 :                     n->object = (Node *) makeString($3);
   10204              18 :                     n->newowner = $6;
   10205              18 :                     $$ = (Node *) n;
   10206                 :                 }
   10207                 :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10208                 :                 {
   10209              17 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10210                 : 
   10211              17 :                     n->objectType = OBJECT_DOMAIN;
   10212              17 :                     n->object = (Node *) $3;
   10213              17 :                     n->newowner = $6;
   10214 CBC          17 :                     $$ = (Node *) n;
   10215                 :                 }
   10216 ECB             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10217                 :                 {
   10218 CBC         280 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10219                 : 
   10220 GIC         280 :                     n->objectType = OBJECT_FUNCTION;
   10221             280 :                     n->object = (Node *) $3;
   10222 CBC         280 :                     n->newowner = $6;
   10223             280 :                     $$ = (Node *) n;
   10224                 :                 }
   10225                 :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10226                 :                 {
   10227             326 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10228                 : 
   10229             326 :                     n->objectType = OBJECT_LANGUAGE;
   10230 GIC         326 :                     n->object = (Node *) makeString($4);
   10231             326 :                     n->newowner = $7;
   10232             326 :                     $$ = (Node *) n;
   10233                 :                 }
   10234 ECB             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10235 EUB             :                 {
   10236 CBC           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10237 EUB             : 
   10238 GBC           6 :                     n->objectType = OBJECT_LARGEOBJECT;
   10239 GIC           6 :                     n->object = (Node *) $4;
   10240               6 :                     n->newowner = $7;
   10241               6 :                     $$ = (Node *) n;
   10242                 :                 }
   10243                 :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10244                 :                 {
   10245              23 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10246                 : 
   10247              23 :                     n->objectType = OBJECT_OPERATOR;
   10248              23 :                     n->object = (Node *) $3;
   10249              23 :                     n->newowner = $6;
   10250              23 :                     $$ = (Node *) n;
   10251                 :                 }
   10252 ECB             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10253                 :                 {
   10254 CBC          27 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10255 ECB             : 
   10256 CBC          27 :                     n->objectType = OBJECT_OPCLASS;
   10257 GIC          27 :                     n->object = (Node *) lcons(makeString($6), $4);
   10258              27 :                     n->newowner = $9;
   10259              27 :                     $$ = (Node *) n;
   10260                 :                 }
   10261                 :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10262                 :                 {
   10263              31 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10264                 : 
   10265              31 :                     n->objectType = OBJECT_OPFAMILY;
   10266              31 :                     n->object = (Node *) lcons(makeString($6), $4);
   10267              31 :                     n->newowner = $9;
   10268 CBC          31 :                     $$ = (Node *) n;
   10269                 :                 }
   10270 ECB             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10271                 :                 {
   10272 CBC           9 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10273 ECB             : 
   10274 GIC           9 :                     n->objectType = OBJECT_PROCEDURE;
   10275               9 :                     n->object = (Node *) $3;
   10276               9 :                     n->newowner = $6;
   10277 CBC           9 :                     $$ = (Node *) n;
   10278                 :                 }
   10279 ECB             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10280                 :                 {
   10281 LBC           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10282 ECB             : 
   10283 UIC           0 :                     n->objectType = OBJECT_ROUTINE;
   10284               0 :                     n->object = (Node *) $3;
   10285               0 :                     n->newowner = $6;
   10286 LBC           0 :                     $$ = (Node *) n;
   10287                 :                 }
   10288 ECB             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10289                 :                 {
   10290 CBC          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10291 ECB             : 
   10292 GIC          26 :                     n->objectType = OBJECT_SCHEMA;
   10293              26 :                     n->object = (Node *) makeString($3);
   10294              26 :                     n->newowner = $6;
   10295 CBC          26 :                     $$ = (Node *) n;
   10296                 :                 }
   10297 ECB             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10298                 :                 {
   10299 CBC          31 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10300 ECB             : 
   10301 GIC          31 :                     n->objectType = OBJECT_TYPE;
   10302              31 :                     n->object = (Node *) $3;
   10303              31 :                     n->newowner = $6;
   10304 CBC          31 :                     $$ = (Node *) n;
   10305                 :                 }
   10306 ECB             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10307                 :                 {
   10308 CBC           3 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10309 ECB             : 
   10310 GIC           3 :                     n->objectType = OBJECT_TABLESPACE;
   10311               3 :                     n->object = (Node *) makeString($3);
   10312               3 :                     n->newowner = $6;
   10313 CBC           3 :                     $$ = (Node *) n;
   10314                 :                 }
   10315 ECB             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10316                 :                 {
   10317 CBC          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10318 ECB             : 
   10319 GIC          16 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10320              16 :                     n->object = (Node *) $3;
   10321              16 :                     n->newowner = $6;
   10322 CBC          16 :                     $$ = (Node *) n;
   10323                 :                 }
   10324 ECB             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10325                 :                 {
   10326 CBC          21 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10327 ECB             : 
   10328 GIC          21 :                     n->objectType = OBJECT_TSDICTIONARY;
   10329              21 :                     n->object = (Node *) $5;
   10330              21 :                     n->newowner = $8;
   10331 CBC          21 :                     $$ = (Node *) n;
   10332                 :                 }
   10333 ECB             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10334                 :                 {
   10335 CBC          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10336 ECB             : 
   10337 GIC          16 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10338              16 :                     n->object = (Node *) $5;
   10339              16 :                     n->newowner = $8;
   10340 CBC          16 :                     $$ = (Node *) n;
   10341                 :                 }
   10342 ECB             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10343                 :                 {
   10344 CBC          10 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10345 ECB             : 
   10346 GIC          10 :                     n->objectType = OBJECT_FDW;
   10347              10 :                     n->object = (Node *) makeString($5);
   10348              10 :                     n->newowner = $8;
   10349 CBC          10 :                     $$ = (Node *) n;
   10350                 :                 }
   10351 ECB             :             | ALTER SERVER name OWNER TO RoleSpec
   10352                 :                 {
   10353 CBC          34 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10354 ECB             : 
   10355 GIC          34 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10356              34 :                     n->object = (Node *) makeString($3);
   10357              34 :                     n->newowner = $6;
   10358 CBC          34 :                     $$ = (Node *) n;
   10359                 :                 }
   10360 ECB             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10361                 :                 {
   10362 CBC           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10363 ECB             : 
   10364 GIC           6 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10365               6 :                     n->object = (Node *) makeString($4);
   10366               6 :                     n->newowner = $7;
   10367 CBC           6 :                     $$ = (Node *) n;
   10368                 :                 }
   10369 ECB             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10370                 :                 {
   10371 CBC          12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10372 ECB             : 
   10373 GIC          12 :                     n->objectType = OBJECT_PUBLICATION;
   10374              12 :                     n->object = (Node *) makeString($3);
   10375              12 :                     n->newowner = $6;
   10376 GBC          12 :                     $$ = (Node *) n;
   10377                 :                 }
   10378 EUB             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10379                 :                 {
   10380 GBC           6 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10381 EUB             : 
   10382 GIC           6 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10383               6 :                     n->object = (Node *) makeString($3);
   10384               6 :                     n->newowner = $6;
   10385 CBC           6 :                     $$ = (Node *) n;
   10386                 :                 }
   10387 ECB             :         ;
   10388                 : 
   10389                 : 
   10390                 : /*****************************************************************************
   10391                 :  *
   10392                 :  * CREATE PUBLICATION name [WITH options]
   10393                 :  *
   10394                 :  * CREATE PUBLICATION FOR ALL TABLES [WITH options]
   10395                 :  *
   10396                 :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10397                 :  *
   10398                 :  * pub_obj is one of:
   10399                 :  *
   10400                 :  *      TABLE table [, ...]
   10401                 :  *      TABLES IN SCHEMA schema [, ...]
   10402                 :  *
   10403                 :  *****************************************************************************/
   10404                 : 
   10405                 : CreatePublicationStmt:
   10406                 :             CREATE PUBLICATION name opt_definition
   10407                 :                 {
   10408 CBC          51 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10409                 : 
   10410 GIC          51 :                     n->pubname = $3;
   10411              51 :                     n->options = $4;
   10412 CBC          51 :                     $$ = (Node *) n;
   10413                 :                 }
   10414 ECB             :             | CREATE PUBLICATION name FOR ALL TABLES opt_definition
   10415                 :                 {
   10416 CBC          24 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10417 ECB             : 
   10418 GIC          24 :                     n->pubname = $3;
   10419              24 :                     n->options = $7;
   10420              24 :                     n->for_all_tables = true;
   10421 CBC          24 :                     $$ = (Node *) n;
   10422                 :                 }
   10423 ECB             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10424                 :                 {
   10425 CBC         262 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10426 ECB             : 
   10427 GIC         262 :                     n->pubname = $3;
   10428             262 :                     n->options = $6;
   10429             262 :                     n->pubobjects = (List *) $5;
   10430 CBC         262 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10431 GIC         253 :                     $$ = (Node *) n;
   10432 ECB             :                 }
   10433                 :         ;
   10434                 : 
   10435                 : /*
   10436                 :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10437                 :  *
   10438                 :  * This rule parses publication objects with and without keyword prefixes.
   10439                 :  *
   10440                 :  * The actual type of the object without keyword prefix depends on the previous
   10441                 :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10442                 :  *
   10443                 :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10444                 :  * because some extended expressions in relation_expr cannot be used as a
   10445                 :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10446                 :  * relation_expr here.
   10447                 :  */
   10448                 : PublicationObjSpec:
   10449                 :             TABLE relation_expr opt_column_list OptWhereClause
   10450                 :                 {
   10451 CBC         566 :                     $$ = makeNode(PublicationObjSpec);
   10452             566 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10453             566 :                     $$->pubtable = makeNode(PublicationTable);
   10454 GIC         566 :                     $$->pubtable->relation = $2;
   10455             566 :                     $$->pubtable->columns = $3;
   10456             566 :                     $$->pubtable->whereClause = $4;
   10457 ECB             :                 }
   10458                 :             | TABLES IN_P SCHEMA ColId
   10459                 :                 {
   10460 CBC         163 :                     $$ = makeNode(PublicationObjSpec);
   10461             163 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10462             163 :                     $$->name = $4;
   10463 GIC         163 :                     $$->location = @4;
   10464                 :                 }
   10465                 :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10466 ECB             :                 {
   10467 GIC           9 :                     $$ = makeNode(PublicationObjSpec);
   10468 CBC           9 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10469               9 :                     $$->location = @4;
   10470 ECB             :                 }
   10471                 :             | ColId opt_column_list OptWhereClause
   10472                 :                 {
   10473 GIC          64 :                     $$ = makeNode(PublicationObjSpec);
   10474              64 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10475 ECB             :                     /*
   10476                 :                      * If either a row filter or column list is specified, create
   10477                 :                      * a PublicationTable object.
   10478                 :                      */
   10479 CBC          64 :                     if ($2 || $3)
   10480 ECB             :                     {
   10481                 :                         /*
   10482                 :                          * The OptWhereClause must be stored here but it is
   10483                 :                          * valid only for tables. For non-table objects, an
   10484                 :                          * error will be thrown later via
   10485                 :                          * preprocess_pubobj_list().
   10486                 :                          */
   10487 GIC          21 :                         $$->pubtable = makeNode(PublicationTable);
   10488              21 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10489              21 :                         $$->pubtable->columns = $2;
   10490              21 :                         $$->pubtable->whereClause = $3;
   10491                 :                     }
   10492                 :                     else
   10493                 :                     {
   10494              43 :                         $$->name = $1;
   10495                 :                     }
   10496              64 :                     $$->location = @1;
   10497                 :                 }
   10498                 :             | ColId indirection opt_column_list OptWhereClause
   10499                 :                 {
   10500              13 :                     $$ = makeNode(PublicationObjSpec);
   10501              13 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10502              13 :                     $$->pubtable = makeNode(PublicationTable);
   10503 CBC          13 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10504 GIC          13 :                     $$->pubtable->columns = $3;
   10505 CBC          13 :                     $$->pubtable->whereClause = $4;
   10506              13 :                     $$->location = @1;
   10507 ECB             :                 }
   10508                 :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10509                 :             | extended_relation_expr opt_column_list OptWhereClause
   10510                 :                 {
   10511 CBC           3 :                     $$ = makeNode(PublicationObjSpec);
   10512 GIC           3 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10513 CBC           3 :                     $$->pubtable = makeNode(PublicationTable);
   10514               3 :                     $$->pubtable->relation = $1;
   10515               3 :                     $$->pubtable->columns = $2;
   10516               3 :                     $$->pubtable->whereClause = $3;
   10517                 :                 }
   10518                 :             | CURRENT_SCHEMA
   10519                 :                 {
   10520               6 :                     $$ = makeNode(PublicationObjSpec);
   10521 GIC           6 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10522 CBC           6 :                     $$->location = @1;
   10523 ECB             :                 }
   10524                 :                 ;
   10525                 : 
   10526                 : pub_obj_list:   PublicationObjSpec
   10527 GIC         719 :                     { $$ = list_make1($1); }
   10528                 :             | pub_obj_list ',' PublicationObjSpec
   10529             105 :                     { $$ = lappend($1, $3); }
   10530                 :     ;
   10531                 : 
   10532                 : /*****************************************************************************
   10533                 :  *
   10534                 :  * ALTER PUBLICATION name SET ( options )
   10535                 :  *
   10536                 :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10537                 :  *
   10538                 :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10539                 :  *
   10540                 :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10541                 :  *
   10542                 :  * pub_obj is one of:
   10543                 :  *
   10544                 :  *      TABLE table_name [, ...]
   10545                 :  *      TABLES IN SCHEMA schema_name [, ...]
   10546 ECB             :  *
   10547                 :  *****************************************************************************/
   10548                 : 
   10549                 : AlterPublicationStmt:
   10550                 :             ALTER PUBLICATION name SET definition
   10551                 :                 {
   10552 GIC          55 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10553                 : 
   10554              55 :                     n->pubname = $3;
   10555 CBC          55 :                     n->options = $5;
   10556              55 :                     $$ = (Node *) n;
   10557 ECB             :                 }
   10558                 :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10559                 :                 {
   10560 GIC         163 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10561                 : 
   10562 CBC         163 :                     n->pubname = $3;
   10563             163 :                     n->pubobjects = $5;
   10564             163 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10565 GIC         160 :                     n->action = AP_AddObjects;
   10566             160 :                     $$ = (Node *) n;
   10567                 :                 }
   10568 ECB             :             | ALTER PUBLICATION name SET pub_obj_list
   10569                 :                 {
   10570 GIC         220 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10571                 : 
   10572             220 :                     n->pubname = $3;
   10573             220 :                     n->pubobjects = $5;
   10574 CBC         220 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10575 GIC         220 :                     n->action = AP_SetObjects;
   10576             220 :                     $$ = (Node *) n;
   10577                 :                 }
   10578                 :             | ALTER PUBLICATION name DROP pub_obj_list
   10579                 :                 {
   10580              74 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10581                 : 
   10582 CBC          74 :                     n->pubname = $3;
   10583              74 :                     n->pubobjects = $5;
   10584              74 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10585              74 :                     n->action = AP_DropObjects;
   10586 GIC          74 :                     $$ = (Node *) n;
   10587                 :                 }
   10588                 :         ;
   10589 ECB             : 
   10590                 : /*****************************************************************************
   10591                 :  *
   10592                 :  * CREATE SUBSCRIPTION name ...
   10593                 :  *
   10594                 :  *****************************************************************************/
   10595                 : 
   10596                 : CreateSubscriptionStmt:
   10597                 :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   10598                 :                 {
   10599 CBC         177 :                     CreateSubscriptionStmt *n =
   10600             177 :                         makeNode(CreateSubscriptionStmt);
   10601             177 :                     n->subname = $3;
   10602 GIC         177 :                     n->conninfo = $5;
   10603             177 :                     n->publication = $7;
   10604             177 :                     n->options = $8;
   10605             177 :                     $$ = (Node *) n;
   10606 ECB             :                 }
   10607                 :         ;
   10608                 : 
   10609                 : /*****************************************************************************
   10610                 :  *
   10611                 :  * ALTER SUBSCRIPTION name ...
   10612                 :  *
   10613                 :  *****************************************************************************/
   10614                 : 
   10615                 : AlterSubscriptionStmt:
   10616                 :             ALTER SUBSCRIPTION name SET definition
   10617                 :                 {
   10618 GIC          78 :                     AlterSubscriptionStmt *n =
   10619              78 :                         makeNode(AlterSubscriptionStmt);
   10620                 : 
   10621              78 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   10622 CBC          78 :                     n->subname = $3;
   10623 GIC          78 :                     n->options = $5;
   10624 CBC          78 :                     $$ = (Node *) n;
   10625                 :                 }
   10626                 :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   10627                 :                 {
   10628 GIC          10 :                     AlterSubscriptionStmt *n =
   10629              10 :                         makeNode(AlterSubscriptionStmt);
   10630                 : 
   10631              10 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   10632              10 :                     n->subname = $3;
   10633              10 :                     n->conninfo = $5;
   10634              10 :                     $$ = (Node *) n;
   10635                 :                 }
   10636                 :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   10637                 :                 {
   10638              26 :                     AlterSubscriptionStmt *n =
   10639              26 :                         makeNode(AlterSubscriptionStmt);
   10640                 : 
   10641              26 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH;
   10642              26 :                     n->subname = $3;
   10643              26 :                     n->options = $6;
   10644              26 :                     $$ = (Node *) n;
   10645                 :                 }
   10646                 :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   10647 ECB             :                 {
   10648 GIC          14 :                     AlterSubscriptionStmt *n =
   10649 CBC          14 :                         makeNode(AlterSubscriptionStmt);
   10650 ECB             : 
   10651 CBC          14 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   10652 GIC          14 :                     n->subname = $3;
   10653              14 :                     n->publication = $6;
   10654              14 :                     n->options = $7;
   10655 CBC          14 :                     $$ = (Node *) n;
   10656                 :                 }
   10657 ECB             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   10658                 :                 {
   10659 CBC          13 :                     AlterSubscriptionStmt *n =
   10660              13 :                         makeNode(AlterSubscriptionStmt);
   10661 ECB             : 
   10662 GIC          13 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   10663              13 :                     n->subname = $3;
   10664              13 :                     n->publication = $6;
   10665 CBC          13 :                     n->options = $7;
   10666 GIC          13 :                     $$ = (Node *) n;
   10667 ECB             :                 }
   10668                 :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   10669                 :                 {
   10670 CBC          30 :                     AlterSubscriptionStmt *n =
   10671              30 :                         makeNode(AlterSubscriptionStmt);
   10672                 : 
   10673 GIC          30 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   10674              30 :                     n->subname = $3;
   10675 CBC          30 :                     n->publication = $6;
   10676 GIC          30 :                     n->options = $7;
   10677 CBC          30 :                     $$ = (Node *) n;
   10678 ECB             :                 }
   10679                 :             | ALTER SUBSCRIPTION name ENABLE_P
   10680                 :                 {
   10681 CBC          13 :                     AlterSubscriptionStmt *n =
   10682 GIC          13 :                         makeNode(AlterSubscriptionStmt);
   10683                 : 
   10684              13 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10685              13 :                     n->subname = $3;
   10686              13 :                     n->options = list_make1(makeDefElem("enabled",
   10687                 :                                             (Node *) makeBoolean(true), @1));
   10688              13 :                     $$ = (Node *) n;
   10689                 :                 }
   10690                 :             | ALTER SUBSCRIPTION name DISABLE_P
   10691                 :                 {
   10692               8 :                     AlterSubscriptionStmt *n =
   10693               8 :                         makeNode(AlterSubscriptionStmt);
   10694 ECB             : 
   10695 CBC           8 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   10696               8 :                     n->subname = $3;
   10697               8 :                     n->options = list_make1(makeDefElem("enabled",
   10698 ECB             :                                             (Node *) makeBoolean(false), @1));
   10699 CBC           8 :                     $$ = (Node *) n;
   10700 ECB             :                 }
   10701                 :             | ALTER SUBSCRIPTION name SKIP definition
   10702                 :                 {
   10703 GIC          12 :                     AlterSubscriptionStmt *n =
   10704              12 :                         makeNode(AlterSubscriptionStmt);
   10705                 : 
   10706              12 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   10707              12 :                     n->subname = $3;
   10708              12 :                     n->options = $5;
   10709              12 :                     $$ = (Node *) n;
   10710                 :                 }
   10711                 :         ;
   10712                 : 
   10713 ECB             : /*****************************************************************************
   10714                 :  *
   10715                 :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   10716                 :  *
   10717                 :  *****************************************************************************/
   10718                 : 
   10719                 : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   10720                 :                 {
   10721 GIC          75 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10722                 : 
   10723 CBC          75 :                     n->subname = $3;
   10724              75 :                     n->missing_ok = false;
   10725 GIC          75 :                     n->behavior = $4;
   10726 CBC          75 :                     $$ = (Node *) n;
   10727 ECB             :                 }
   10728                 :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   10729                 :                 {
   10730 GIC           3 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   10731                 : 
   10732               3 :                     n->subname = $5;
   10733 CBC           3 :                     n->missing_ok = true;
   10734               3 :                     n->behavior = $6;
   10735 GIC           3 :                     $$ = (Node *) n;
   10736 ECB             :                 }
   10737                 :         ;
   10738                 : 
   10739                 : /*****************************************************************************
   10740                 :  *
   10741                 :  *      QUERY:  Define Rewrite Rule
   10742                 :  *
   10743                 :  *****************************************************************************/
   10744                 : 
   10745                 : RuleStmt:   CREATE opt_or_replace RULE name AS
   10746                 :             ON event TO qualified_name where_clause
   10747                 :             DO opt_instead RuleActionList
   10748                 :                 {
   10749 CBC        1031 :                     RuleStmt   *n = makeNode(RuleStmt);
   10750 ECB             : 
   10751 GIC        1031 :                     n->replace = $2;
   10752            1031 :                     n->relation = $9;
   10753            1031 :                     n->rulename = $4;
   10754 CBC        1031 :                     n->whereClause = $10;
   10755            1031 :                     n->event = $7;
   10756 GIC        1031 :                     n->instead = $12;
   10757 CBC        1031 :                     n->actions = $13;
   10758            1031 :                     $$ = (Node *) n;
   10759 ECB             :                 }
   10760                 :         ;
   10761                 : 
   10762                 : RuleActionList:
   10763 GIC         336 :             NOTHING                                 { $$ = NIL; }
   10764             672 :             | RuleActionStmt                        { $$ = list_make1($1); }
   10765 CBC          23 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   10766 ECB             :         ;
   10767                 : 
   10768                 : /* the thrashing around here is to discard "empty" statements... */
   10769                 : RuleActionMulti:
   10770                 :             RuleActionMulti ';' RuleActionStmtOrEmpty
   10771 CBC          31 :                 { if ($3 != NULL)
   10772              23 :                     $$ = lappend($1, $3);
   10773                 :                   else
   10774 GIC           8 :                     $$ = $1;
   10775                 :                 }
   10776 ECB             :             | RuleActionStmtOrEmpty
   10777 CBC          23 :                 { if ($1 != NULL)
   10778 GIC          23 :                     $$ = list_make1($1);
   10779 ECB             :                   else
   10780 LBC           0 :                     $$ = NIL;
   10781 ECB             :                 }
   10782                 :         ;
   10783                 : 
   10784                 : RuleActionStmt:
   10785                 :             SelectStmt
   10786                 :             | InsertStmt
   10787                 :             | UpdateStmt
   10788                 :             | DeleteStmt
   10789                 :             | NotifyStmt
   10790                 :         ;
   10791                 : 
   10792                 : RuleActionStmtOrEmpty:
   10793 GIC          46 :             RuleActionStmt                          { $$ = $1; }
   10794 CBC           8 :             |   /*EMPTY*/                           { $$ = NULL; }
   10795                 :         ;
   10796                 : 
   10797 GIC           9 : event:      SELECT                                  { $$ = CMD_SELECT; }
   10798 CBC         719 :             | UPDATE                                { $$ = CMD_UPDATE; }
   10799              76 :             | DELETE_P                              { $$ = CMD_DELETE; }
   10800 GIC         227 :             | INSERT                                { $$ = CMD_INSERT; }
   10801 ECB             :          ;
   10802                 : 
   10803                 : opt_instead:
   10804 CBC         616 :             INSTEAD                                 { $$ = true; }
   10805 GIC          68 :             | ALSO                                  { $$ = false; }
   10806             347 :             | /*EMPTY*/                             { $$ = false; }
   10807                 :         ;
   10808                 : 
   10809                 : 
   10810                 : /*****************************************************************************
   10811                 :  *
   10812                 :  *      QUERY:
   10813                 :  *              NOTIFY <identifier> can appear both in rule bodies and
   10814                 :  *              as a query-level command
   10815                 :  *
   10816 ECB             :  *****************************************************************************/
   10817                 : 
   10818                 : NotifyStmt: NOTIFY ColId notify_payload
   10819                 :                 {
   10820 CBC          60 :                     NotifyStmt *n = makeNode(NotifyStmt);
   10821 ECB             : 
   10822 GIC          60 :                     n->conditionname = $2;
   10823              60 :                     n->payload = $3;
   10824              60 :                     $$ = (Node *) n;
   10825 ECB             :                 }
   10826                 :         ;
   10827                 : 
   10828                 : notify_payload:
   10829 CBC          31 :             ',' Sconst                          { $$ = $2; }
   10830              29 :             | /*EMPTY*/                         { $$ = NULL; }
   10831                 :         ;
   10832                 : 
   10833                 : ListenStmt: LISTEN ColId
   10834                 :                 {
   10835 GIC          37 :                     ListenStmt *n = makeNode(ListenStmt);
   10836                 : 
   10837              37 :                     n->conditionname = $2;
   10838              37 :                     $$ = (Node *) n;
   10839                 :                 }
   10840                 :         ;
   10841                 : 
   10842                 : UnlistenStmt:
   10843                 :             UNLISTEN ColId
   10844 ECB             :                 {
   10845 GIC           3 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   10846 ECB             : 
   10847 CBC           3 :                     n->conditionname = $2;
   10848               3 :                     $$ = (Node *) n;
   10849 ECB             :                 }
   10850                 :             | UNLISTEN '*'
   10851                 :                 {
   10852 CBC          16 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   10853 ECB             : 
   10854 GIC          16 :                     n->conditionname = NULL;
   10855              16 :                     $$ = (Node *) n;
   10856                 :                 }
   10857                 :         ;
   10858 ECB             : 
   10859                 : 
   10860                 : /*****************************************************************************
   10861                 :  *
   10862                 :  *      Transactions:
   10863                 :  *
   10864                 :  *      BEGIN / COMMIT / ROLLBACK
   10865                 :  *      (also older versions END / ABORT)
   10866                 :  *
   10867                 :  *****************************************************************************/
   10868                 : 
   10869                 : TransactionStmt:
   10870                 :             ABORT_P opt_transaction opt_transaction_chain
   10871                 :                 {
   10872 CBC          97 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10873 ECB             : 
   10874 GIC          97 :                     n->kind = TRANS_STMT_ROLLBACK;
   10875 GBC          97 :                     n->options = NIL;
   10876 GIC          97 :                     n->chain = $3;
   10877              97 :                     $$ = (Node *) n;
   10878                 :                 }
   10879                 :             | START TRANSACTION transaction_mode_list_or_empty
   10880                 :                 {
   10881             761 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10882                 : 
   10883             761 :                     n->kind = TRANS_STMT_START;
   10884             761 :                     n->options = $3;
   10885             761 :                     $$ = (Node *) n;
   10886                 :                 }
   10887                 :             | COMMIT opt_transaction opt_transaction_chain
   10888 ECB             :                 {
   10889 CBC        5487 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10890                 : 
   10891 GIC        5487 :                     n->kind = TRANS_STMT_COMMIT;
   10892 CBC        5487 :                     n->options = NIL;
   10893            5487 :                     n->chain = $3;
   10894            5487 :                     $$ = (Node *) n;
   10895 ECB             :                 }
   10896                 :             | ROLLBACK opt_transaction opt_transaction_chain
   10897                 :                 {
   10898 GIC        1070 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10899 ECB             : 
   10900 CBC        1070 :                     n->kind = TRANS_STMT_ROLLBACK;
   10901            1070 :                     n->options = NIL;
   10902 GIC        1070 :                     n->chain = $3;
   10903            1070 :                     $$ = (Node *) n;
   10904                 :                 }
   10905                 :             | SAVEPOINT ColId
   10906                 :                 {
   10907            1000 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10908                 : 
   10909            1000 :                     n->kind = TRANS_STMT_SAVEPOINT;
   10910            1000 :                     n->savepoint_name = $2;
   10911            1000 :                     $$ = (Node *) n;
   10912                 :                 }
   10913                 :             | RELEASE SAVEPOINT ColId
   10914                 :                 {
   10915 CBC         102 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10916                 : 
   10917             102 :                     n->kind = TRANS_STMT_RELEASE;
   10918             102 :                     n->savepoint_name = $3;
   10919             102 :                     $$ = (Node *) n;
   10920                 :                 }
   10921                 :             | RELEASE ColId
   10922                 :                 {
   10923 GIC          42 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10924 ECB             : 
   10925 CBC          42 :                     n->kind = TRANS_STMT_RELEASE;
   10926 GIC          42 :                     n->savepoint_name = $2;
   10927              42 :                     $$ = (Node *) n;
   10928                 :                 }
   10929                 :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   10930 ECB             :                 {
   10931 GIC         107 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10932 ECB             : 
   10933 CBC         107 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   10934 GIC         107 :                     n->savepoint_name = $5;
   10935             107 :                     $$ = (Node *) n;
   10936                 :                 }
   10937                 :             | ROLLBACK opt_transaction TO ColId
   10938                 :                 {
   10939             242 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10940 ECB             : 
   10941 GIC         242 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   10942 CBC         242 :                     n->savepoint_name = $4;
   10943             242 :                     $$ = (Node *) n;
   10944                 :                 }
   10945                 :             | PREPARE TRANSACTION Sconst
   10946                 :                 {
   10947             385 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10948                 : 
   10949             385 :                     n->kind = TRANS_STMT_PREPARE;
   10950             385 :                     n->gid = $3;
   10951 GIC         385 :                     $$ = (Node *) n;
   10952                 :                 }
   10953                 :             | COMMIT PREPARED Sconst
   10954                 :                 {
   10955             310 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10956                 : 
   10957             310 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   10958             310 :                     n->gid = $3;
   10959             310 :                     $$ = (Node *) n;
   10960                 :                 }
   10961                 :             | ROLLBACK PREPARED Sconst
   10962                 :                 {
   10963              36 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10964                 : 
   10965              36 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   10966              36 :                     n->gid = $3;
   10967 CBC          36 :                     $$ = (Node *) n;
   10968                 :                 }
   10969 ECB             :         ;
   10970                 : 
   10971                 : TransactionStmtLegacy:
   10972                 :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   10973                 :                 {
   10974 GIC        6546 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10975                 : 
   10976 CBC        6546 :                     n->kind = TRANS_STMT_BEGIN;
   10977 GIC        6546 :                     n->options = $3;
   10978 CBC        6546 :                     $$ = (Node *) n;
   10979 ECB             :                 }
   10980                 :             | END_P opt_transaction opt_transaction_chain
   10981                 :                 {
   10982 GIC         180 :                     TransactionStmt *n = makeNode(TransactionStmt);
   10983                 : 
   10984 CBC         180 :                     n->kind = TRANS_STMT_COMMIT;
   10985 GIC         180 :                     n->options = NIL;
   10986 CBC         180 :                     n->chain = $3;
   10987             180 :                     $$ = (Node *) n;
   10988 ECB             :                 }
   10989                 :         ;
   10990                 : 
   10991                 : opt_transaction:    WORK
   10992                 :             | TRANSACTION
   10993                 :             | /*EMPTY*/
   10994                 :         ;
   10995                 : 
   10996                 : transaction_mode_item:
   10997                 :             ISOLATION LEVEL iso_level
   10998 CBC        3146 :                     { $$ = makeDefElem("transaction_isolation",
   10999 GIC        3146 :                                        makeStringConst($3, @3), @1); }
   11000                 :             | READ ONLY
   11001             595 :                     { $$ = makeDefElem("transaction_read_only",
   11002 CBC         595 :                                        makeIntConst(true, @1), @1); }
   11003                 :             | READ WRITE
   11004              41 :                     { $$ = makeDefElem("transaction_read_only",
   11005              41 :                                        makeIntConst(false, @1), @1); }
   11006 ECB             :             | DEFERRABLE
   11007 GIC          19 :                     { $$ = makeDefElem("transaction_deferrable",
   11008                 :                                        makeIntConst(true, @1), @1); }
   11009                 :             | NOT DEFERRABLE
   11010 CBC           5 :                     { $$ = makeDefElem("transaction_deferrable",
   11011 GIC           5 :                                        makeIntConst(false, @1), @1); }
   11012 ECB             :         ;
   11013                 : 
   11014                 : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11015                 : transaction_mode_list:
   11016                 :             transaction_mode_item
   11017 GIC        3251 :                     { $$ = list_make1($1); }
   11018 ECB             :             | transaction_mode_list ',' transaction_mode_item
   11019 GIC         395 :                     { $$ = lappend($1, $3); }
   11020 ECB             :             | transaction_mode_list transaction_mode_item
   11021 CBC         160 :                     { $$ = lappend($1, $2); }
   11022 ECB             :         ;
   11023                 : 
   11024                 : transaction_mode_list_or_empty:
   11025                 :             transaction_mode_list
   11026                 :             | /* EMPTY */
   11027 GIC        4283 :                     { $$ = NIL; }
   11028 ECB             :         ;
   11029                 : 
   11030                 : opt_transaction_chain:
   11031 GIC          57 :             AND CHAIN       { $$ = true; }
   11032               1 :             | AND NO CHAIN  { $$ = false; }
   11033            6776 :             | /* EMPTY */   { $$ = false; }
   11034 ECB             :         ;
   11035                 : 
   11036                 : 
   11037                 : /*****************************************************************************
   11038                 :  *
   11039                 :  *  QUERY:
   11040                 :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11041                 :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11042                 :  *
   11043                 :  *****************************************************************************/
   11044                 : 
   11045                 : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11046                 :                 AS SelectStmt opt_check_option
   11047                 :                 {
   11048 GIC       43942 :                     ViewStmt   *n = makeNode(ViewStmt);
   11049                 : 
   11050 CBC       43942 :                     n->view = $4;
   11051 GIC       43942 :                     n->view->relpersistence = $2;
   11052 CBC       43942 :                     n->aliases = $5;
   11053           43942 :                     n->query = $8;
   11054           43942 :                     n->replace = false;
   11055 GIC       43942 :                     n->options = $6;
   11056           43942 :                     n->withCheckOption = $9;
   11057           43942 :                     $$ = (Node *) n;
   11058 ECB             :                 }
   11059                 :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11060                 :                 AS SelectStmt opt_check_option
   11061                 :                 {
   11062 CBC         119 :                     ViewStmt   *n = makeNode(ViewStmt);
   11063                 : 
   11064 GIC         119 :                     n->view = $6;
   11065             119 :                     n->view->relpersistence = $4;
   11066             119 :                     n->aliases = $7;
   11067             119 :                     n->query = $10;
   11068             119 :                     n->replace = true;
   11069 CBC         119 :                     n->options = $8;
   11070 GIC         119 :                     n->withCheckOption = $11;
   11071 CBC         119 :                     $$ = (Node *) n;
   11072 ECB             :                 }
   11073                 :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11074                 :                 AS SelectStmt opt_check_option
   11075                 :                 {
   11076 GIC           4 :                     ViewStmt   *n = makeNode(ViewStmt);
   11077 ECB             : 
   11078 GIC           4 :                     n->view = $5;
   11079 CBC           4 :                     n->view->relpersistence = $2;
   11080               4 :                     n->aliases = $7;
   11081               4 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11082               4 :                     n->replace = false;
   11083 GIC           4 :                     n->options = $9;
   11084               4 :                     n->withCheckOption = $12;
   11085               4 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11086 UIC           0 :                         ereport(ERROR,
   11087                 :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11088                 :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11089                 :                                  parser_errposition(@12)));
   11090 GIC           4 :                     $$ = (Node *) n;
   11091                 :                 }
   11092                 :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11093 ECB             :                 AS SelectStmt opt_check_option
   11094                 :                 {
   11095 GIC           3 :                     ViewStmt   *n = makeNode(ViewStmt);
   11096 ECB             : 
   11097 CBC           3 :                     n->view = $7;
   11098 GIC           3 :                     n->view->relpersistence = $4;
   11099 CBC           3 :                     n->aliases = $9;
   11100               3 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11101 GIC           3 :                     n->replace = true;
   11102 CBC           3 :                     n->options = $11;
   11103 GIC           3 :                     n->withCheckOption = $14;
   11104               3 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11105 LBC           0 :                         ereport(ERROR,
   11106 ECB             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11107                 :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11108                 :                                  parser_errposition(@14)));
   11109 GIC           3 :                     $$ = (Node *) n;
   11110                 :                 }
   11111                 :         ;
   11112 ECB             : 
   11113                 : opt_check_option:
   11114 CBC          45 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11115 GIC           3 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11116 CBC          12 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11117 GIC       44008 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11118                 :         ;
   11119                 : 
   11120                 : /*****************************************************************************
   11121                 :  *
   11122 ECB             :  *      QUERY:
   11123                 :  *              LOAD "filename"
   11124                 :  *
   11125                 :  *****************************************************************************/
   11126                 : 
   11127                 : LoadStmt:   LOAD file_name
   11128                 :                 {
   11129 GIC          26 :                     LoadStmt   *n = makeNode(LoadStmt);
   11130                 : 
   11131              26 :                     n->filename = $2;
   11132              26 :                     $$ = (Node *) n;
   11133                 :                 }
   11134                 :         ;
   11135                 : 
   11136                 : 
   11137                 : /*****************************************************************************
   11138                 :  *
   11139                 :  *      CREATE DATABASE
   11140                 :  *
   11141                 :  *****************************************************************************/
   11142                 : 
   11143 ECB             : CreatedbStmt:
   11144                 :             CREATE DATABASE name opt_with createdb_opt_list
   11145                 :                 {
   11146 CBC         808 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11147 ECB             : 
   11148 CBC         808 :                     n->dbname = $3;
   11149             808 :                     n->options = $5;
   11150             808 :                     $$ = (Node *) n;
   11151 ECB             :                 }
   11152                 :         ;
   11153                 : 
   11154                 : createdb_opt_list:
   11155 GIC         744 :             createdb_opt_items                      { $$ = $1; }
   11156              69 :             | /* EMPTY */                           { $$ = NIL; }
   11157 ECB             :         ;
   11158                 : 
   11159                 : createdb_opt_items:
   11160 CBC         744 :             createdb_opt_item                       { $$ = list_make1($1); }
   11161            1333 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11162 ECB             :         ;
   11163                 : 
   11164                 : createdb_opt_item:
   11165                 :             createdb_opt_name opt_equal NumericOnly
   11166                 :                 {
   11167 GIC         615 :                     $$ = makeDefElem($1, $3, @1);
   11168                 :                 }
   11169                 :             | createdb_opt_name opt_equal opt_boolean_or_string
   11170                 :                 {
   11171 CBC        1462 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11172                 :                 }
   11173 ECB             :             | createdb_opt_name opt_equal DEFAULT
   11174                 :                 {
   11175 LBC           0 :                     $$ = makeDefElem($1, NULL, @1);
   11176 ECB             :                 }
   11177                 :         ;
   11178                 : 
   11179                 : /*
   11180                 :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11181 EUB             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11182                 :  * we need, and allow IDENT so that database option names don't have to be
   11183                 :  * parser keywords unless they are already keywords for other reasons.
   11184                 :  *
   11185 ECB             :  * XXX this coding technique is fragile since if someone makes a formerly
   11186                 :  * non-keyword option name into a keyword and forgets to add it here, the
   11187                 :  * option will silently break.  Best defense is to provide a regression test
   11188                 :  * exercising every such option, at least at the syntax level.
   11189                 :  */
   11190                 : createdb_opt_name:
   11191 GIC        1926 :             IDENT                           { $$ = $1; }
   11192 LBC           0 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11193 CBC          23 :             | ENCODING                      { $$ = pstrdup($1); }
   11194 LBC           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11195 CBC           1 :             | OWNER                         { $$ = pstrdup($1); }
   11196               8 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11197             119 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11198 ECB             :         ;
   11199                 : 
   11200 EUB             : /*
   11201                 :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11202                 :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11203                 :  */
   11204 ECB             : opt_equal:  '='
   11205                 :             | /*EMPTY*/
   11206                 :         ;
   11207                 : 
   11208                 : 
   11209                 : /*****************************************************************************
   11210                 :  *
   11211                 :  *      ALTER DATABASE
   11212                 :  *
   11213                 :  *****************************************************************************/
   11214                 : 
   11215                 : AlterDatabaseStmt:
   11216                 :             ALTER DATABASE name WITH createdb_opt_list
   11217                 :                  {
   11218 UIC           0 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11219                 : 
   11220               0 :                     n->dbname = $3;
   11221               0 :                     n->options = $5;
   11222               0 :                     $$ = (Node *) n;
   11223                 :                  }
   11224 ECB             :             | ALTER DATABASE name createdb_opt_list
   11225                 :                  {
   11226 CBC           5 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11227 ECB             : 
   11228 GIC           5 :                     n->dbname = $3;
   11229               5 :                     n->options = $4;
   11230               5 :                     $$ = (Node *) n;
   11231                 :                  }
   11232                 :             | ALTER DATABASE name SET TABLESPACE name
   11233                 :                  {
   11234               5 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11235                 : 
   11236               5 :                     n->dbname = $3;
   11237               5 :                     n->options = list_make1(makeDefElem("tablespace",
   11238                 :                                                         (Node *) makeString($6), @6));
   11239               5 :                     $$ = (Node *) n;
   11240                 :                  }
   11241 ECB             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11242                 :                  {
   11243 CBC           6 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11244 ECB             : 
   11245 CBC           6 :                     n->dbname = $3;
   11246 GIC           6 :                     $$ = (Node *) n;
   11247                 :                  }
   11248                 :         ;
   11249                 : 
   11250 ECB             : AlterDatabaseSetStmt:
   11251                 :             ALTER DATABASE name SetResetClause
   11252                 :                 {
   11253 GIC         516 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11254                 : 
   11255 CBC         516 :                     n->dbname = $3;
   11256             516 :                     n->setstmt = $4;
   11257 GIC         516 :                     $$ = (Node *) n;
   11258                 :                 }
   11259                 :         ;
   11260                 : 
   11261                 : 
   11262 ECB             : /*****************************************************************************
   11263                 :  *
   11264                 :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11265                 :  *
   11266                 :  * This is implicitly CASCADE, no need for drop behavior
   11267                 :  *****************************************************************************/
   11268                 : 
   11269                 : DropdbStmt: DROP DATABASE name
   11270 EUB             :                 {
   11271 GIC          20 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11272                 : 
   11273              20 :                     n->dbname = $3;
   11274              20 :                     n->missing_ok = false;
   11275              20 :                     n->options = NULL;
   11276              20 :                     $$ = (Node *) n;
   11277                 :                 }
   11278                 :             | DROP DATABASE IF_P EXISTS name
   11279                 :                 {
   11280               2 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11281                 : 
   11282               2 :                     n->dbname = $5;
   11283               2 :                     n->missing_ok = true;
   11284               2 :                     n->options = NULL;
   11285               2 :                     $$ = (Node *) n;
   11286 ECB             :                 }
   11287 EUB             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11288 ECB             :                 {
   11289 GBC           7 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11290 ECB             : 
   11291 CBC           7 :                     n->dbname = $3;
   11292               7 :                     n->missing_ok = false;
   11293 GIC           7 :                     n->options = $6;
   11294               7 :                     $$ = (Node *) n;
   11295                 :                 }
   11296                 :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11297                 :                 {
   11298               6 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11299                 : 
   11300               6 :                     n->dbname = $5;
   11301               6 :                     n->missing_ok = true;
   11302               6 :                     n->options = $8;
   11303               6 :                     $$ = (Node *) n;
   11304                 :                 }
   11305                 :         ;
   11306                 : 
   11307                 : drop_option_list:
   11308                 :             drop_option
   11309                 :                 {
   11310              13 :                     $$ = list_make1((Node *) $1);
   11311                 :                 }
   11312                 :             | drop_option_list ',' drop_option
   11313 EUB             :                 {
   11314 UIC           0 :                     $$ = lappend($1, (Node *) $3);
   11315 EUB             :                 }
   11316                 :         ;
   11317                 : 
   11318                 : /*
   11319                 :  * Currently only the FORCE option is supported, but the syntax is designed
   11320                 :  * to be extensible so that we can add more options in the future if required.
   11321 ECB             :  */
   11322                 : drop_option:
   11323                 :             FORCE
   11324                 :                 {
   11325 CBC          13 :                     $$ = makeDefElem("force", NULL, @1);
   11326                 :                 }
   11327                 :         ;
   11328                 : 
   11329 ECB             : /*****************************************************************************
   11330                 :  *
   11331                 :  *      ALTER COLLATION
   11332                 :  *
   11333                 :  *****************************************************************************/
   11334                 : 
   11335                 : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11336                 :                 {
   11337 GIC           6 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11338 ECB             : 
   11339 GIC           6 :                     n->collname = $3;
   11340 CBC           6 :                     $$ = (Node *) n;
   11341 ECB             :                 }
   11342                 :         ;
   11343                 : 
   11344                 : 
   11345                 : /*****************************************************************************
   11346                 :  *
   11347                 :  *      ALTER SYSTEM
   11348                 :  *
   11349                 :  * This is used to change configuration parameters persistently.
   11350                 :  *****************************************************************************/
   11351                 : 
   11352                 : AlterSystemStmt:
   11353                 :             ALTER SYSTEM_P SET generic_set
   11354                 :                 {
   11355 GIC          51 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11356                 : 
   11357              51 :                     n->setstmt = $4;
   11358              51 :                     $$ = (Node *) n;
   11359                 :                 }
   11360                 :             | ALTER SYSTEM_P RESET generic_reset
   11361                 :                 {
   11362              24 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11363                 : 
   11364              24 :                     n->setstmt = $4;
   11365              24 :                     $$ = (Node *) n;
   11366 ECB             :                 }
   11367                 :         ;
   11368                 : 
   11369                 : 
   11370                 : /*****************************************************************************
   11371                 :  *
   11372                 :  * Manipulate a domain
   11373                 :  *
   11374                 :  *****************************************************************************/
   11375                 : 
   11376                 : CreateDomainStmt:
   11377                 :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11378                 :                 {
   11379 CBC        1862 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11380 ECB             : 
   11381 GIC        1862 :                     n->domainname = $3;
   11382            1862 :                     n->typeName = $5;
   11383            1862 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11384 ECB             :                                      yyscanner);
   11385 GIC        1862 :                     $$ = (Node *) n;
   11386 ECB             :                 }
   11387                 :         ;
   11388                 : 
   11389                 : AlterDomainStmt:
   11390                 :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11391                 :             ALTER DOMAIN_P any_name alter_column_default
   11392                 :                 {
   11393 CBC           7 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11394                 : 
   11395               7 :                     n->subtype = 'T';
   11396               7 :                     n->typeName = $3;
   11397               7 :                     n->def = $4;
   11398               7 :                     $$ = (Node *) n;
   11399                 :                 }
   11400                 :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11401                 :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11402                 :                 {
   11403 GIC           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11404                 : 
   11405 CBC           6 :                     n->subtype = 'N';
   11406 GIC           6 :                     n->typeName = $3;
   11407               6 :                     $$ = (Node *) n;
   11408                 :                 }
   11409 EUB             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11410                 :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11411                 :                 {
   11412 GIC          12 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11413                 : 
   11414              12 :                     n->subtype = 'O';
   11415              12 :                     n->typeName = $3;
   11416              12 :                     $$ = (Node *) n;
   11417                 :                 }
   11418                 :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11419                 :             | ALTER DOMAIN_P any_name ADD_P TableConstraint
   11420 ECB             :                 {
   11421 GIC          72 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11422                 : 
   11423              72 :                     n->subtype = 'C';
   11424              72 :                     n->typeName = $3;
   11425              72 :                     n->def = $5;
   11426              72 :                     $$ = (Node *) n;
   11427                 :                 }
   11428                 :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11429                 :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11430                 :                 {
   11431              18 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11432 ECB             : 
   11433 GIC          18 :                     n->subtype = 'X';
   11434 CBC          18 :                     n->typeName = $3;
   11435              18 :                     n->name = $6;
   11436 GIC          18 :                     n->behavior = $7;
   11437              18 :                     n->missing_ok = false;
   11438              18 :                     $$ = (Node *) n;
   11439                 :                 }
   11440                 :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11441                 :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11442                 :                 {
   11443               3 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11444                 : 
   11445               3 :                     n->subtype = 'X';
   11446               3 :                     n->typeName = $3;
   11447               3 :                     n->name = $8;
   11448               3 :                     n->behavior = $9;
   11449               3 :                     n->missing_ok = true;
   11450 CBC           3 :                     $$ = (Node *) n;
   11451                 :                 }
   11452 ECB             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11453                 :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11454                 :                 {
   11455 GIC           6 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11456                 : 
   11457 CBC           6 :                     n->subtype = 'V';
   11458 GIC           6 :                     n->typeName = $3;
   11459 CBC           6 :                     n->name = $6;
   11460               6 :                     $$ = (Node *) n;
   11461                 :                 }
   11462                 :             ;
   11463                 : 
   11464                 : opt_as:     AS
   11465                 :             | /* EMPTY */
   11466                 :         ;
   11467                 : 
   11468                 : 
   11469                 : /*****************************************************************************
   11470                 :  *
   11471                 :  * Manipulate a text search dictionary or configuration
   11472                 :  *
   11473                 :  *****************************************************************************/
   11474 ECB             : 
   11475                 : AlterTSDictionaryStmt:
   11476                 :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11477                 :                 {
   11478 CBC          20 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11479                 : 
   11480              20 :                     n->dictname = $5;
   11481 GIC          20 :                     n->options = $6;
   11482              20 :                     $$ = (Node *) n;
   11483                 :                 }
   11484                 :         ;
   11485                 : 
   11486                 : AlterTSConfigurationStmt:
   11487                 :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11488 ECB             :                 {
   11489 GIC       25529 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11490 ECB             : 
   11491 CBC       25529 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11492           25529 :                     n->cfgname = $5;
   11493           25529 :                     n->tokentype = $9;
   11494 GIC       25529 :                     n->dicts = $11;
   11495           25529 :                     n->override = false;
   11496           25529 :                     n->replace = false;
   11497           25529 :                     $$ = (Node *) n;
   11498 ECB             :                 }
   11499                 :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11500                 :                 {
   11501 CBC          10 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11502 ECB             : 
   11503 GIC          10 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11504              10 :                     n->cfgname = $5;
   11505              10 :                     n->tokentype = $9;
   11506              10 :                     n->dicts = $11;
   11507 CBC          10 :                     n->override = true;
   11508 GIC          10 :                     n->replace = false;
   11509 CBC          10 :                     $$ = (Node *) n;
   11510 ECB             :                 }
   11511                 :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   11512                 :                 {
   11513 GIC           9 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11514                 : 
   11515               9 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   11516 CBC           9 :                     n->cfgname = $5;
   11517 GIC           9 :                     n->tokentype = NIL;
   11518 CBC           9 :                     n->dicts = list_make2($9,$11);
   11519               9 :                     n->override = false;
   11520               9 :                     n->replace = true;
   11521               9 :                     $$ = (Node *) n;
   11522                 :                 }
   11523                 :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   11524                 :                 {
   11525 UIC           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11526 ECB             : 
   11527 UIC           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   11528 LBC           0 :                     n->cfgname = $5;
   11529               0 :                     n->tokentype = $9;
   11530               0 :                     n->dicts = list_make2($11,$13);
   11531               0 :                     n->override = false;
   11532               0 :                     n->replace = true;
   11533               0 :                     $$ = (Node *) n;
   11534                 :                 }
   11535                 :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   11536                 :                 {
   11537 UIC           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11538 ECB             : 
   11539 UIC           0 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11540 LBC           0 :                     n->cfgname = $5;
   11541               0 :                     n->tokentype = $9;
   11542               0 :                     n->missing_ok = false;
   11543               0 :                     $$ = (Node *) n;
   11544 ECB             :                 }
   11545                 :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   11546                 :                 {
   11547 UIC           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11548                 : 
   11549               0 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   11550 LBC           0 :                     n->cfgname = $5;
   11551 UIC           0 :                     n->tokentype = $11;
   11552 LBC           0 :                     n->missing_ok = true;
   11553               0 :                     $$ = (Node *) n;
   11554 ECB             :                 }
   11555                 :         ;
   11556                 : 
   11557                 : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   11558                 : any_with:   WITH
   11559                 :             | WITH_LA
   11560                 :         ;
   11561                 : 
   11562                 : 
   11563                 : /*****************************************************************************
   11564                 :  *
   11565                 :  * Manipulate a conversion
   11566                 :  *
   11567                 :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   11568                 :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   11569                 :  *
   11570                 :  *****************************************************************************/
   11571                 : 
   11572                 : CreateConversionStmt:
   11573                 :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   11574                 :             TO Sconst FROM any_name
   11575                 :             {
   11576 CBC          32 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   11577 ECB             : 
   11578 GIC          32 :                 n->conversion_name = $4;
   11579              32 :                 n->for_encoding_name = $6;
   11580              32 :                 n->to_encoding_name = $8;
   11581              32 :                 n->func_name = $10;
   11582              32 :                 n->def = $2;
   11583              32 :                 $$ = (Node *) n;
   11584 ECB             :             }
   11585                 :         ;
   11586                 : 
   11587                 : /*****************************************************************************
   11588                 :  *
   11589                 :  *      QUERY:
   11590                 :  *              CLUSTER [VERBOSE] <qualified_name> [ USING <index_name> ]
   11591                 :  *              CLUSTER [ (options) ] <qualified_name> [ USING <index_name> ]
   11592                 :  *              CLUSTER [VERBOSE]
   11593                 :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   11594                 :  *
   11595                 :  *****************************************************************************/
   11596                 : 
   11597                 : ClusterStmt:
   11598                 :             CLUSTER opt_verbose qualified_name cluster_index_specification
   11599                 :                 {
   11600 CBC          85 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11601 ECB             : 
   11602 CBC          85 :                     n->relation = $3;
   11603              85 :                     n->indexname = $4;
   11604              85 :                     n->params = NIL;
   11605 GIC          85 :                     if ($2)
   11606 UIC           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11607 GIC          85 :                     $$ = (Node *) n;
   11608 ECB             :                 }
   11609                 : 
   11610                 :             | CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   11611                 :                 {
   11612 LBC           0 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11613 ECB             : 
   11614 LBC           0 :                     n->relation = $5;
   11615               0 :                     n->indexname = $6;
   11616               0 :                     n->params = $3;
   11617 UIC           0 :                     $$ = (Node *) n;
   11618                 :                 }
   11619                 :             | CLUSTER opt_verbose
   11620 EUB             :                 {
   11621 GIC          12 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11622 EUB             : 
   11623 GBC          12 :                     n->relation = NULL;
   11624              12 :                     n->indexname = NULL;
   11625              12 :                     n->params = NIL;
   11626              12 :                     if ($2)
   11627               6 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11628              12 :                     $$ = (Node *) n;
   11629                 :                 }
   11630                 :             /* kept for pre-8.3 compatibility */
   11631                 :             | CLUSTER opt_verbose name ON qualified_name
   11632 EUB             :                 {
   11633 GIC           9 :                     ClusterStmt *n = makeNode(ClusterStmt);
   11634 EUB             : 
   11635 GBC           9 :                     n->relation = $5;
   11636               9 :                     n->indexname = $3;
   11637               9 :                     n->params = NIL;
   11638               9 :                     if ($2)
   11639 UIC           0 :                         n->params = lappend(n->params, makeDefElem("verbose", NULL, @2));
   11640 GIC           9 :                     $$ = (Node *) n;
   11641                 :                 }
   11642 EUB             :         ;
   11643                 : 
   11644                 : cluster_index_specification:
   11645 GBC          70 :             USING name              { $$ = $2; }
   11646              15 :             | /*EMPTY*/             { $$ = NULL; }
   11647 EUB             :         ;
   11648                 : 
   11649                 : 
   11650                 : /*****************************************************************************
   11651                 :  *
   11652                 :  *      QUERY:
   11653                 :  *              VACUUM
   11654                 :  *              ANALYZE
   11655                 :  *
   11656                 :  *****************************************************************************/
   11657                 : 
   11658                 : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   11659                 :                 {
   11660 GIC        1033 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11661                 : 
   11662            1033 :                     n->options = NIL;
   11663            1033 :                     if ($2)
   11664              53 :                         n->options = lappend(n->options,
   11665              53 :                                              makeDefElem("full", NULL, @2));
   11666            1033 :                     if ($3)
   11667             331 :                         n->options = lappend(n->options,
   11668             331 :                                              makeDefElem("freeze", NULL, @3));
   11669            1033 :                     if ($4)
   11670               5 :                         n->options = lappend(n->options,
   11671 CBC           5 :                                              makeDefElem("verbose", NULL, @4));
   11672 GIC        1033 :                     if ($5)
   11673 CBC         136 :                         n->options = lappend(n->options,
   11674             136 :                                              makeDefElem("analyze", NULL, @5));
   11675            1033 :                     n->rels = $6;
   11676            1033 :                     n->is_vacuumcmd = true;
   11677            1033 :                     $$ = (Node *) n;
   11678 ECB             :                 }
   11679                 :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   11680                 :                 {
   11681 GIC        1491 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11682                 : 
   11683            1491 :                     n->options = $3;
   11684            1491 :                     n->rels = $5;
   11685            1491 :                     n->is_vacuumcmd = true;
   11686            1491 :                     $$ = (Node *) n;
   11687                 :                 }
   11688                 :         ;
   11689                 : 
   11690                 : AnalyzeStmt: analyze_keyword opt_verbose opt_vacuum_relation_list
   11691                 :                 {
   11692            2367 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11693                 : 
   11694            2367 :                     n->options = NIL;
   11695 CBC        2367 :                     if ($2)
   11696 UIC           0 :                         n->options = lappend(n->options,
   11697 LBC           0 :                                              makeDefElem("verbose", NULL, @2));
   11698 CBC        2367 :                     n->rels = $3;
   11699            2367 :                     n->is_vacuumcmd = false;
   11700            2367 :                     $$ = (Node *) n;
   11701 EUB             :                 }
   11702 ECB             :             | analyze_keyword '(' utility_option_list ')' opt_vacuum_relation_list
   11703                 :                 {
   11704 GIC          93 :                     VacuumStmt *n = makeNode(VacuumStmt);
   11705                 : 
   11706              93 :                     n->options = $3;
   11707 GBC          93 :                     n->rels = $5;
   11708 GIC          93 :                     n->is_vacuumcmd = false;
   11709 GBC          93 :                     $$ = (Node *) n;
   11710 EUB             :                 }
   11711                 :         ;
   11712                 : 
   11713                 : utility_option_list:
   11714                 :             utility_option_elem
   11715                 :                 {
   11716 CBC        6948 :                     $$ = list_make1($1);
   11717                 :                 }
   11718 ECB             :             | utility_option_list ',' utility_option_elem
   11719                 :                 {
   11720 CBC        3183 :                     $$ = lappend($1, $3);
   11721 ECB             :                 }
   11722                 :         ;
   11723                 : 
   11724                 : analyze_keyword:
   11725                 :             ANALYZE
   11726                 :             | ANALYSE /* British */
   11727                 :         ;
   11728                 : 
   11729                 : utility_option_elem:
   11730                 :             utility_option_name utility_option_arg
   11731                 :                 {
   11732 CBC       10131 :                     $$ = makeDefElem($1, $2, @1);
   11733 ECB             :                 }
   11734 EUB             :         ;
   11735 ECB             : 
   11736                 : utility_option_name:
   11737 GIC        9342 :             NonReservedWord                         { $$ = $1; }
   11738             727 :             | analyze_keyword                       { $$ = "analyze"; }
   11739 GNC          65 :             | FORMAT_LA                             { $$ = "format"; }
   11740                 :         ;
   11741 ECB             : 
   11742                 : utility_option_arg:
   11743 GIC        6383 :             opt_boolean_or_string                   { $$ = (Node *) makeString($1); }
   11744             181 :             | NumericOnly                           { $$ = (Node *) $1; }
   11745            3567 :             | /* EMPTY */                           { $$ = NULL; }
   11746                 :         ;
   11747                 : 
   11748                 : opt_analyze:
   11749             136 :             analyze_keyword                         { $$ = true; }
   11750             897 :             | /*EMPTY*/                             { $$ = false; }
   11751                 :         ;
   11752                 : 
   11753                 : opt_verbose:
   11754              11 :             VERBOSE                                 { $$ = true; }
   11755            4641 :             | /*EMPTY*/                             { $$ = false; }
   11756 ECB             :         ;
   11757                 : 
   11758 CBC          53 : opt_full:   FULL                                    { $$ = true; }
   11759             980 :             | /*EMPTY*/                             { $$ = false; }
   11760 ECB             :         ;
   11761                 : 
   11762 CBC         331 : opt_freeze: FREEZE                                  { $$ = true; }
   11763             702 :             | /*EMPTY*/                             { $$ = false; }
   11764 ECB             :         ;
   11765                 : 
   11766                 : opt_name_list:
   11767 CBC        1033 :             '(' name_list ')'                       { $$ = $2; }
   11768            5539 :             | /*EMPTY*/                             { $$ = NIL; }
   11769 ECB             :         ;
   11770                 : 
   11771                 : vacuum_relation:
   11772                 :             qualified_name opt_name_list
   11773                 :                 {
   11774 GIC        4404 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   11775                 :                 }
   11776                 :         ;
   11777 ECB             : 
   11778                 : vacuum_relation_list:
   11779                 :             vacuum_relation
   11780 CBC        4330 :                     { $$ = list_make1($1); }
   11781 ECB             :             | vacuum_relation_list ',' vacuum_relation
   11782 CBC          74 :                     { $$ = lappend($1, $3); }
   11783                 :         ;
   11784                 : 
   11785                 : opt_vacuum_relation_list:
   11786 GIC        4330 :             vacuum_relation_list                    { $$ = $1; }
   11787             654 :             | /*EMPTY*/                             { $$ = NIL; }
   11788 ECB             :         ;
   11789                 : 
   11790                 : 
   11791                 : /*****************************************************************************
   11792 EUB             :  *
   11793                 :  *      QUERY:
   11794 ECB             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   11795                 :  *              EXPLAIN ( options ) query
   11796                 :  *
   11797                 :  *****************************************************************************/
   11798                 : 
   11799                 : ExplainStmt:
   11800                 :         EXPLAIN ExplainableStmt
   11801                 :                 {
   11802 CBC        3507 :                     ExplainStmt *n = makeNode(ExplainStmt);
   11803 ECB             : 
   11804 CBC        3507 :                     n->query = $2;
   11805            3507 :                     n->options = NIL;
   11806 GIC        3507 :                     $$ = (Node *) n;
   11807                 :                 }
   11808                 :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   11809                 :                 {
   11810            1146 :                     ExplainStmt *n = makeNode(ExplainStmt);
   11811                 : 
   11812 CBC        1146 :                     n->query = $4;
   11813 GIC        1146 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   11814            1146 :                     if ($3)
   11815 UIC           0 :                         n->options = lappend(n->options,
   11816 LBC           0 :                                              makeDefElem("verbose", NULL, @3));
   11817 GIC        1146 :                     $$ = (Node *) n;
   11818                 :                 }
   11819                 :         | EXPLAIN VERBOSE ExplainableStmt
   11820                 :                 {
   11821 UIC           0 :                     ExplainStmt *n = makeNode(ExplainStmt);
   11822                 : 
   11823               0 :                     n->query = $3;
   11824               0 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   11825               0 :                     $$ = (Node *) n;
   11826                 :                 }
   11827                 :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   11828 ECB             :                 {
   11829 GIC        5286 :                     ExplainStmt *n = makeNode(ExplainStmt);
   11830                 : 
   11831            5286 :                     n->query = $5;
   11832            5286 :                     n->options = $3;
   11833 CBC        5286 :                     $$ = (Node *) n;
   11834 ECB             :                 }
   11835                 :         ;
   11836                 : 
   11837                 : ExplainableStmt:
   11838                 :             SelectStmt
   11839                 :             | InsertStmt
   11840                 :             | UpdateStmt
   11841                 :             | DeleteStmt
   11842                 :             | MergeStmt
   11843                 :             | DeclareCursorStmt
   11844                 :             | CreateAsStmt
   11845                 :             | CreateMatViewStmt
   11846                 :             | RefreshMatViewStmt
   11847                 :             | ExecuteStmt                   /* by default all are $$=$1 */
   11848                 :         ;
   11849                 : 
   11850                 : /*****************************************************************************
   11851                 :  *
   11852                 :  *      QUERY:
   11853                 :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   11854                 :  *
   11855                 :  *****************************************************************************/
   11856                 : 
   11857                 : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   11858                 :                 {
   11859 CBC         813 :                     PrepareStmt *n = makeNode(PrepareStmt);
   11860                 : 
   11861 GIC         813 :                     n->name = $2;
   11862             813 :                     n->argtypes = $3;
   11863 CBC         813 :                     n->query = $5;
   11864             813 :                     $$ = (Node *) n;
   11865                 :                 }
   11866                 :         ;
   11867                 : 
   11868 GIC         686 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   11869             130 :                 | /* EMPTY */               { $$ = NIL; }
   11870 ECB             :         ;
   11871                 : 
   11872                 : PreparableStmt:
   11873                 :             SelectStmt
   11874                 :             | InsertStmt
   11875                 :             | UpdateStmt
   11876                 :             | DeleteStmt
   11877                 :             | MergeStmt                     /* by default all are $$=$1 */
   11878                 :         ;
   11879                 : 
   11880                 : /*****************************************************************************
   11881                 :  *
   11882                 :  * EXECUTE <plan_name> [(params, ...)]
   11883                 :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   11884                 :  *
   11885                 :  *****************************************************************************/
   11886                 : 
   11887                 : ExecuteStmt: EXECUTE name execute_param_clause
   11888                 :                 {
   11889 GIC        4776 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   11890                 : 
   11891            4776 :                     n->name = $2;
   11892            4776 :                     n->params = $3;
   11893            4776 :                     $$ = (Node *) n;
   11894                 :                 }
   11895                 :             | CREATE OptTemp TABLE create_as_target AS
   11896                 :                 EXECUTE name execute_param_clause opt_with_data
   11897                 :                 {
   11898 CBC          36 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   11899 GIC          36 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   11900 ECB             : 
   11901 CBC          36 :                     n->name = $7;
   11902              36 :                     n->params = $8;
   11903 GIC          36 :                     ctas->query = (Node *) n;
   11904              36 :                     ctas->into = $4;
   11905              36 :                     ctas->objtype = OBJECT_TABLE;
   11906 CBC          36 :                     ctas->is_select_into = false;
   11907 GIC          36 :                     ctas->if_not_exists = false;
   11908 ECB             :                     /* cram additional flags into the IntoClause */
   11909 CBC          36 :                     $4->rel->relpersistence = $2;
   11910              36 :                     $4->skipData = !($9);
   11911 GBC          36 :                     $$ = (Node *) ctas;
   11912 EUB             :                 }
   11913 ECB             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   11914                 :                 EXECUTE name execute_param_clause opt_with_data
   11915                 :                 {
   11916 GIC           6 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   11917 GBC           6 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   11918                 : 
   11919               6 :                     n->name = $10;
   11920               6 :                     n->params = $11;
   11921               6 :                     ctas->query = (Node *) n;
   11922 GIC           6 :                     ctas->into = $7;
   11923               6 :                     ctas->objtype = OBJECT_TABLE;
   11924               6 :                     ctas->is_select_into = false;
   11925 CBC           6 :                     ctas->if_not_exists = true;
   11926                 :                     /* cram additional flags into the IntoClause */
   11927               6 :                     $7->rel->relpersistence = $2;
   11928               6 :                     $7->skipData = !($12);
   11929               6 :                     $$ = (Node *) ctas;
   11930                 :                 }
   11931                 :         ;
   11932                 : 
   11933 GIC        4288 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   11934             530 :                     | /* EMPTY */                   { $$ = NIL; }
   11935                 :                     ;
   11936                 : 
   11937                 : /*****************************************************************************
   11938                 :  *
   11939                 :  *      QUERY:
   11940                 :  *              DEALLOCATE [PREPARE] <plan_name>
   11941                 :  *
   11942                 :  *****************************************************************************/
   11943                 : 
   11944                 : DeallocateStmt: DEALLOCATE name
   11945                 :                     {
   11946            1119 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   11947                 : 
   11948            1119 :                         n->name = $2;
   11949            1119 :                         $$ = (Node *) n;
   11950                 :                     }
   11951                 :                 | DEALLOCATE PREPARE name
   11952                 :                     {
   11953               9 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   11954                 : 
   11955 CBC           9 :                         n->name = $3;
   11956 GIC           9 :                         $$ = (Node *) n;
   11957 ECB             :                     }
   11958                 :                 | DEALLOCATE ALL
   11959                 :                     {
   11960 CBC          23 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   11961                 : 
   11962 GIC          23 :                         n->name = NULL;
   11963              23 :                         $$ = (Node *) n;
   11964 ECB             :                     }
   11965                 :                 | DEALLOCATE PREPARE ALL
   11966                 :                     {
   11967 UIC           0 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   11968                 : 
   11969               0 :                         n->name = NULL;
   11970               0 :                         $$ = (Node *) n;
   11971                 :                     }
   11972                 :         ;
   11973                 : 
   11974                 : /*****************************************************************************
   11975                 :  *
   11976                 :  *      QUERY:
   11977                 :  *              INSERT STATEMENTS
   11978                 :  *
   11979                 :  *****************************************************************************/
   11980                 : 
   11981                 : InsertStmt:
   11982                 :             opt_with_clause INSERT INTO insert_target insert_rest
   11983                 :             opt_on_conflict returning_clause
   11984                 :                 {
   11985 CBC       43090 :                     $5->relation = $4;
   11986 GIC       43090 :                     $5->onConflictClause = $6;
   11987 CBC       43090 :                     $5->returningList = $7;
   11988           43090 :                     $5->withClause = $1;
   11989           43090 :                     $$ = (Node *) $5;
   11990                 :                 }
   11991                 :         ;
   11992                 : 
   11993                 : /*
   11994 ECB             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   11995                 :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   11996                 :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   11997                 :  * divergence from other places.  So just require AS for now.
   11998                 :  */
   11999                 : insert_target:
   12000                 :             qualified_name
   12001                 :                 {
   12002 CBC       43027 :                     $$ = $1;
   12003 ECB             :                 }
   12004                 :             | qualified_name AS ColId
   12005                 :                 {
   12006 CBC          63 :                     $1->alias = makeAlias($3, NIL);
   12007              63 :                     $$ = $1;
   12008                 :                 }
   12009                 :         ;
   12010                 : 
   12011                 : insert_rest:
   12012 ECB             :             SelectStmt
   12013                 :                 {
   12014 GIC       34846 :                     $$ = makeNode(InsertStmt);
   12015 CBC       34846 :                     $$->cols = NIL;
   12016           34846 :                     $$->selectStmt = $1;
   12017 ECB             :                 }
   12018                 :             | OVERRIDING override_kind VALUE_P SelectStmt
   12019                 :                 {
   12020 CBC          48 :                     $$ = makeNode(InsertStmt);
   12021              48 :                     $$->cols = NIL;
   12022 GIC          48 :                     $$->override = $2;
   12023 CBC          48 :                     $$->selectStmt = $4;
   12024 ECB             :                 }
   12025                 :             | '(' insert_column_list ')' SelectStmt
   12026                 :                 {
   12027 GIC        7821 :                     $$ = makeNode(InsertStmt);
   12028            7821 :                     $$->cols = $2;
   12029 CBC        7821 :                     $$->selectStmt = $4;
   12030 ECB             :                 }
   12031                 :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12032                 :                 {
   12033 UIC           0 :                     $$ = makeNode(InsertStmt);
   12034               0 :                     $$->cols = $2;
   12035               0 :                     $$->override = $5;
   12036               0 :                     $$->selectStmt = $7;
   12037                 :                 }
   12038                 :             | DEFAULT VALUES
   12039                 :                 {
   12040 GIC         375 :                     $$ = makeNode(InsertStmt);
   12041             375 :                     $$->cols = NIL;
   12042 CBC         375 :                     $$->selectStmt = NULL;
   12043                 :                 }
   12044 ECB             :         ;
   12045                 : 
   12046                 : override_kind:
   12047 GIC          30 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12048              30 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12049 ECB             :         ;
   12050                 : 
   12051                 : insert_column_list:
   12052                 :             insert_column_item
   12053 GIC        7905 :                     { $$ = list_make1($1); }
   12054                 :             | insert_column_list ',' insert_column_item
   12055           15554 :                     { $$ = lappend($1, $3); }
   12056 ECB             :         ;
   12057                 : 
   12058                 : insert_column_item:
   12059                 :             ColId opt_indirection
   12060                 :                 {
   12061 GIC       23459 :                     $$ = makeNode(ResTarget);
   12062           23459 :                     $$->name = $1;
   12063 GBC       23459 :                     $$->indirection = check_indirection($2, yyscanner);
   12064 GIC       23459 :                     $$->val = NULL;
   12065 GBC       23459 :                     $$->location = @1;
   12066 EUB             :                 }
   12067                 :         ;
   12068                 : 
   12069                 : opt_on_conflict:
   12070                 :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12071                 :                 {
   12072 GIC         572 :                     $$ = makeNode(OnConflictClause);
   12073             572 :                     $$->action = ONCONFLICT_UPDATE;
   12074             572 :                     $$->infer = $3;
   12075             572 :                     $$->targetList = $7;
   12076             572 :                     $$->whereClause = $8;
   12077             572 :                     $$->location = @1;
   12078                 :                 }
   12079                 :             |
   12080                 :             ON CONFLICT opt_conf_expr DO NOTHING
   12081 ECB             :                 {
   12082 CBC         161 :                     $$ = makeNode(OnConflictClause);
   12083             161 :                     $$->action = ONCONFLICT_NOTHING;
   12084             161 :                     $$->infer = $3;
   12085             161 :                     $$->targetList = NIL;
   12086 GIC         161 :                     $$->whereClause = NULL;
   12087             161 :                     $$->location = @1;
   12088                 :                 }
   12089                 :             | /*EMPTY*/
   12090                 :                 {
   12091           42357 :                     $$ = NULL;
   12092                 :                 }
   12093                 :         ;
   12094                 : 
   12095                 : opt_conf_expr:
   12096                 :             '(' index_params ')' where_clause
   12097                 :                 {
   12098 CBC         628 :                     $$ = makeNode(InferClause);
   12099 GIC         628 :                     $$->indexElems = $2;
   12100             628 :                     $$->whereClause = $4;
   12101             628 :                     $$->conname = NULL;
   12102 CBC         628 :                     $$->location = @1;
   12103 ECB             :                 }
   12104                 :             |
   12105                 :             ON CONSTRAINT name
   12106                 :                 {
   12107 GIC          24 :                     $$ = makeNode(InferClause);
   12108              24 :                     $$->indexElems = NIL;
   12109              24 :                     $$->whereClause = NULL;
   12110 CBC          24 :                     $$->conname = $3;
   12111              24 :                     $$->location = @1;
   12112 ECB             :                 }
   12113                 :             | /*EMPTY*/
   12114                 :                 {
   12115 GIC          81 :                     $$ = NULL;
   12116 ECB             :                 }
   12117                 :         ;
   12118                 : 
   12119                 : returning_clause:
   12120 GIC        1232 :             RETURNING target_list       { $$ = $2; }
   12121           51593 :             | /* EMPTY */               { $$ = NIL; }
   12122                 :         ;
   12123 ECB             : 
   12124                 : 
   12125                 : /*****************************************************************************
   12126                 :  *
   12127                 :  *      QUERY:
   12128                 :  *              DELETE STATEMENTS
   12129 EUB             :  *
   12130                 :  *****************************************************************************/
   12131                 : 
   12132                 : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12133                 :             using_clause where_or_current_clause returning_clause
   12134                 :                 {
   12135 GIC        2104 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12136 ECB             : 
   12137 CBC        2104 :                     n->relation = $4;
   12138            2104 :                     n->usingClause = $5;
   12139 GIC        2104 :                     n->whereClause = $6;
   12140            2104 :                     n->returningList = $7;
   12141            2104 :                     n->withClause = $1;
   12142            2104 :                     $$ = (Node *) n;
   12143 ECB             :                 }
   12144                 :         ;
   12145                 : 
   12146                 : using_clause:
   12147 GIC          54 :                 USING from_list                     { $$ = $2; }
   12148            2050 :             | /*EMPTY*/                             { $$ = NIL; }
   12149 ECB             :         ;
   12150                 : 
   12151                 : 
   12152                 : /*****************************************************************************
   12153                 :  *
   12154                 :  *      QUERY:
   12155                 :  *              LOCK TABLE
   12156                 :  *
   12157                 :  *****************************************************************************/
   12158                 : 
   12159                 : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12160                 :                 {
   12161 CBC         522 :                     LockStmt   *n = makeNode(LockStmt);
   12162                 : 
   12163 GIC         522 :                     n->relations = $3;
   12164             522 :                     n->mode = $4;
   12165             522 :                     n->nowait = $5;
   12166             522 :                     $$ = (Node *) n;
   12167                 :                 }
   12168 ECB             :         ;
   12169                 : 
   12170 CBC         476 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12171              46 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12172 ECB             :         ;
   12173                 : 
   12174 GIC         234 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12175               7 :             | ROW SHARE                     { $$ = RowShareLock; }
   12176              44 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12177              33 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12178 CBC          40 :             | SHARE                         { $$ = ShareLock; }
   12179               6 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12180              50 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12181              62 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12182 ECB             :         ;
   12183                 : 
   12184 GIC         148 : opt_nowait: NOWAIT                          { $$ = true; }
   12185             389 :             | /*EMPTY*/                     { $$ = false; }
   12186                 :         ;
   12187 ECB             : 
   12188                 : opt_nowait_or_skip:
   12189 GIC          25 :             NOWAIT                          { $$ = LockWaitError; }
   12190              95 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12191            2246 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12192                 :         ;
   12193                 : 
   12194 ECB             : 
   12195                 : /*****************************************************************************
   12196                 :  *
   12197                 :  *      QUERY:
   12198                 :  *              UpdateStmt (UPDATE)
   12199                 :  *
   12200                 :  *****************************************************************************/
   12201                 : 
   12202                 : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12203                 :             SET set_clause_list
   12204                 :             from_clause
   12205                 :             where_or_current_clause
   12206                 :             returning_clause
   12207                 :                 {
   12208 GIC        7631 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12209                 : 
   12210            7631 :                     n->relation = $3;
   12211 CBC        7631 :                     n->targetList = $5;
   12212 GIC        7631 :                     n->fromClause = $6;
   12213            7631 :                     n->whereClause = $7;
   12214            7631 :                     n->returningList = $8;
   12215            7631 :                     n->withClause = $1;
   12216 CBC        7631 :                     $$ = (Node *) n;
   12217 ECB             :                 }
   12218                 :         ;
   12219                 : 
   12220                 : set_clause_list:
   12221 GIC        8555 :             set_clause                          { $$ = $1; }
   12222            1955 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12223                 :         ;
   12224                 : 
   12225                 : set_clause:
   12226                 :             set_target '=' a_expr
   12227                 :                 {
   12228           10422 :                     $1->val = (Node *) $3;
   12229           10422 :                     $$ = list_make1($1);
   12230                 :                 }
   12231 ECB             :             | '(' set_target_list ')' '=' a_expr
   12232                 :                 {
   12233 CBC          88 :                     int         ncolumns = list_length($2);
   12234              88 :                     int         i = 1;
   12235 ECB             :                     ListCell   *col_cell;
   12236                 : 
   12237                 :                     /* Create a MultiAssignRef source for each target */
   12238 CBC         272 :                     foreach(col_cell, $2)
   12239                 :                     {
   12240 GIC         184 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12241             184 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12242                 : 
   12243 CBC         184 :                         r->source = (Node *) $5;
   12244             184 :                         r->colno = i;
   12245 GIC         184 :                         r->ncolumns = ncolumns;
   12246             184 :                         res_col->val = (Node *) r;
   12247             184 :                         i++;
   12248                 :                     }
   12249                 : 
   12250              88 :                     $$ = $2;
   12251                 :                 }
   12252                 :         ;
   12253                 : 
   12254                 : set_target:
   12255                 :             ColId opt_indirection
   12256                 :                 {
   12257 CBC       10609 :                     $$ = makeNode(ResTarget);
   12258 GIC       10609 :                     $$->name = $1;
   12259 CBC       10609 :                     $$->indirection = check_indirection($2, yyscanner);
   12260           10609 :                     $$->val = NULL;  /* upper production sets this */
   12261           10609 :                     $$->location = @1;
   12262 ECB             :                 }
   12263                 :         ;
   12264                 : 
   12265                 : set_target_list:
   12266 CBC          91 :             set_target                              { $$ = list_make1($1); }
   12267              96 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12268                 :         ;
   12269                 : 
   12270 ECB             : 
   12271                 : /*****************************************************************************
   12272                 :  *
   12273                 :  *      QUERY:
   12274                 :  *              MERGE
   12275                 :  *
   12276                 :  *****************************************************************************/
   12277                 : 
   12278                 : MergeStmt:
   12279                 :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12280                 :             USING table_ref
   12281                 :             ON a_expr
   12282                 :             merge_when_list
   12283                 :                 {
   12284 GIC         528 :                     MergeStmt  *m = makeNode(MergeStmt);
   12285 ECB             : 
   12286 CBC         528 :                     m->withClause = $1;
   12287             528 :                     m->relation = $4;
   12288 GIC         528 :                     m->sourceRelation = $6;
   12289             528 :                     m->joinCondition = $8;
   12290             528 :                     m->mergeWhenClauses = $9;
   12291                 : 
   12292             528 :                     $$ = (Node *) m;
   12293                 :                 }
   12294                 :         ;
   12295                 : 
   12296                 : merge_when_list:
   12297             528 :             merge_when_clause                       { $$ = list_make1($1); }
   12298             279 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12299                 :         ;
   12300                 : 
   12301                 : merge_when_clause:
   12302                 :             WHEN MATCHED opt_merge_when_condition THEN merge_update
   12303                 :                 {
   12304 CBC         352 :                     $5->matched = true;
   12305 GIC         352 :                     $5->condition = $3;
   12306 ECB             : 
   12307 CBC         352 :                     $$ = (Node *) $5;
   12308 ECB             :                 }
   12309                 :             | WHEN MATCHED opt_merge_when_condition THEN merge_delete
   12310                 :                 {
   12311 CBC         121 :                     $5->matched = true;
   12312             121 :                     $5->condition = $3;
   12313                 : 
   12314 GIC         121 :                     $$ = (Node *) $5;
   12315                 :                 }
   12316                 :             | WHEN NOT MATCHED opt_merge_when_condition THEN merge_insert
   12317 ECB             :                 {
   12318 CBC         319 :                     $6->matched = false;
   12319 GIC         319 :                     $6->condition = $4;
   12320                 : 
   12321             319 :                     $$ = (Node *) $6;
   12322                 :                 }
   12323                 :             | WHEN MATCHED opt_merge_when_condition THEN DO NOTHING
   12324 ECB             :                 {
   12325 CBC          11 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12326                 : 
   12327 GIC          11 :                     m->matched = true;
   12328              11 :                     m->commandType = CMD_NOTHING;
   12329 CBC          11 :                     m->condition = $3;
   12330 ECB             : 
   12331 GIC          11 :                     $$ = (Node *) m;
   12332                 :                 }
   12333                 :             | WHEN NOT MATCHED opt_merge_when_condition THEN DO NOTHING
   12334 ECB             :                 {
   12335 GIC           4 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12336 ECB             : 
   12337 CBC           4 :                     m->matched = false;
   12338 GIC           4 :                     m->commandType = CMD_NOTHING;
   12339 CBC           4 :                     m->condition = $4;
   12340 ECB             : 
   12341 CBC           4 :                     $$ = (Node *) m;
   12342 ECB             :                 }
   12343                 :         ;
   12344                 : 
   12345                 : opt_merge_when_condition:
   12346 CBC         215 :             AND a_expr              { $$ = $2; }
   12347 GIC         607 :             |                       { $$ = NULL; }
   12348                 :         ;
   12349                 : 
   12350                 : merge_update:
   12351                 :             UPDATE SET set_clause_list
   12352                 :                 {
   12353 CBC         352 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12354             352 :                     n->commandType = CMD_UPDATE;
   12355             352 :                     n->override = OVERRIDING_NOT_SET;
   12356             352 :                     n->targetList = $3;
   12357             352 :                     n->values = NIL;
   12358                 : 
   12359 GIC         352 :                     $$ = n;
   12360                 :                 }
   12361                 :         ;
   12362 ECB             : 
   12363                 : merge_delete:
   12364                 :             DELETE_P
   12365                 :                 {
   12366 GIC         121 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12367             121 :                     n->commandType = CMD_DELETE;
   12368             121 :                     n->override = OVERRIDING_NOT_SET;
   12369             121 :                     n->targetList = NIL;
   12370             121 :                     n->values = NIL;
   12371                 : 
   12372             121 :                     $$ = n;
   12373                 :                 }
   12374                 :         ;
   12375                 : 
   12376                 : merge_insert:
   12377                 :             INSERT merge_values_clause
   12378                 :                 {
   12379             217 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12380 CBC         217 :                     n->commandType = CMD_INSERT;
   12381 GIC         217 :                     n->override = OVERRIDING_NOT_SET;
   12382 CBC         217 :                     n->targetList = NIL;
   12383             217 :                     n->values = $2;
   12384             217 :                     $$ = n;
   12385 ECB             :                 }
   12386                 :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12387                 :                 {
   12388 LBC           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12389 UIC           0 :                     n->commandType = CMD_INSERT;
   12390               0 :                     n->override = $3;
   12391               0 :                     n->targetList = NIL;
   12392               0 :                     n->values = $5;
   12393 LBC           0 :                     $$ = n;
   12394 ECB             :                 }
   12395                 :             | INSERT '(' insert_column_list ')' merge_values_clause
   12396                 :                 {
   12397 GIC          72 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12398              72 :                     n->commandType = CMD_INSERT;
   12399              72 :                     n->override = OVERRIDING_NOT_SET;
   12400 CBC          72 :                     n->targetList = $3;
   12401              72 :                     n->values = $5;
   12402 GIC          72 :                     $$ = n;
   12403 ECB             :                 }
   12404                 :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12405                 :                 {
   12406 GIC          12 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12407 CBC          12 :                     n->commandType = CMD_INSERT;
   12408              12 :                     n->override = $6;
   12409 GIC          12 :                     n->targetList = $3;
   12410 CBC          12 :                     n->values = $8;
   12411 GIC          12 :                     $$ = n;
   12412                 :                 }
   12413                 :             | INSERT DEFAULT VALUES
   12414 ECB             :                 {
   12415 CBC          18 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12416 GIC          18 :                     n->commandType = CMD_INSERT;
   12417 CBC          18 :                     n->override = OVERRIDING_NOT_SET;
   12418 GIC          18 :                     n->targetList = NIL;
   12419              18 :                     n->values = NIL;
   12420              18 :                     $$ = n;
   12421 ECB             :                 }
   12422                 :         ;
   12423                 : 
   12424                 : merge_values_clause:
   12425                 :             VALUES '(' expr_list ')'
   12426                 :                 {
   12427 CBC         301 :                     $$ = $3;
   12428                 :                 }
   12429                 :         ;
   12430                 : 
   12431 ECB             : /*****************************************************************************
   12432                 :  *
   12433                 :  *      QUERY:
   12434                 :  *              CURSOR STATEMENTS
   12435                 :  *
   12436                 :  *****************************************************************************/
   12437                 : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   12438                 :                 {
   12439 GIC        1381 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   12440                 : 
   12441            1381 :                     n->portalname = $2;
   12442 ECB             :                     /* currently we always set FAST_PLAN option */
   12443 CBC        1381 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   12444 GIC        1381 :                     n->query = $7;
   12445            1381 :                     $$ = (Node *) n;
   12446                 :                 }
   12447                 :         ;
   12448                 : 
   12449 CBC        5392 : cursor_name:    name                        { $$ = $1; }
   12450 ECB             :         ;
   12451                 : 
   12452 CBC        1381 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   12453              52 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   12454 GIC         120 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   12455 CBC           5 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   12456 UIC           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   12457 GIC           3 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   12458                 :         ;
   12459                 : 
   12460            1332 : opt_hold: /* EMPTY */                       { $$ = 0; }
   12461              46 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   12462 CBC           3 :             | WITHOUT HOLD                  { $$ = 0; }
   12463 ECB             :         ;
   12464                 : 
   12465                 : /*****************************************************************************
   12466                 :  *
   12467                 :  *      QUERY:
   12468                 :  *              SELECT STATEMENTS
   12469                 :  *
   12470                 :  *****************************************************************************/
   12471                 : 
   12472                 : /* A complete SELECT statement looks like this.
   12473                 :  *
   12474                 :  * The rule returns either a single SelectStmt node or a tree of them,
   12475                 :  * representing a set-operation tree.
   12476                 :  *
   12477                 :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   12478                 :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   12479                 :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   12480                 :  * To resolve the ambiguity, we are careful to define the grammar so that
   12481                 :  * the decision is staved off as long as possible: as long as we can keep
   12482                 :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   12483                 :  * it's no longer possible to do that will we decide that parens belong to
   12484 EUB             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   12485                 :  * parentheses are treated as part of the sub-select.  The necessity of doing
   12486                 :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   12487                 :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   12488                 :  * SELECT viewpoint when we see the UNION.
   12489                 :  *
   12490                 :  * This approach is implemented by defining a nonterminal select_with_parens,
   12491                 :  * which represents a SELECT with at least one outer layer of parentheses,
   12492                 :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   12493 ECB             :  * in the expression grammar.  We will then have shift-reduce conflicts
   12494                 :  * which we can resolve in favor of always treating '(' <select> ')' as
   12495                 :  * a select_with_parens.  To resolve the conflicts, the productions that
   12496                 :  * conflict with the select_with_parens productions are manually given
   12497                 :  * precedences lower than the precedence of ')', thereby ensuring that we
   12498                 :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   12499                 :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   12500                 :  * precedence for this, which is a fairly arbitrary choice.
   12501                 :  *
   12502                 :  * To be able to define select_with_parens itself without ambiguity, we need
   12503                 :  * a nonterminal select_no_parens that represents a SELECT structure with no
   12504                 :  * outermost parentheses.  This is a little bit tedious, but it works.
   12505                 :  *
   12506                 :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   12507                 :  * with or without outer parentheses.
   12508                 :  */
   12509                 : 
   12510                 : SelectStmt: select_no_parens            %prec UMINUS
   12511                 :             | select_with_parens        %prec UMINUS
   12512                 :         ;
   12513                 : 
   12514                 : select_with_parens:
   12515 CBC       44838 :             '(' select_no_parens ')'                { $$ = $2; }
   12516              75 :             | '(' select_with_parens ')'            { $$ = $2; }
   12517                 :         ;
   12518                 : 
   12519                 : /*
   12520                 :  * This rule parses the equivalent of the standard's <query expression>.
   12521                 :  * The duplicative productions are annoying, but hard to get rid of without
   12522                 :  * creating shift/reduce conflicts.
   12523 ECB             :  *
   12524                 :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   12525                 :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   12526                 :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   12527                 :  * clause.
   12528                 :  *  2002-08-28 bjm
   12529                 :  */
   12530                 : select_no_parens:
   12531 GIC      243746 :             simple_select                       { $$ = $1; }
   12532                 :             | select_clause sort_clause
   12533                 :                 {
   12534           24082 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   12535 ECB             :                                         NULL, NULL,
   12536                 :                                         yyscanner);
   12537 CBC       24082 :                     $$ = $1;
   12538                 :                 }
   12539 ECB             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   12540                 :                 {
   12541 CBC        2144 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   12542 GIC        2144 :                                         $4,
   12543                 :                                         NULL,
   12544                 :                                         yyscanner);
   12545 CBC        2144 :                     $$ = $1;
   12546                 :                 }
   12547                 :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   12548 ECB             :                 {
   12549 CBC        2984 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   12550            2984 :                                         $3,
   12551 ECB             :                                         NULL,
   12552 EUB             :                                         yyscanner);
   12553 CBC        2978 :                     $$ = $1;
   12554                 :                 }
   12555                 :             | with_clause select_clause
   12556 ECB             :                 {
   12557 CBC         809 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   12558 ECB             :                                         NULL,
   12559 GIC         809 :                                         $1,
   12560                 :                                         yyscanner);
   12561             809 :                     $$ = $2;
   12562                 :                 }
   12563                 :             | with_clause select_clause sort_clause
   12564                 :                 {
   12565             194 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   12566                 :                                         NULL,
   12567             194 :                                         $1,
   12568                 :                                         yyscanner);
   12569             194 :                     $$ = $2;
   12570                 :                 }
   12571                 :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   12572                 :                 {
   12573               3 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   12574               3 :                                         $5,
   12575               3 :                                         $1,
   12576                 :                                         yyscanner);
   12577               3 :                     $$ = $2;
   12578                 :                 }
   12579                 :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   12580                 :                 {
   12581              32 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   12582              32 :                                         $4,
   12583              32 :                                         $1,
   12584                 :                                         yyscanner);
   12585              32 :                     $$ = $2;
   12586                 :                 }
   12587                 :         ;
   12588                 : 
   12589                 : select_clause:
   12590           63356 :             simple_select                           { $$ = $1; }
   12591             230 :             | select_with_parens                    { $$ = $1; }
   12592                 :         ;
   12593                 : 
   12594                 : /*
   12595                 :  * This rule parses SELECT statements that can appear within set operations,
   12596                 :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   12597                 :  * the ordering of the set operations.  Without '(' and ')' we want the
   12598                 :  * operations to be ordered per the precedence specs at the head of this file.
   12599                 :  *
   12600                 :  * As with select_no_parens, simple_select cannot have outer parentheses,
   12601                 :  * but can have parenthesized subclauses.
   12602                 :  *
   12603                 :  * It might appear that we could fold the first two alternatives into one
   12604                 :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   12605                 :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   12606                 :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   12607                 :  *
   12608                 :  * Note that sort clauses cannot be included at this level --- SQL requires
   12609                 :  *      SELECT foo UNION SELECT bar ORDER BY baz
   12610                 :  * to be parsed as
   12611 ECB             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   12612                 :  * not
   12613                 :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   12614                 :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   12615                 :  * described as part of the select_no_parens production, not simple_select.
   12616                 :  * This does not limit functionality, because you can reintroduce these
   12617                 :  * clauses inside parentheses.
   12618                 :  *
   12619                 :  * NOTE: only the leftmost component SelectStmt should have INTO.
   12620                 :  * However, this is not checked by the grammar; parse analysis must check it.
   12621                 :  */
   12622                 : simple_select:
   12623                 :             SELECT opt_all_clause opt_target_list
   12624                 :             into_clause from_clause where_clause
   12625                 :             group_clause having_clause window_clause
   12626                 :                 {
   12627 CBC      246886 :                     SelectStmt *n = makeNode(SelectStmt);
   12628                 : 
   12629 GIC      246886 :                     n->targetList = $3;
   12630 CBC      246886 :                     n->intoClause = $4;
   12631 GIC      246886 :                     n->fromClause = $5;
   12632          246886 :                     n->whereClause = $6;
   12633 CBC      246886 :                     n->groupClause = ($7)->list;
   12634 GIC      246886 :                     n->groupDistinct = ($7)->distinct;
   12635          246886 :                     n->havingClause = $8;
   12636          246886 :                     n->windowClause = $9;
   12637 CBC      246886 :                     $$ = (Node *) n;
   12638 ECB             :                 }
   12639                 :             | SELECT distinct_clause target_list
   12640                 :             into_clause from_clause where_clause
   12641                 :             group_clause having_clause window_clause
   12642                 :                 {
   12643 GIC        3996 :                     SelectStmt *n = makeNode(SelectStmt);
   12644                 : 
   12645 CBC        3996 :                     n->distinctClause = $2;
   12646            3996 :                     n->targetList = $3;
   12647 GIC        3996 :                     n->intoClause = $4;
   12648            3996 :                     n->fromClause = $5;
   12649 CBC        3996 :                     n->whereClause = $6;
   12650 GIC        3996 :                     n->groupClause = ($7)->list;
   12651            3996 :                     n->groupDistinct = ($7)->distinct;
   12652            3996 :                     n->havingClause = $8;
   12653 CBC        3996 :                     n->windowClause = $9;
   12654 GIC        3996 :                     $$ = (Node *) n;
   12655 ECB             :                 }
   12656 GIC       39445 :             | values_clause                         { $$ = $1; }
   12657 ECB             :             | TABLE relation_expr
   12658                 :                 {
   12659                 :                     /* same as SELECT * FROM relation_expr */
   12660 GIC         109 :                     ColumnRef  *cr = makeNode(ColumnRef);
   12661 CBC         109 :                     ResTarget  *rt = makeNode(ResTarget);
   12662 GIC         109 :                     SelectStmt *n = makeNode(SelectStmt);
   12663 ECB             : 
   12664 GIC         109 :                     cr->fields = list_make1(makeNode(A_Star));
   12665 CBC         109 :                     cr->location = -1;
   12666                 : 
   12667 GIC         109 :                     rt->name = NULL;
   12668             109 :                     rt->indirection = NIL;
   12669 CBC         109 :                     rt->val = (Node *) cr;
   12670             109 :                     rt->location = -1;
   12671 ECB             : 
   12672 GIC         109 :                     n->targetList = list_make1(rt);
   12673 CBC         109 :                     n->fromClause = list_make1($2);
   12674 GIC         109 :                     $$ = (Node *) n;
   12675                 :                 }
   12676                 :             | select_clause UNION set_quantifier select_clause
   12677 ECB             :                 {
   12678 CBC       16321 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
   12679 ECB             :                 }
   12680                 :             | select_clause INTERSECT set_quantifier select_clause
   12681                 :                 {
   12682 GIC         126 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   12683                 :                 }
   12684                 :             | select_clause EXCEPT set_quantifier select_clause
   12685                 :                 {
   12686 CBC         219 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   12687 ECB             :                 }
   12688                 :         ;
   12689                 : 
   12690                 : /*
   12691                 :  * SQL standard WITH clause looks like:
   12692                 :  *
   12693                 :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   12694                 :  *      AS (query) [ SEARCH or CYCLE clause ]
   12695                 :  *
   12696                 :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   12697                 :  */
   12698                 : with_clause:
   12699                 :         WITH cte_list
   12700                 :             {
   12701 GIC         989 :                 $$ = makeNode(WithClause);
   12702             989 :                 $$->ctes = $2;
   12703             989 :                 $$->recursive = false;
   12704             989 :                 $$->location = @1;
   12705                 :             }
   12706                 :         | WITH_LA cte_list
   12707                 :             {
   12708               3 :                 $$ = makeNode(WithClause);
   12709               3 :                 $$->ctes = $2;
   12710               3 :                 $$->recursive = false;
   12711               3 :                 $$->location = @1;
   12712                 :             }
   12713                 :         | WITH RECURSIVE cte_list
   12714                 :             {
   12715             500 :                 $$ = makeNode(WithClause);
   12716             500 :                 $$->ctes = $3;
   12717             500 :                 $$->recursive = true;
   12718             500 :                 $$->location = @1;
   12719                 :             }
   12720                 :         ;
   12721                 : 
   12722                 : cte_list:
   12723 CBC        1492 :         common_table_expr                       { $$ = list_make1($1); }
   12724 GIC         381 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   12725 ECB             :         ;
   12726                 : 
   12727                 : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   12728                 :             {
   12729 CBC        1873 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   12730 ECB             : 
   12731 CBC        1873 :                 n->ctename = $1;
   12732            1873 :                 n->aliascolnames = $2;
   12733            1873 :                 n->ctematerialized = $4;
   12734 GIC        1873 :                 n->ctequery = $6;
   12735            1873 :                 n->search_clause = castNode(CTESearchClause, $8);
   12736            1873 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   12737            1873 :                 n->location = @1;
   12738            1873 :                 $$ = (Node *) n;
   12739 ECB             :             }
   12740                 :         ;
   12741                 : 
   12742                 : opt_materialized:
   12743 CBC          62 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   12744              21 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   12745            1790 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   12746 ECB             :         ;
   12747                 : 
   12748                 : opt_search_clause:
   12749                 :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   12750                 :             {
   12751 GIC          45 :                 CTESearchClause *n = makeNode(CTESearchClause);
   12752 ECB             : 
   12753 GIC          45 :                 n->search_col_list = $5;
   12754              45 :                 n->search_breadth_first = false;
   12755              45 :                 n->search_seq_column = $7;
   12756 CBC          45 :                 n->location = @1;
   12757              45 :                 $$ = (Node *) n;
   12758 ECB             :             }
   12759                 :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   12760                 :             {
   12761 CBC          18 :                 CTESearchClause *n = makeNode(CTESearchClause);
   12762                 : 
   12763              18 :                 n->search_col_list = $5;
   12764              18 :                 n->search_breadth_first = true;
   12765              18 :                 n->search_seq_column = $7;
   12766              18 :                 n->location = @1;
   12767 GIC          18 :                 $$ = (Node *) n;
   12768 ECB             :             }
   12769                 :         | /*EMPTY*/
   12770                 :             {
   12771 GIC        1810 :                 $$ = NULL;
   12772                 :             }
   12773                 :         ;
   12774 ECB             : 
   12775                 : opt_cycle_clause:
   12776                 :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   12777                 :             {
   12778 CBC          33 :                 CTECycleClause *n = makeNode(CTECycleClause);
   12779                 : 
   12780 GIC          33 :                 n->cycle_col_list = $2;
   12781              33 :                 n->cycle_mark_column = $4;
   12782 CBC          33 :                 n->cycle_mark_value = $6;
   12783 GIC          33 :                 n->cycle_mark_default = $8;
   12784              33 :                 n->cycle_path_column = $10;
   12785              33 :                 n->location = @1;
   12786              33 :                 $$ = (Node *) n;
   12787                 :             }
   12788                 :         | CYCLE columnList SET ColId USING ColId
   12789                 :             {
   12790              30 :                 CTECycleClause *n = makeNode(CTECycleClause);
   12791                 : 
   12792              30 :                 n->cycle_col_list = $2;
   12793              30 :                 n->cycle_mark_column = $4;
   12794              30 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   12795              30 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   12796              30 :                 n->cycle_path_column = $6;
   12797 CBC          30 :                 n->location = @1;
   12798              30 :                 $$ = (Node *) n;
   12799 ECB             :             }
   12800                 :         | /*EMPTY*/
   12801                 :             {
   12802 GIC        1810 :                 $$ = NULL;
   12803                 :             }
   12804 ECB             :         ;
   12805                 : 
   12806                 : opt_with_clause:
   12807 CBC         454 :         with_clause                             { $$ = $1; }
   12808 GIC       52945 :         | /*EMPTY*/                             { $$ = NULL; }
   12809                 :         ;
   12810                 : 
   12811 ECB             : into_clause:
   12812                 :             INTO OptTempTableName
   12813                 :                 {
   12814 CBC          64 :                     $$ = makeNode(IntoClause);
   12815 GIC          64 :                     $$->rel = $2;
   12816              64 :                     $$->colNames = NIL;
   12817              64 :                     $$->options = NIL;
   12818              64 :                     $$->onCommit = ONCOMMIT_NOOP;
   12819 CBC          64 :                     $$->tableSpaceName = NULL;
   12820              64 :                     $$->viewQuery = NULL;
   12821 GIC          64 :                     $$->skipData = false;
   12822                 :                 }
   12823                 :             | /*EMPTY*/
   12824          250821 :                 { $$ = NULL; }
   12825 ECB             :         ;
   12826                 : 
   12827                 : /*
   12828                 :  * Redundancy here is needed to avoid shift/reduce conflicts,
   12829                 :  * since TEMP is not a reserved word.  See also OptTemp.
   12830                 :  */
   12831                 : OptTempTableName:
   12832                 :             TEMPORARY opt_table qualified_name
   12833                 :                 {
   12834 LBC           0 :                     $$ = $3;
   12835 UIC           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12836                 :                 }
   12837                 :             | TEMP opt_table qualified_name
   12838                 :                 {
   12839 CBC           3 :                     $$ = $3;
   12840               3 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12841 ECB             :                 }
   12842                 :             | LOCAL TEMPORARY opt_table qualified_name
   12843                 :                 {
   12844 UIC           0 :                     $$ = $4;
   12845               0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12846                 :                 }
   12847 ECB             :             | LOCAL TEMP opt_table qualified_name
   12848                 :                 {
   12849 LBC           0 :                     $$ = $4;
   12850               0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12851 ECB             :                 }
   12852                 :             | GLOBAL TEMPORARY opt_table qualified_name
   12853                 :                 {
   12854 UIC           0 :                     ereport(WARNING,
   12855                 :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   12856                 :                              parser_errposition(@1)));
   12857 LBC           0 :                     $$ = $4;
   12858 UIC           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12859 ECB             :                 }
   12860                 :             | GLOBAL TEMP opt_table qualified_name
   12861                 :                 {
   12862 LBC           0 :                     ereport(WARNING,
   12863 ECB             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   12864                 :                              parser_errposition(@1)));
   12865 UIC           0 :                     $$ = $4;
   12866               0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   12867 ECB             :                 }
   12868                 :             | UNLOGGED opt_table qualified_name
   12869                 :                 {
   12870 UIC           0 :                     $$ = $3;
   12871               0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   12872                 :                 }
   12873                 :             | TABLE qualified_name
   12874 ECB             :                 {
   12875 GIC          15 :                     $$ = $2;
   12876 CBC          15 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   12877 ECB             :                 }
   12878                 :             | qualified_name
   12879                 :                 {
   12880 CBC          46 :                     $$ = $1;
   12881              46 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   12882 ECB             :                 }
   12883                 :         ;
   12884                 : 
   12885                 : opt_table:  TABLE
   12886                 :             | /*EMPTY*/
   12887                 :         ;
   12888                 : 
   12889                 : set_quantifier:
   12890 CBC       11962 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   12891              16 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   12892            7247 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   12893 ECB             :         ;
   12894                 : 
   12895                 : /* We use (NIL) as a placeholder to indicate that all target expressions
   12896                 :  * should be placed in the DISTINCT list during parsetree analysis.
   12897                 :  */
   12898                 : distinct_clause:
   12899 GIC        3918 :             DISTINCT                                { $$ = list_make1(NIL); }
   12900              81 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   12901                 :         ;
   12902                 : 
   12903 ECB             : opt_all_clause:
   12904                 :             ALL
   12905                 :             | /*EMPTY*/
   12906                 :         ;
   12907                 : 
   12908                 : opt_distinct_clause:
   12909 UIC           0 :             distinct_clause                         { $$ = $1; }
   12910 CBC       17582 :             | opt_all_clause                        { $$ = NIL; }
   12911 ECB             :         ;
   12912                 : 
   12913                 : opt_sort_clause:
   12914 CBC        4599 :             sort_clause                             { $$ = $1; }
   12915          263024 :             | /*EMPTY*/                             { $$ = NIL; }
   12916 ECB             :         ;
   12917                 : 
   12918                 : sort_clause:
   12919 GIC       29049 :             ORDER BY sortby_list                    { $$ = $3; }
   12920 ECB             :         ;
   12921                 : 
   12922                 : sortby_list:
   12923 GIC       29058 :             sortby                                  { $$ = list_make1($1); }
   12924           12627 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   12925                 :         ;
   12926                 : 
   12927                 : sortby:     a_expr USING qual_all_Op opt_nulls_order
   12928                 :                 {
   12929             110 :                     $$ = makeNode(SortBy);
   12930 GBC         110 :                     $$->node = $1;
   12931             110 :                     $$->sortby_dir = SORTBY_USING;
   12932 GIC         110 :                     $$->sortby_nulls = $4;
   12933             110 :                     $$->useOp = $3;
   12934             110 :                     $$->location = @3;
   12935 ECB             :                 }
   12936                 :             | a_expr opt_asc_desc opt_nulls_order
   12937                 :                 {
   12938 GIC       41575 :                     $$ = makeNode(SortBy);
   12939           41575 :                     $$->node = $1;
   12940 GBC       41575 :                     $$->sortby_dir = $2;
   12941           41575 :                     $$->sortby_nulls = $3;
   12942 GIC       41575 :                     $$->useOp = NIL;
   12943           41575 :                     $$->location = -1;       /* no operator */
   12944                 :                 }
   12945 EUB             :         ;
   12946                 : 
   12947                 : 
   12948                 : select_limit:
   12949                 :             limit_clause offset_clause
   12950                 :                 {
   12951 GIC          81 :                     $$ = $1;
   12952              81 :                     ($$)->limitOffset = $2;
   12953 EUB             :                 }
   12954                 :             | offset_clause limit_clause
   12955                 :                 {
   12956 GIC         106 :                     $$ = $2;
   12957             106 :                     ($$)->limitOffset = $1;
   12958 EUB             :                 }
   12959                 :             | limit_clause
   12960                 :                 {
   12961 GBC        2752 :                     $$ = $1;
   12962 EUB             :                 }
   12963                 :             | offset_clause
   12964                 :                 {
   12965 GIC         172 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   12966 EUB             : 
   12967 GBC         172 :                     n->limitOffset = $1;
   12968 GIC         172 :                     n->limitCount = NULL;
   12969             172 :                     n->limitOption = LIMIT_OPTION_COUNT;
   12970             172 :                     $$ = n;
   12971 ECB             :                 }
   12972                 :         ;
   12973                 : 
   12974                 : opt_select_limit:
   12975 GIC          95 :             select_limit                        { $$ = $1; }
   12976 CBC       19634 :             | /* EMPTY */                       { $$ = NULL; }
   12977 ECB             :         ;
   12978                 : 
   12979                 : limit_clause:
   12980                 :             LIMIT select_limit_value
   12981                 :                 {
   12982 GIC        2899 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   12983                 : 
   12984            2899 :                     n->limitOffset = NULL;
   12985            2899 :                     n->limitCount = $2;
   12986 CBC        2899 :                     n->limitOption = LIMIT_OPTION_COUNT;
   12987            2899 :                     $$ = n;
   12988 ECB             :                 }
   12989                 :             | LIMIT select_limit_value ',' select_offset_value
   12990                 :                 {
   12991                 :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   12992 UIC           0 :                     ereport(ERROR,
   12993                 :                             (errcode(ERRCODE_SYNTAX_ERROR),
   12994                 :                              errmsg("LIMIT #,# syntax is not supported"),
   12995 ECB             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   12996                 :                              parser_errposition(@1)));
   12997                 :                 }
   12998                 :             /* SQL:2008 syntax */
   12999                 :             /* to avoid shift/reduce conflicts, handle the optional value with
   13000                 :              * a separate production rather than an opt_ expression.  The fact
   13001                 :              * that ONLY is fully reserved means that this way, we defer any
   13002                 :              * decision about what rule reduces ROW or ROWS to the point where
   13003                 :              * we can see the ONLY token in the lookahead slot.
   13004                 :              */
   13005 EUB             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13006 ECB             :                 {
   13007 GIC          10 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13008                 : 
   13009              10 :                     n->limitOffset = NULL;
   13010 CBC          10 :                     n->limitCount = $3;
   13011              10 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13012 GIC          10 :                     $$ = n;
   13013                 :                 }
   13014                 :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13015 ECB             :                 {
   13016 GIC          27 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13017                 : 
   13018              27 :                     n->limitOffset = NULL;
   13019 CBC          27 :                     n->limitCount = $3;
   13020              27 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13021 GIC          27 :                     $$ = n;
   13022                 :                 }
   13023                 :             | FETCH first_or_next row_or_rows ONLY
   13024                 :                 {
   13025 LBC           0 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13026 ECB             : 
   13027 LBC           0 :                     n->limitOffset = NULL;
   13028               0 :                     n->limitCount = makeIntConst(1, -1);
   13029               0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13030               0 :                     $$ = n;
   13031                 :                 }
   13032                 :             | FETCH first_or_next row_or_rows WITH TIES
   13033                 :                 {
   13034 CBC           3 :                     SelectLimit *n = (SelectLimit *) palloc(sizeof(SelectLimit));
   13035 ECB             : 
   13036 CBC           3 :                     n->limitOffset = NULL;
   13037               3 :                     n->limitCount = makeIntConst(1, -1);
   13038               3 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13039               3 :                     $$ = n;
   13040                 :                 }
   13041                 :         ;
   13042                 : 
   13043                 : offset_clause:
   13044                 :             OFFSET select_offset_value
   13045 GIC         359 :                 { $$ = $2; }
   13046                 :             /* SQL:2008 syntax */
   13047 ECB             :             | OFFSET select_fetch_first_value row_or_rows
   13048 LBC           0 :                 { $$ = $2; }
   13049                 :         ;
   13050                 : 
   13051                 : select_limit_value:
   13052 CBC        2898 :             a_expr                                  { $$ = $1; }
   13053 ECB             :             | ALL
   13054                 :                 {
   13055                 :                     /* LIMIT ALL is represented as a NULL constant */
   13056 GIC           1 :                     $$ = makeNullAConst(@1);
   13057 ECB             :                 }
   13058                 :         ;
   13059                 : 
   13060                 : select_offset_value:
   13061 CBC         359 :             a_expr                                  { $$ = $1; }
   13062                 :         ;
   13063 ECB             : 
   13064                 : /*
   13065                 :  * Allowing full expressions without parentheses causes various parsing
   13066                 :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13067                 :  * <simple value specification>, which is either a literal or a parameter (but
   13068                 :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13069                 :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13070                 :  * to determine whether the expression is missing rather than trying to make it
   13071                 :  * optional in this rule.
   13072                 :  *
   13073                 :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13074                 :  * cover signed numeric literals, which are allowed by the spec. So we include
   13075                 :  * those here explicitly. We need FCONST as well as ICONST because values that
   13076                 :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13077                 :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13078                 :  * builds.)
   13079                 :  */
   13080                 : select_fetch_first_value:
   13081 CBC          37 :             c_expr                                  { $$ = $1; }
   13082 ECB             :             | '+' I_or_F_const
   13083 LBC           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13084                 :             | '-' I_or_F_const
   13085 UIC           0 :                 { $$ = doNegate($2, @1); }
   13086                 :         ;
   13087                 : 
   13088 EUB             : I_or_F_const:
   13089 UIC           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13090               0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13091                 :         ;
   13092                 : 
   13093                 : /* noise words */
   13094 GIC          16 : row_or_rows: ROW                                    { $$ = 0; }
   13095              24 :             | ROWS                                  { $$ = 0; }
   13096                 :         ;
   13097                 : 
   13098              40 : first_or_next: FIRST_P                              { $$ = 0; }
   13099 UIC           0 :             | NEXT                                  { $$ = 0; }
   13100                 :         ;
   13101                 : 
   13102                 : 
   13103 ECB             : /*
   13104                 :  * This syntax for group_clause tries to follow the spec quite closely.
   13105                 :  * However, the spec allows only column references, not expressions,
   13106                 :  * which introduces an ambiguity between implicit row constructors
   13107                 :  * (a,b) and lists of column references.
   13108                 :  *
   13109                 :  * We handle this by using the a_expr production for what the spec calls
   13110                 :  * <ordinary grouping set>, which in the spec represents either one column
   13111                 :  * reference or a parenthesized list of column references. Then, we check the
   13112                 :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13113                 :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13114                 :  * not here)
   13115                 :  *
   13116                 :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13117                 :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13118                 :  * in a group clause, but if they have a reason to, we make it possible.)
   13119                 :  *
   13120                 :  * Each item in the group_clause list is either an expression tree or a
   13121 EUB             :  * GroupingSet node of some type.
   13122                 :  */
   13123                 : group_clause:
   13124                 :             GROUP_P BY set_quantifier group_by_list
   13125                 :                 {
   13126 GBC        2553 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13127                 : 
   13128 GIC        2553 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13129            2553 :                     n->list = $4;
   13130 CBC        2553 :                     $$ = n;
   13131                 :                 }
   13132 ECB             :             | /*EMPTY*/
   13133                 :                 {
   13134 CBC      265911 :                     GroupClause *n = (GroupClause *) palloc(sizeof(GroupClause));
   13135 ECB             : 
   13136 GIC      265911 :                     n->distinct = false;
   13137          265911 :                     n->list = NIL;
   13138          265911 :                     $$ = n;
   13139                 :                 }
   13140                 :         ;
   13141 ECB             : 
   13142                 : group_by_list:
   13143 GIC        2798 :             group_by_item                           { $$ = list_make1($1); }
   13144 GBC        2361 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13145                 :         ;
   13146                 : 
   13147                 : group_by_item:
   13148 CBC        4586 :             a_expr                                  { $$ = $1; }
   13149 GIC         111 :             | empty_grouping_set                    { $$ = $1; }
   13150              92 :             | cube_clause                           { $$ = $1; }
   13151             125 :             | rollup_clause                         { $$ = $1; }
   13152 CBC         245 :             | grouping_sets_clause                  { $$ = $1; }
   13153                 :         ;
   13154                 : 
   13155                 : empty_grouping_set:
   13156                 :             '(' ')'
   13157 ECB             :                 {
   13158 GIC         111 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13159                 :                 }
   13160                 :         ;
   13161                 : 
   13162                 : /*
   13163                 :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13164                 :  * so that they shift in these rules rather than reducing the conflicting
   13165                 :  * unreserved_keyword rule.
   13166                 :  */
   13167                 : 
   13168                 : rollup_clause:
   13169                 :             ROLLUP '(' expr_list ')'
   13170                 :                 {
   13171             125 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13172                 :                 }
   13173                 :         ;
   13174                 : 
   13175                 : cube_clause:
   13176                 :             CUBE '(' expr_list ')'
   13177 ECB             :                 {
   13178 GIC          92 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13179 EUB             :                 }
   13180                 :         ;
   13181                 : 
   13182                 : grouping_sets_clause:
   13183                 :             GROUPING SETS '(' group_by_list ')'
   13184                 :                 {
   13185 GBC         245 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13186 EUB             :                 }
   13187                 :         ;
   13188                 : 
   13189                 : having_clause:
   13190 CBC         263 :             HAVING a_expr                           { $$ = $2; }
   13191          268201 :             | /*EMPTY*/                             { $$ = NULL; }
   13192                 :         ;
   13193                 : 
   13194 ECB             : for_locking_clause:
   13195 GBC        2317 :             for_locking_items                       { $$ = $1; }
   13196 UIC           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13197                 :         ;
   13198                 : 
   13199                 : opt_for_locking_clause:
   13200 GIC         170 :             for_locking_clause                      { $$ = $1; }
   13201           20428 :             | /* EMPTY */                           { $$ = NIL; }
   13202                 :         ;
   13203                 : 
   13204                 : for_locking_items:
   13205            2317 :             for_locking_item                        { $$ = list_make1($1); }
   13206              49 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13207                 :         ;
   13208                 : 
   13209                 : for_locking_item:
   13210                 :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13211                 :                 {
   13212            2366 :                     LockingClause *n = makeNode(LockingClause);
   13213                 : 
   13214            2366 :                     n->lockedRels = $2;
   13215            2366 :                     n->strength = $1;
   13216            2366 :                     n->waitPolicy = $3;
   13217            2366 :                     $$ = (Node *) n;
   13218                 :                 }
   13219                 :         ;
   13220                 : 
   13221                 : for_locking_strength:
   13222 CBC         725 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13223 GIC          33 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13224 CBC         107 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13225            1501 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13226 ECB             :         ;
   13227                 : 
   13228                 : locked_rels_list:
   13229 GIC        1504 :             OF qualified_name_list                  { $$ = $2; }
   13230 CBC         862 :             | /* EMPTY */                           { $$ = NIL; }
   13231                 :         ;
   13232 ECB             : 
   13233                 : 
   13234                 : /*
   13235                 :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13236                 :  * making VALUES a fully reserved word, which will probably break more apps
   13237                 :  * than allowing the noise-word is worth.
   13238                 :  */
   13239                 : values_clause:
   13240                 :             VALUES '(' expr_list ')'
   13241                 :                 {
   13242 GIC       39445 :                     SelectStmt *n = makeNode(SelectStmt);
   13243                 : 
   13244 CBC       39445 :                     n->valuesLists = list_make1($3);
   13245           39445 :                     $$ = (Node *) n;
   13246 ECB             :                 }
   13247                 :             | values_clause ',' '(' expr_list ')'
   13248                 :                 {
   13249 GIC       82144 :                     SelectStmt *n = (SelectStmt *) $1;
   13250                 : 
   13251           82144 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13252           82144 :                     $$ = (Node *) n;
   13253                 :                 }
   13254 ECB             :         ;
   13255                 : 
   13256                 : 
   13257                 : /*****************************************************************************
   13258                 :  *
   13259                 :  *  clauses common to all Optimizable Stmts:
   13260                 :  *      from_clause     - allow list of both JOIN expressions and table names
   13261                 :  *      where_clause    - qualifications for joins or restrictions
   13262                 :  *
   13263                 :  *****************************************************************************/
   13264                 : 
   13265                 : from_clause:
   13266 GIC      189198 :             FROM from_list                          { $$ = $2; }
   13267 CBC       86897 :             | /*EMPTY*/                             { $$ = NIL; }
   13268                 :         ;
   13269                 : 
   13270                 : from_list:
   13271 GIC      189532 :             table_ref                               { $$ = list_make1($1); }
   13272           61351 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13273                 :         ;
   13274 ECB             : 
   13275                 : /*
   13276                 :  * table_ref is where an alias clause can be attached.
   13277                 :  */
   13278                 : table_ref:  relation_expr opt_alias_clause
   13279                 :                 {
   13280 GIC      275848 :                     $1->alias = $2;
   13281 CBC      275848 :                     $$ = (Node *) $1;
   13282                 :                 }
   13283                 :             | relation_expr opt_alias_clause tablesample_clause
   13284                 :                 {
   13285 GIC         121 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13286 ECB             : 
   13287 CBC         121 :                     $1->alias = $2;
   13288                 :                     /* relation_expr goes inside the RangeTableSample node */
   13289 GIC         121 :                     n->relation = (Node *) $1;
   13290             121 :                     $$ = (Node *) n;
   13291 ECB             :                 }
   13292 EUB             :             | func_table func_alias_clause
   13293                 :                 {
   13294 GIC       28973 :                     RangeFunction *n = (RangeFunction *) $1;
   13295                 : 
   13296 CBC       28973 :                     n->alias = linitial($2);
   13297           28973 :                     n->coldeflist = lsecond($2);
   13298 GIC       28973 :                     $$ = (Node *) n;
   13299                 :                 }
   13300                 :             | LATERAL_P func_table func_alias_clause
   13301 ECB             :                 {
   13302 CBC         996 :                     RangeFunction *n = (RangeFunction *) $2;
   13303                 : 
   13304 GIC         996 :                     n->lateral = true;
   13305             996 :                     n->alias = linitial($3);
   13306             996 :                     n->coldeflist = lsecond($3);
   13307             996 :                     $$ = (Node *) n;
   13308 ECB             :                 }
   13309                 :             | xmltable opt_alias_clause
   13310                 :                 {
   13311 CBC          40 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13312 ECB             : 
   13313 CBC          40 :                     n->alias = $2;
   13314 GIC          40 :                     $$ = (Node *) n;
   13315                 :                 }
   13316                 :             | LATERAL_P xmltable opt_alias_clause
   13317                 :                 {
   13318 CBC          67 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13319 ECB             : 
   13320 CBC          67 :                     n->lateral = true;
   13321              67 :                     n->alias = $3;
   13322 GIC          67 :                     $$ = (Node *) n;
   13323                 :                 }
   13324                 :             | select_with_parens opt_alias_clause
   13325 ECB             :                 {
   13326 CBC       13646 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13327                 : 
   13328 GIC       13646 :                     n->lateral = false;
   13329           13646 :                     n->subquery = $1;
   13330           13646 :                     n->alias = $2;
   13331           13646 :                     $$ = (Node *) n;
   13332                 :                 }
   13333                 :             | LATERAL_P select_with_parens opt_alias_clause
   13334                 :                 {
   13335 CBC        1673 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13336 ECB             : 
   13337 GIC        1673 :                     n->lateral = true;
   13338            1673 :                     n->subquery = $2;
   13339            1673 :                     n->alias = $3;
   13340            1673 :                     $$ = (Node *) n;
   13341 ECB             :                 }
   13342                 :             | joined_table
   13343                 :                 {
   13344 GIC       69851 :                     $$ = (Node *) $1;
   13345                 :                 }
   13346 ECB             :             | '(' joined_table ')' alias_clause
   13347                 :                 {
   13348 CBC          87 :                     $2->alias = $4;
   13349              87 :                     $$ = (Node *) $2;
   13350 ECB             :                 }
   13351                 :         ;
   13352                 : 
   13353                 : 
   13354                 : /*
   13355                 :  * It may seem silly to separate joined_table from table_ref, but there is
   13356                 :  * method in SQL's madness: if you don't do it this way you get reduce-
   13357                 :  * reduce conflicts, because it's not clear to the parser generator whether
   13358                 :  * to expect alias_clause after ')' or not.  For the same reason we must
   13359                 :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13360                 :  * join_type to expand to empty; if we try it, the parser generator can't
   13361                 :  * figure out when to reduce an empty join_type right after table_ref.
   13362                 :  *
   13363                 :  * Note that a CROSS JOIN is the same as an unqualified
   13364                 :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13365                 :  * but a qualification expression to limit membership.
   13366                 :  * A NATURAL JOIN implicitly matches column names between
   13367                 :  * tables and the shape is determined by which columns are
   13368                 :  * in common. We'll collect columns during the later transformations.
   13369                 :  */
   13370                 : 
   13371                 : joined_table:
   13372                 :             '(' joined_table ')'
   13373                 :                 {
   13374 CBC        7279 :                     $$ = $2;
   13375                 :                 }
   13376                 :             | table_ref CROSS JOIN table_ref
   13377                 :                 {
   13378 ECB             :                     /* CROSS JOIN is same as unqualified inner join */
   13379 GIC         140 :                     JoinExpr   *n = makeNode(JoinExpr);
   13380 ECB             : 
   13381 CBC         140 :                     n->jointype = JOIN_INNER;
   13382             140 :                     n->isNatural = false;
   13383             140 :                     n->larg = $1;
   13384 GIC         140 :                     n->rarg = $4;
   13385             140 :                     n->usingClause = NIL;
   13386             140 :                     n->join_using_alias = NULL;
   13387 CBC         140 :                     n->quals = NULL;
   13388 GIC         140 :                     $$ = n;
   13389 ECB             :                 }
   13390                 :             | table_ref join_type JOIN table_ref join_qual
   13391                 :                 {
   13392 CBC       36840 :                     JoinExpr   *n = makeNode(JoinExpr);
   13393                 : 
   13394 GIC       36840 :                     n->jointype = $2;
   13395           36840 :                     n->isNatural = false;
   13396 CBC       36840 :                     n->larg = $1;
   13397 GIC       36840 :                     n->rarg = $4;
   13398           36840 :                     if ($5 != NULL && IsA($5, List))
   13399                 :                     {
   13400 ECB             :                          /* USING clause */
   13401 CBC         243 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   13402 GIC         243 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   13403                 :                     }
   13404                 :                     else
   13405                 :                     {
   13406                 :                         /* ON clause */
   13407           36597 :                         n->quals = $5;
   13408                 :                     }
   13409           36840 :                     $$ = n;
   13410                 :                 }
   13411                 :             | table_ref JOIN table_ref join_qual
   13412                 :                 {
   13413                 :                     /* letting join_type reduce to empty doesn't work */
   13414           32829 :                     JoinExpr   *n = makeNode(JoinExpr);
   13415                 : 
   13416           32829 :                     n->jointype = JOIN_INNER;
   13417           32829 :                     n->isNatural = false;
   13418           32829 :                     n->larg = $1;
   13419           32829 :                     n->rarg = $3;
   13420           32829 :                     if ($4 != NULL && IsA($4, List))
   13421                 :                     {
   13422                 :                         /* USING clause */
   13423             354 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   13424             354 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   13425                 :                     }
   13426 ECB             :                     else
   13427                 :                     {
   13428                 :                         /* ON clause */
   13429 GIC       32475 :                         n->quals = $4;
   13430                 :                     }
   13431 CBC       32829 :                     $$ = n;
   13432                 :                 }
   13433 ECB             :             | table_ref NATURAL join_type JOIN table_ref
   13434                 :                 {
   13435 CBC          39 :                     JoinExpr   *n = makeNode(JoinExpr);
   13436 ECB             : 
   13437 CBC          39 :                     n->jointype = $3;
   13438              39 :                     n->isNatural = true;
   13439              39 :                     n->larg = $1;
   13440              39 :                     n->rarg = $5;
   13441 GIC          39 :                     n->usingClause = NIL; /* figure out which columns later... */
   13442              39 :                     n->join_using_alias = NULL;
   13443              39 :                     n->quals = NULL; /* fill later */
   13444 CBC          39 :                     $$ = n;
   13445                 :                 }
   13446 ECB             :             | table_ref NATURAL JOIN table_ref
   13447                 :                 {
   13448                 :                     /* letting join_type reduce to empty doesn't work */
   13449 CBC          90 :                     JoinExpr   *n = makeNode(JoinExpr);
   13450 ECB             : 
   13451 GIC          90 :                     n->jointype = JOIN_INNER;
   13452              90 :                     n->isNatural = true;
   13453 CBC          90 :                     n->larg = $1;
   13454              90 :                     n->rarg = $4;
   13455 GIC          90 :                     n->usingClause = NIL; /* figure out which columns later... */
   13456              90 :                     n->join_using_alias = NULL;
   13457              90 :                     n->quals = NULL; /* fill later */
   13458              90 :                     $$ = n;
   13459 ECB             :                 }
   13460                 :         ;
   13461                 : 
   13462                 : alias_clause:
   13463                 :             AS ColId '(' name_list ')'
   13464                 :                 {
   13465 GIC        7308 :                     $$ = makeNode(Alias);
   13466 CBC        7308 :                     $$->aliasname = $2;
   13467 GIC        7308 :                     $$->colnames = $4;
   13468 ECB             :                 }
   13469                 :             | AS ColId
   13470                 :                 {
   13471 CBC       16630 :                     $$ = makeNode(Alias);
   13472           16630 :                     $$->aliasname = $2;
   13473                 :                 }
   13474                 :             | ColId '(' name_list ')'
   13475 ECB             :                 {
   13476 CBC        3340 :                     $$ = makeNode(Alias);
   13477 GIC        3340 :                     $$->aliasname = $1;
   13478            3340 :                     $$->colnames = $3;
   13479                 :                 }
   13480                 :             | ColId
   13481 ECB             :                 {
   13482 GIC      194377 :                     $$ = makeNode(Alias);
   13483 CBC      194377 :                     $$->aliasname = $1;
   13484                 :                 }
   13485                 :         ;
   13486                 : 
   13487          200152 : opt_alias_clause: alias_clause                      { $$ = $1; }
   13488 GIC       91243 :             | /*EMPTY*/                             { $$ = NULL; }
   13489 ECB             :         ;
   13490                 : 
   13491                 : /*
   13492                 :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   13493                 :  * per SQL standard.  (The grammar could parse the other variants, but they
   13494                 :  * don't seem to be useful, and it might lead to parser problems in the
   13495                 :  * future.)
   13496                 :  */
   13497                 : opt_alias_clause_for_join_using:
   13498                 :             AS ColId
   13499                 :                 {
   13500 GIC          42 :                     $$ = makeNode(Alias);
   13501 CBC          42 :                     $$->aliasname = $2;
   13502                 :                     /* the column name list will be inserted later */
   13503 ECB             :                 }
   13504 CBC         555 :             | /*EMPTY*/                             { $$ = NULL; }
   13505 ECB             :         ;
   13506                 : 
   13507                 : /*
   13508                 :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   13509                 :  * return a 2-element list that gets disassembled by calling production.
   13510                 :  */
   13511                 : func_alias_clause:
   13512                 :             alias_clause
   13513                 :                 {
   13514 GIC       21416 :                     $$ = list_make2($1, NIL);
   13515                 :                 }
   13516                 :             | AS '(' TableFuncElementList ')'
   13517 ECB             :                 {
   13518 CBC          52 :                     $$ = list_make2(NULL, $3);
   13519 ECB             :                 }
   13520                 :             | AS ColId '(' TableFuncElementList ')'
   13521                 :                 {
   13522 GIC         268 :                     Alias      *a = makeNode(Alias);
   13523 ECB             : 
   13524 CBC         268 :                     a->aliasname = $2;
   13525 GIC         268 :                     $$ = list_make2(a, $4);
   13526                 :                 }
   13527                 :             | ColId '(' TableFuncElementList ')'
   13528 ECB             :                 {
   13529 CBC          25 :                     Alias      *a = makeNode(Alias);
   13530 ECB             : 
   13531 GIC          25 :                     a->aliasname = $1;
   13532              25 :                     $$ = list_make2(a, $3);
   13533                 :                 }
   13534 ECB             :             | /*EMPTY*/
   13535                 :                 {
   13536 GIC        8208 :                     $$ = list_make2(NULL, NIL);
   13537                 :                 }
   13538                 :         ;
   13539 ECB             : 
   13540 CBC         494 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   13541 GIC       34207 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   13542             169 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   13543            2009 :             | INNER_P                               { $$ = JOIN_INNER; }
   13544                 :         ;
   13545                 : 
   13546                 : /* OUTER is just noise... */
   13547                 : opt_outer: OUTER_P
   13548                 :             | /*EMPTY*/
   13549                 :         ;
   13550                 : 
   13551                 : /* JOIN qualification clauses
   13552 ECB             :  * Possibilities are:
   13553                 :  *  USING ( column list ) [ AS alias ]
   13554                 :  *                        allows only unqualified column names,
   13555                 :  *                        which must match between tables.
   13556                 :  *  ON expr allows more general qualifications.
   13557                 :  *
   13558                 :  * We return USING as a two-element List (the first item being a sub-List
   13559                 :  * of the common column names, and the second either an Alias item or NULL).
   13560                 :  * An ON-expr will not be a List, so it can be told apart that way.
   13561                 :  */
   13562                 : 
   13563                 : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   13564                 :                 {
   13565 GIC         597 :                     $$ = (Node *) list_make2($3, $5);
   13566 ECB             :                 }
   13567                 :             | ON a_expr
   13568                 :                 {
   13569 GIC       69072 :                     $$ = $2;
   13570 ECB             :                 }
   13571                 :         ;
   13572                 : 
   13573                 : 
   13574                 : relation_expr:
   13575                 :             qualified_name
   13576                 :                 {
   13577                 :                     /* inheritance query, implicitly */
   13578 GIC      333464 :                     $$ = $1;
   13579          333464 :                     $$->inh = true;
   13580          333464 :                     $$->alias = NULL;
   13581 ECB             :                 }
   13582                 :             | extended_relation_expr
   13583                 :                 {
   13584 CBC        3109 :                     $$ = $1;
   13585                 :                 }
   13586                 :         ;
   13587                 : 
   13588 ECB             : extended_relation_expr:
   13589                 :             qualified_name '*'
   13590                 :                 {
   13591                 :                     /* inheritance query, explicitly */
   13592 CBC         102 :                     $$ = $1;
   13593             102 :                     $$->inh = true;
   13594             102 :                     $$->alias = NULL;
   13595 ECB             :                 }
   13596                 :             | ONLY qualified_name
   13597                 :                 {
   13598                 :                     /* no inheritance */
   13599 GIC        3010 :                     $$ = $2;
   13600            3010 :                     $$->inh = false;
   13601            3010 :                     $$->alias = NULL;
   13602                 :                 }
   13603                 :             | ONLY '(' qualified_name ')'
   13604                 :                 {
   13605                 :                     /* no inheritance, SQL99-style syntax */
   13606 UIC           0 :                     $$ = $3;
   13607               0 :                     $$->inh = false;
   13608               0 :                     $$->alias = NULL;
   13609                 :                 }
   13610                 :         ;
   13611                 : 
   13612                 : 
   13613                 : relation_expr_list:
   13614 GIC        1178 :             relation_expr                           { $$ = list_make1($1); }
   13615            4272 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   13616                 :         ;
   13617 ECB             : 
   13618                 : 
   13619                 : /*
   13620                 :  * Given "UPDATE foo set set ...", we have to decide without looking any
   13621                 :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   13622                 :  * keyword.  Since "set" is allowed as a column name both interpretations
   13623                 :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   13624                 :  * relation_expr_opt_alias production a higher precedence than the SET token
   13625                 :  * has, causing the parser to prefer to reduce, in effect assuming that the
   13626                 :  * SET is not an alias.
   13627                 :  */
   13628                 : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   13629                 :                 {
   13630 CBC        9625 :                     $$ = $1;
   13631 ECB             :                 }
   13632                 :             | relation_expr ColId
   13633                 :                 {
   13634 GIC         644 :                     Alias      *alias = makeNode(Alias);
   13635                 : 
   13636 CBC         644 :                     alias->aliasname = $2;
   13637 GIC         644 :                     $1->alias = alias;
   13638             644 :                     $$ = $1;
   13639                 :                 }
   13640                 :             | relation_expr AS ColId
   13641                 :                 {
   13642              15 :                     Alias      *alias = makeNode(Alias);
   13643                 : 
   13644 CBC          15 :                     alias->aliasname = $3;
   13645              15 :                     $1->alias = alias;
   13646              15 :                     $$ = $1;
   13647                 :                 }
   13648                 :         ;
   13649                 : 
   13650                 : /*
   13651 ECB             :  * TABLESAMPLE decoration in a FROM item
   13652                 :  */
   13653                 : tablesample_clause:
   13654                 :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   13655                 :                 {
   13656 GIC         121 :                     RangeTableSample *n = makeNode(RangeTableSample);
   13657                 : 
   13658 EUB             :                     /* n->relation will be filled in later */
   13659 GBC         121 :                     n->method = $2;
   13660             121 :                     n->args = $4;
   13661 GIC         121 :                     n->repeatable = $6;
   13662             121 :                     n->location = @2;
   13663             121 :                     $$ = (Node *) n;
   13664                 :                 }
   13665                 :         ;
   13666 ECB             : 
   13667                 : opt_repeatable_clause:
   13668 GIC          48 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   13669              73 :             | /*EMPTY*/                 { $$ = NULL; }
   13670                 :         ;
   13671                 : 
   13672                 : /*
   13673                 :  * func_table represents a function invocation in a FROM list. It can be
   13674                 :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   13675                 :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   13676                 :  * optionally with WITH ORDINALITY attached.
   13677                 :  * In the ROWS FROM syntax, a column definition list can be given for each
   13678                 :  * function, for example:
   13679                 :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   13680                 :  *                bar() AS (bar_res_a text, bar_res_b text))
   13681                 :  * It's also possible to attach a column definition list to the RangeFunction
   13682 ECB             :  * as a whole, but that's handled by the table_ref production.
   13683                 :  */
   13684                 : func_table: func_expr_windowless opt_ordinality
   13685                 :                 {
   13686 CBC       29906 :                     RangeFunction *n = makeNode(RangeFunction);
   13687                 : 
   13688           29906 :                     n->lateral = false;
   13689           29906 :                     n->ordinality = $2;
   13690           29906 :                     n->is_rowsfrom = false;
   13691 GIC       29906 :                     n->functions = list_make1(list_make2($1, NIL));
   13692                 :                     /* alias and coldeflist are set by table_ref production */
   13693           29906 :                     $$ = (Node *) n;
   13694 ECB             :                 }
   13695                 :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   13696                 :                 {
   13697 CBC          66 :                     RangeFunction *n = makeNode(RangeFunction);
   13698 ECB             : 
   13699 GIC          66 :                     n->lateral = false;
   13700              66 :                     n->ordinality = $6;
   13701              66 :                     n->is_rowsfrom = true;
   13702              66 :                     n->functions = $4;
   13703                 :                     /* alias and coldeflist are set by table_ref production */
   13704              66 :                     $$ = (Node *) n;
   13705                 :                 }
   13706                 :         ;
   13707                 : 
   13708 ECB             : rowsfrom_item: func_expr_windowless opt_col_def_list
   13709 GIC         159 :                 { $$ = list_make2($1, $2); }
   13710                 :         ;
   13711 ECB             : 
   13712                 : rowsfrom_list:
   13713 CBC          66 :             rowsfrom_item                       { $$ = list_make1($1); }
   13714              93 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   13715 ECB             :         ;
   13716                 : 
   13717 GIC          27 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   13718             132 :             | /*EMPTY*/                             { $$ = NIL; }
   13719                 :         ;
   13720 ECB             : 
   13721 CBC         308 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   13722 GIC       29664 :             | /*EMPTY*/                             { $$ = false; }
   13723                 :         ;
   13724                 : 
   13725                 : 
   13726                 : where_clause:
   13727          121785 :             WHERE a_expr                            { $$ = $2; }
   13728          156058 :             | /*EMPTY*/                             { $$ = NULL; }
   13729                 :         ;
   13730                 : 
   13731                 : /* variant for UPDATE and DELETE */
   13732                 : where_or_current_clause:
   13733            7298 :             WHERE a_expr                            { $$ = $2; }
   13734                 :             | WHERE CURRENT_P OF cursor_name
   13735                 :                 {
   13736             127 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   13737                 : 
   13738 ECB             :                     /* cvarno is filled in by parse analysis */
   13739 GIC         127 :                     n->cursor_name = $4;
   13740 CBC         127 :                     n->cursor_param = 0;
   13741             127 :                     $$ = (Node *) n;
   13742 ECB             :                 }
   13743 CBC        2310 :             | /*EMPTY*/                             { $$ = NULL; }
   13744                 :         ;
   13745 ECB             : 
   13746                 : 
   13747                 : OptTableFuncElementList:
   13748 GIC         312 :             TableFuncElementList                { $$ = $1; }
   13749 CBC           3 :             | /*EMPTY*/                         { $$ = NIL; }
   13750                 :         ;
   13751 ECB             : 
   13752                 : TableFuncElementList:
   13753                 :             TableFuncElement
   13754                 :                 {
   13755 GIC         684 :                     $$ = list_make1($1);
   13756 ECB             :                 }
   13757                 :             | TableFuncElementList ',' TableFuncElement
   13758                 :                 {
   13759 GIC         902 :                     $$ = lappend($1, $3);
   13760                 :                 }
   13761 ECB             :         ;
   13762                 : 
   13763                 : TableFuncElement:   ColId Typename opt_collate_clause
   13764                 :                 {
   13765 CBC        1618 :                     ColumnDef *n = makeNode(ColumnDef);
   13766 ECB             : 
   13767 GIC        1618 :                     n->colname = $1;
   13768            1618 :                     n->typeName = $2;
   13769 CBC        1618 :                     n->inhcount = 0;
   13770            1618 :                     n->is_local = true;
   13771 GIC        1618 :                     n->is_not_null = false;
   13772            1618 :                     n->is_from_type = false;
   13773 CBC        1618 :                     n->storage = 0;
   13774            1618 :                     n->raw_default = NULL;
   13775 GIC        1618 :                     n->cooked_default = NULL;
   13776            1618 :                     n->collClause = (CollateClause *) $3;
   13777            1618 :                     n->collOid = InvalidOid;
   13778            1618 :                     n->constraints = NIL;
   13779 CBC        1618 :                     n->location = @1;
   13780            1618 :                     $$ = (Node *) n;
   13781                 :                 }
   13782                 :         ;
   13783                 : 
   13784                 : /*
   13785 ECB             :  * XMLTABLE
   13786                 :  */
   13787                 : xmltable:
   13788                 :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   13789                 :                 {
   13790 GIC          97 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   13791 ECB             : 
   13792 CBC          97 :                     n->rowexpr = $3;
   13793              97 :                     n->docexpr = $4;
   13794 GIC          97 :                     n->columns = $6;
   13795 CBC          97 :                     n->namespaces = NIL;
   13796 GIC          97 :                     n->location = @1;
   13797              97 :                     $$ = (Node *) n;
   13798                 :                 }
   13799                 :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   13800 ECB             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   13801                 :                 {
   13802 GIC          10 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   13803                 : 
   13804              10 :                     n->rowexpr = $8;
   13805              10 :                     n->docexpr = $9;
   13806              10 :                     n->columns = $11;
   13807 CBC          10 :                     n->namespaces = $5;
   13808 GIC          10 :                     n->location = @1;
   13809              10 :                     $$ = (Node *) n;
   13810                 :                 }
   13811 ECB             :         ;
   13812                 : 
   13813 GIC         107 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   13814             262 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   13815                 :         ;
   13816                 : 
   13817 ECB             : xmltable_column_el:
   13818                 :             ColId Typename
   13819                 :                 {
   13820 CBC          93 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   13821 ECB             : 
   13822 CBC          93 :                     fc->colname = $1;
   13823              93 :                     fc->for_ordinality = false;
   13824              93 :                     fc->typeName = $2;
   13825              93 :                     fc->is_not_null = false;
   13826              93 :                     fc->colexpr = NULL;
   13827              93 :                     fc->coldefexpr = NULL;
   13828              93 :                     fc->location = @1;
   13829 ECB             : 
   13830 CBC          93 :                     $$ = (Node *) fc;
   13831 ECB             :                 }
   13832                 :             | ColId Typename xmltable_column_option_list
   13833                 :                 {
   13834 GIC         245 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   13835                 :                     ListCell   *option;
   13836             245 :                     bool        nullability_seen = false;
   13837                 : 
   13838             245 :                     fc->colname = $1;
   13839             245 :                     fc->typeName = $2;
   13840             245 :                     fc->for_ordinality = false;
   13841             245 :                     fc->is_not_null = false;
   13842 CBC         245 :                     fc->colexpr = NULL;
   13843 GIC         245 :                     fc->coldefexpr = NULL;
   13844 CBC         245 :                     fc->location = @1;
   13845 ECB             : 
   13846 CBC         546 :                     foreach(option, $3)
   13847 ECB             :                     {
   13848 CBC         301 :                         DefElem   *defel = (DefElem *) lfirst(option);
   13849 ECB             : 
   13850 GIC         301 :                         if (strcmp(defel->defname, "default") == 0)
   13851                 :                         {
   13852              28 :                             if (fc->coldefexpr != NULL)
   13853 UIC           0 :                                 ereport(ERROR,
   13854 ECB             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   13855                 :                                          errmsg("only one DEFAULT value is allowed"),
   13856                 :                                          parser_errposition(defel->location)));
   13857 CBC          28 :                             fc->coldefexpr = defel->arg;
   13858 ECB             :                         }
   13859 CBC         273 :                         else if (strcmp(defel->defname, "path") == 0)
   13860 ECB             :                         {
   13861 CBC         245 :                             if (fc->colexpr != NULL)
   13862 UIC           0 :                                 ereport(ERROR,
   13863                 :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   13864                 :                                          errmsg("only one PATH value per column is allowed"),
   13865 ECB             :                                          parser_errposition(defel->location)));
   13866 CBC         245 :                             fc->colexpr = defel->arg;
   13867                 :                         }
   13868 GIC          28 :                         else if (strcmp(defel->defname, "is_not_null") == 0)
   13869                 :                         {
   13870              28 :                             if (nullability_seen)
   13871 UIC           0 :                                 ereport(ERROR,
   13872 ECB             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   13873                 :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   13874                 :                                          parser_errposition(defel->location)));
   13875 CBC          28 :                             fc->is_not_null = boolVal(defel->arg);
   13876              28 :                             nullability_seen = true;
   13877 ECB             :                         }
   13878                 :                         else
   13879                 :                         {
   13880 LBC           0 :                             ereport(ERROR,
   13881                 :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   13882 ECB             :                                      errmsg("unrecognized column option \"%s\"",
   13883                 :                                             defel->defname),
   13884                 :                                      parser_errposition(defel->location)));
   13885                 :                         }
   13886                 :                     }
   13887 GIC         245 :                     $$ = (Node *) fc;
   13888 ECB             :                 }
   13889                 :             | ColId FOR ORDINALITY
   13890                 :                 {
   13891 CBC          31 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   13892 ECB             : 
   13893 CBC          31 :                     fc->colname = $1;
   13894              31 :                     fc->for_ordinality = true;
   13895 ECB             :                     /* other fields are ignored, initialized by makeNode */
   13896 CBC          31 :                     fc->location = @1;
   13897                 : 
   13898              31 :                     $$ = (Node *) fc;
   13899                 :                 }
   13900 ECB             :         ;
   13901                 : 
   13902                 : xmltable_column_option_list:
   13903                 :             xmltable_column_option_el
   13904 CBC         245 :                 { $$ = list_make1($1); }
   13905 EUB             :             | xmltable_column_option_list xmltable_column_option_el
   13906 GIC          56 :                 { $$ = lappend($1, $2); }
   13907                 :         ;
   13908                 : 
   13909 ECB             : xmltable_column_option_el:
   13910                 :             IDENT b_expr
   13911 CBC         245 :                 { $$ = makeDefElem($1, $2, @1); }
   13912                 :             | DEFAULT b_expr
   13913              28 :                 { $$ = makeDefElem("default", $2, @1); }
   13914 EUB             :             | NOT NULL_P
   13915 GIC          28 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(true), @1); }
   13916                 :             | NULL_P
   13917 UIC           0 :                 { $$ = makeDefElem("is_not_null", (Node *) makeBoolean(false), @1); }
   13918 ECB             :         ;
   13919                 : 
   13920                 : xml_namespace_list:
   13921                 :             xml_namespace_el
   13922 CBC          10 :                 { $$ = list_make1($1); }
   13923 EUB             :             | xml_namespace_list ',' xml_namespace_el
   13924 UIC           0 :                 { $$ = lappend($1, $3); }
   13925                 :         ;
   13926                 : 
   13927 ECB             : xml_namespace_el:
   13928                 :             b_expr AS ColLabel
   13929                 :                 {
   13930 GIC           7 :                     $$ = makeNode(ResTarget);
   13931               7 :                     $$->name = $3;
   13932 GBC           7 :                     $$->indirection = NIL;
   13933 GIC           7 :                     $$->val = $1;
   13934               7 :                     $$->location = @1;
   13935                 :                 }
   13936                 :             | DEFAULT b_expr
   13937                 :                 {
   13938               3 :                     $$ = makeNode(ResTarget);
   13939 CBC           3 :                     $$->name = NULL;
   13940 GIC           3 :                     $$->indirection = NIL;
   13941               3 :                     $$->val = $2;
   13942               3 :                     $$->location = @1;
   13943 ECB             :                 }
   13944                 :         ;
   13945                 : 
   13946                 : /*****************************************************************************
   13947                 :  *
   13948                 :  *  Type syntax
   13949                 :  *      SQL introduces a large amount of type-specific syntax.
   13950                 :  *      Define individual clauses to handle these cases, and use
   13951                 :  *       the generic case to handle regular type-extensible Postgres syntax.
   13952                 :  *      - thomas 1997-10-10
   13953                 :  *
   13954                 :  *****************************************************************************/
   13955                 : 
   13956                 : Typename:   SimpleTypename opt_array_bounds
   13957                 :                 {
   13958 CBC      529583 :                     $$ = $1;
   13959 GIC      529583 :                     $$->arrayBounds = $2;
   13960                 :                 }
   13961                 :             | SETOF SimpleTypename opt_array_bounds
   13962                 :                 {
   13963 CBC        3563 :                     $$ = $2;
   13964 GIC        3563 :                     $$->arrayBounds = $3;
   13965 CBC        3563 :                     $$->setof = true;
   13966                 :                 }
   13967 ECB             :             /* SQL standard syntax, currently only one-dimensional */
   13968                 :             | SimpleTypename ARRAY '[' Iconst ']'
   13969 EUB             :                 {
   13970 GIC           3 :                     $$ = $1;
   13971               3 :                     $$->arrayBounds = list_make1(makeInteger($4));
   13972                 :                 }
   13973                 :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   13974 ECB             :                 {
   13975 UIC           0 :                     $$ = $2;
   13976 UBC           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   13977 UIC           0 :                     $$->setof = true;
   13978                 :                 }
   13979                 :             | SimpleTypename ARRAY
   13980                 :                 {
   13981               0 :                     $$ = $1;
   13982 LBC           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   13983 ECB             :                 }
   13984                 :             | SETOF SimpleTypename ARRAY
   13985                 :                 {
   13986 LBC           0 :                     $$ = $2;
   13987 UIC           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   13988               0 :                     $$->setof = true;
   13989                 :                 }
   13990 ECB             :         ;
   13991                 : 
   13992                 : opt_array_bounds:
   13993                 :             opt_array_bounds '[' ']'
   13994 CBC        9712 :                     {  $$ = lappend($1, makeInteger(-1)); }
   13995                 :             | opt_array_bounds '[' Iconst ']'
   13996 GIC          26 :                     {  $$ = lappend($1, makeInteger($3)); }
   13997                 :             | /*EMPTY*/
   13998          533146 :                     {  $$ = NIL; }
   13999                 :         ;
   14000                 : 
   14001                 : SimpleTypename:
   14002          452361 :             GenericType                             { $$ = $1; }
   14003           60745 :             | Numeric                               { $$ = $1; }
   14004            1187 :             | Bit                                   { $$ = $1; }
   14005            1826 :             | Character                             { $$ = $1; }
   14006           10306 :             | ConstDatetime                         { $$ = $1; }
   14007                 :             | ConstInterval opt_interval
   14008                 :                 {
   14009            6909 :                     $$ = $1;
   14010 CBC        6909 :                     $$->typmods = $2;
   14011 ECB             :                 }
   14012                 :             | ConstInterval '(' Iconst ')'
   14013                 :                 {
   14014 UIC           0 :                     $$ = $1;
   14015 LBC           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14016 ECB             :                                              makeIntConst($3, @3));
   14017                 :                 }
   14018                 :         ;
   14019                 : 
   14020                 : /* We have a separate ConstTypename to allow defaulting fixed-length
   14021                 :  * types such as CHAR() and BIT() to an unspecified length.
   14022                 :  * SQL9x requires that these default to a length of one, but this
   14023                 :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14024                 :  * where there is an obvious better choice to make.
   14025                 :  * Note that ConstInterval is not included here since it must
   14026                 :  * be pushed up higher in the rules to accommodate the postfix
   14027 EUB             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14028                 :  * the generic-type-name case in AexprConst to avoid premature
   14029                 :  * reduce/reduce conflicts against function names.
   14030                 :  */
   14031                 : ConstTypename:
   14032 GIC          39 :             Numeric                                 { $$ = $1; }
   14033 UBC           0 :             | ConstBit                              { $$ = $1; }
   14034 GBC          16 :             | ConstCharacter                        { $$ = $1; }
   14035 GIC        1084 :             | ConstDatetime                         { $$ = $1; }
   14036                 :         ;
   14037                 : 
   14038 EUB             : /*
   14039                 :  * GenericType covers all type names that don't have special syntax mandated
   14040                 :  * by the standard, including qualified names.  We also allow type modifiers.
   14041                 :  * To avoid parsing conflicts against function invocations, the modifiers
   14042                 :  * have to be shown as expr_list here, but parse analysis will only accept
   14043                 :  * constants for them.
   14044                 :  */
   14045                 : GenericType:
   14046 ECB             :             type_function_name opt_type_modifiers
   14047                 :                 {
   14048 CBC      420883 :                     $$ = makeTypeName($1);
   14049 GIC      420883 :                     $$->typmods = $2;
   14050 CBC      420883 :                     $$->location = @1;
   14051                 :                 }
   14052                 :             | type_function_name attrs opt_type_modifiers
   14053                 :                 {
   14054           31478 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14055           31478 :                     $$->typmods = $3;
   14056           31478 :                     $$->location = @1;
   14057 ECB             :                 }
   14058                 :         ;
   14059                 : 
   14060 GIC         661 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14061 CBC      456875 :                     | /* EMPTY */                   { $$ = NIL; }
   14062 ECB             :         ;
   14063                 : 
   14064                 : /*
   14065                 :  * SQL numeric data types
   14066 EUB             :  */
   14067                 : Numeric:    INT_P
   14068                 :                 {
   14069 GIC       17527 :                     $$ = SystemTypeName("int4");
   14070           17527 :                     $$->location = @1;
   14071                 :                 }
   14072                 :             | INTEGER
   14073                 :                 {
   14074           11181 :                     $$ = SystemTypeName("int4");
   14075           11181 :                     $$->location = @1;
   14076                 :                 }
   14077                 :             | SMALLINT
   14078                 :                 {
   14079             812 :                     $$ = SystemTypeName("int2");
   14080             812 :                     $$->location = @1;
   14081                 :                 }
   14082                 :             | BIGINT
   14083                 :                 {
   14084 CBC        6690 :                     $$ = SystemTypeName("int8");
   14085 GBC        6690 :                     $$->location = @1;
   14086 ECB             :                 }
   14087                 :             | REAL
   14088                 :                 {
   14089 GIC          59 :                     $$ = SystemTypeName("float4");
   14090              59 :                     $$->location = @1;
   14091                 :                 }
   14092                 :             | FLOAT_P opt_float
   14093                 :                 {
   14094             221 :                     $$ = $2;
   14095             221 :                     $$->location = @1;
   14096                 :                 }
   14097                 :             | DOUBLE_P PRECISION
   14098                 :                 {
   14099             768 :                     $$ = SystemTypeName("float8");
   14100 CBC         768 :                     $$->location = @1;
   14101 ECB             :                 }
   14102                 :             | DECIMAL_P opt_type_modifiers
   14103                 :                 {
   14104 GIC          16 :                     $$ = SystemTypeName("numeric");
   14105              16 :                     $$->typmods = $2;
   14106 CBC          16 :                     $$->location = @1;
   14107 ECB             :                 }
   14108                 :             | DEC opt_type_modifiers
   14109                 :                 {
   14110 UIC           0 :                     $$ = SystemTypeName("numeric");
   14111               0 :                     $$->typmods = $2;
   14112 LBC           0 :                     $$->location = @1;
   14113 ECB             :                 }
   14114                 :             | NUMERIC opt_type_modifiers
   14115                 :                 {
   14116 GIC        5159 :                     $$ = SystemTypeName("numeric");
   14117            5159 :                     $$->typmods = $2;
   14118            5159 :                     $$->location = @1;
   14119                 :                 }
   14120                 :             | BOOLEAN_P
   14121 ECB             :                 {
   14122 CBC       18351 :                     $$ = SystemTypeName("bool");
   14123 GIC       18351 :                     $$->location = @1;
   14124                 :                 }
   14125                 :         ;
   14126 ECB             : 
   14127                 : opt_float:  '(' Iconst ')'
   14128                 :                 {
   14129                 :                     /*
   14130                 :                      * Check FLOAT() precision limits assuming IEEE floating
   14131                 :                      * types - thomas 1997-09-18
   14132                 :                      */
   14133 GIC           1 :                     if ($2 < 1)
   14134 UIC           0 :                         ereport(ERROR,
   14135                 :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14136 ECB             :                                  errmsg("precision for type float must be at least 1 bit"),
   14137                 :                                  parser_errposition(@2)));
   14138 GIC           1 :                     else if ($2 <= 24)
   14139               1 :                         $$ = SystemTypeName("float4");
   14140 UIC           0 :                     else if ($2 <= 53)
   14141 LBC           0 :                         $$ = SystemTypeName("float8");
   14142 ECB             :                     else
   14143 UIC           0 :                         ereport(ERROR,
   14144                 :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   14145                 :                                  errmsg("precision for type float must be less than 54 bits"),
   14146 ECB             :                                  parser_errposition(@2)));
   14147                 :                 }
   14148                 :             | /*EMPTY*/
   14149                 :                 {
   14150 GIC         220 :                     $$ = SystemTypeName("float8");
   14151 ECB             :                 }
   14152                 :         ;
   14153                 : 
   14154                 : /*
   14155                 :  * SQL bit-field data types
   14156                 :  * The following implements BIT() and BIT VARYING().
   14157                 :  */
   14158                 : Bit:        BitWithLength
   14159                 :                 {
   14160 GIC         837 :                     $$ = $1;
   14161                 :                 }
   14162 EUB             :             | BitWithoutLength
   14163                 :                 {
   14164 GBC         350 :                     $$ = $1;
   14165                 :                 }
   14166                 :         ;
   14167                 : 
   14168 ECB             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   14169                 : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   14170                 : ConstBit:   BitWithLength
   14171                 :                 {
   14172 UIC           0 :                     $$ = $1;
   14173                 :                 }
   14174 ECB             :             | BitWithoutLength
   14175                 :                 {
   14176 UIC           0 :                     $$ = $1;
   14177               0 :                     $$->typmods = NIL;
   14178                 :                 }
   14179                 :         ;
   14180                 : 
   14181                 : BitWithLength:
   14182                 :             BIT opt_varying '(' expr_list ')'
   14183                 :                 {
   14184                 :                     char *typname;
   14185 ECB             : 
   14186 GBC         837 :                     typname = $2 ? "varbit" : "bit";
   14187 GIC         837 :                     $$ = SystemTypeName(typname);
   14188             837 :                     $$->typmods = $4;
   14189             837 :                     $$->location = @1;
   14190 ECB             :                 }
   14191                 :         ;
   14192 EUB             : 
   14193                 : BitWithoutLength:
   14194                 :             BIT opt_varying
   14195                 :                 {
   14196                 :                     /* bit defaults to bit(1), varbit to no limit */
   14197 GIC         350 :                     if ($2)
   14198                 :                     {
   14199               9 :                         $$ = SystemTypeName("varbit");
   14200                 :                     }
   14201                 :                     else
   14202 ECB             :                     {
   14203 GIC         341 :                         $$ = SystemTypeName("bit");
   14204             341 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14205                 :                     }
   14206             350 :                     $$->location = @1;
   14207                 :                 }
   14208                 :         ;
   14209                 : 
   14210                 : 
   14211                 : /*
   14212 ECB             :  * SQL character data types
   14213                 :  * The following implements CHAR() and VARCHAR().
   14214                 :  */
   14215                 : Character:  CharacterWithLength
   14216                 :                 {
   14217 GIC         967 :                     $$ = $1;
   14218                 :                 }
   14219                 :             | CharacterWithoutLength
   14220                 :                 {
   14221             859 :                     $$ = $1;
   14222                 :                 }
   14223                 :         ;
   14224 EUB             : 
   14225                 : ConstCharacter:  CharacterWithLength
   14226                 :                 {
   14227 GIC           6 :                     $$ = $1;
   14228 EUB             :                 }
   14229                 :             | CharacterWithoutLength
   14230                 :                 {
   14231                 :                     /* Length was not specified so allow to be unrestricted.
   14232                 :                      * This handles problems with fixed-length (bpchar) strings
   14233                 :                      * which in column definitions must default to a length
   14234                 :                      * of one, but should not be constrained if the length
   14235                 :                      * was not specified.
   14236                 :                      */
   14237 GIC          10 :                     $$ = $1;
   14238 CBC          10 :                     $$->typmods = NIL;
   14239 ECB             :                 }
   14240                 :         ;
   14241                 : 
   14242                 : CharacterWithLength:  character '(' Iconst ')'
   14243                 :                 {
   14244 GIC         973 :                     $$ = SystemTypeName($1);
   14245             973 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14246             973 :                     $$->location = @1;
   14247                 :                 }
   14248                 :         ;
   14249 ECB             : 
   14250                 : CharacterWithoutLength:  character
   14251                 :                 {
   14252 GIC         869 :                     $$ = SystemTypeName($1);
   14253                 :                     /* char defaults to char(1), varchar to no limit */
   14254             869 :                     if (strcmp($1, "bpchar") == 0)
   14255 CBC         122 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   14256             869 :                     $$->location = @1;
   14257                 :                 }
   14258 ECB             :         ;
   14259                 : 
   14260                 : character:  CHARACTER opt_varying
   14261 GIC         779 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14262                 :             | CHAR_P opt_varying
   14263             486 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14264                 :             | VARCHAR
   14265             576 :                                         { $$ = "varchar"; }
   14266                 :             | NATIONAL CHARACTER opt_varying
   14267 UIC           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14268                 :             | NATIONAL CHAR_P opt_varying
   14269 LBC           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   14270                 :             | NCHAR opt_varying
   14271 GIC           1 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   14272                 :         ;
   14273 ECB             : 
   14274                 : opt_varying:
   14275 GIC         728 :             VARYING                                 { $$ = true; }
   14276            1725 :             | /*EMPTY*/                             { $$ = false; }
   14277                 :         ;
   14278                 : 
   14279 ECB             : /*
   14280                 :  * SQL date/time types
   14281                 :  */
   14282                 : ConstDatetime:
   14283                 :             TIMESTAMP '(' Iconst ')' opt_timezone
   14284                 :                 {
   14285 GIC         319 :                     if ($5)
   14286             310 :                         $$ = SystemTypeName("timestamptz");
   14287                 :                     else
   14288               9 :                         $$ = SystemTypeName("timestamp");
   14289 CBC         319 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14290             319 :                     $$->location = @1;
   14291                 :                 }
   14292                 :             | TIMESTAMP opt_timezone
   14293                 :                 {
   14294 GIC        6589 :                     if ($2)
   14295             886 :                         $$ = SystemTypeName("timestamptz");
   14296 ECB             :                     else
   14297 CBC        5703 :                         $$ = SystemTypeName("timestamp");
   14298            6589 :                     $$->location = @1;
   14299                 :                 }
   14300                 :             | TIME '(' Iconst ')' opt_timezone
   14301                 :                 {
   14302 GIC          11 :                     if ($5)
   14303               4 :                         $$ = SystemTypeName("timetz");
   14304 ECB             :                     else
   14305 GIC           7 :                         $$ = SystemTypeName("time");
   14306 CBC          11 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   14307              11 :                     $$->location = @1;
   14308 ECB             :                 }
   14309                 :             | TIME opt_timezone
   14310                 :                 {
   14311 GIC        4471 :                     if ($2)
   14312             133 :                         $$ = SystemTypeName("timetz");
   14313 ECB             :                     else
   14314 GIC        4338 :                         $$ = SystemTypeName("time");
   14315 CBC        4471 :                     $$->location = @1;
   14316                 :                 }
   14317 ECB             :         ;
   14318                 : 
   14319 EUB             : ConstInterval:
   14320                 :             INTERVAL
   14321                 :                 {
   14322 GIC        8087 :                     $$ = SystemTypeName("interval");
   14323 CBC        8087 :                     $$->location = @1;
   14324                 :                 }
   14325                 :         ;
   14326                 : 
   14327 ECB             : opt_timezone:
   14328 CBC        1333 :             WITH_LA TIME ZONE                       { $$ = true; }
   14329 GNC         250 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   14330 GIC        9807 :             | /*EMPTY*/                             { $$ = false; }
   14331                 :         ;
   14332                 : 
   14333                 : opt_interval:
   14334                 :             YEAR_P
   14335               6 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   14336                 :             | MONTH_P
   14337 CBC           9 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   14338 ECB             :             | DAY_P
   14339 GIC           9 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   14340 ECB             :             | HOUR_P
   14341 CBC           6 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   14342 ECB             :             | MINUTE_P
   14343 GIC           6 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   14344                 :             | interval_second
   14345              12 :                 { $$ = $1; }
   14346 ECB             :             | YEAR_P TO MONTH_P
   14347                 :                 {
   14348 GIC           9 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   14349 ECB             :                                                  INTERVAL_MASK(MONTH), @1));
   14350                 :                 }
   14351                 :             | DAY_P TO HOUR_P
   14352                 :                 {
   14353 GIC          12 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14354 ECB             :                                                  INTERVAL_MASK(HOUR), @1));
   14355                 :                 }
   14356                 :             | DAY_P TO MINUTE_P
   14357                 :                 {
   14358 CBC          12 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   14359 ECB             :                                                  INTERVAL_MASK(HOUR) |
   14360                 :                                                  INTERVAL_MASK(MINUTE), @1));
   14361                 :                 }
   14362                 :             | DAY_P TO interval_second
   14363                 :                 {
   14364 CBC          24 :                     $$ = $3;
   14365 GIC          24 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   14366 ECB             :                                                 INTERVAL_MASK(HOUR) |
   14367                 :                                                 INTERVAL_MASK(MINUTE) |
   14368 GIC          24 :                                                 INTERVAL_MASK(SECOND), @1);
   14369                 :                 }
   14370                 :             | HOUR_P TO MINUTE_P
   14371                 :                 {
   14372               9 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   14373                 :                                                  INTERVAL_MASK(MINUTE), @1));
   14374 ECB             :                 }
   14375                 :             | HOUR_P TO interval_second
   14376                 :                 {
   14377 GIC          18 :                     $$ = $3;
   14378              18 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   14379                 :                                                 INTERVAL_MASK(MINUTE) |
   14380 CBC          18 :                                                 INTERVAL_MASK(SECOND), @1);
   14381 ECB             :                 }
   14382                 :             | MINUTE_P TO interval_second
   14383                 :                 {
   14384 GIC          33 :                     $$ = $3;
   14385              33 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   14386              33 :                                                 INTERVAL_MASK(SECOND), @1);
   14387 ECB             :                 }
   14388                 :             | /*EMPTY*/
   14389 CBC        7916 :                 { $$ = NIL; }
   14390                 :         ;
   14391 ECB             : 
   14392                 : interval_second:
   14393                 :             SECOND_P
   14394                 :                 {
   14395 CBC          51 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   14396                 :                 }
   14397 ECB             :             | SECOND_P '(' Iconst ')'
   14398                 :                 {
   14399 GIC          36 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   14400 ECB             :                                     makeIntConst($3, @3));
   14401                 :                 }
   14402                 :         ;
   14403                 : 
   14404                 : 
   14405                 : /*****************************************************************************
   14406                 :  *
   14407                 :  *  expression grammar
   14408                 :  *
   14409                 :  *****************************************************************************/
   14410                 : 
   14411                 : /*
   14412                 :  * General expressions
   14413                 :  * This is the heart of the expression syntax.
   14414                 :  *
   14415                 :  * We have two expression types: a_expr is the unrestricted kind, and
   14416                 :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   14417                 :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   14418                 :  * because that use of AND conflicts with AND as a boolean operator.  So,
   14419                 :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   14420                 :  *
   14421                 :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   14422                 :  * always be used by surrounding it with parens.
   14423                 :  *
   14424                 :  * c_expr is all the productions that are common to a_expr and b_expr;
   14425                 :  * it's factored out just to eliminate redundant coding.
   14426                 :  *
   14427                 :  * Be careful of productions involving more than one terminal token.
   14428                 :  * By default, bison will assign such productions the precedence of their
   14429                 :  * last terminal, but in nearly all cases you want it to be the precedence
   14430                 :  * of the first terminal instead; otherwise you will not get the behavior
   14431                 :  * you expect!  So we use %prec annotations freely to set precedences.
   14432                 :  */
   14433 GIC     3061214 : a_expr:     c_expr                                  { $$ = $1; }
   14434                 :             | a_expr TYPECAST Typename
   14435          103868 :                     { $$ = makeTypeCast($1, $3, @2); }
   14436 ECB             :             | a_expr COLLATE any_name
   14437                 :                 {
   14438 CBC        3643 :                     CollateClause *n = makeNode(CollateClause);
   14439                 : 
   14440 GIC        3643 :                     n->arg = $1;
   14441 CBC        3643 :                     n->collname = $3;
   14442 GIC        3643 :                     n->location = @2;
   14443            3643 :                     $$ = (Node *) n;
   14444                 :                 }
   14445                 :             | a_expr AT TIME ZONE a_expr            %prec AT
   14446                 :                 {
   14447 CBC         183 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   14448 GIC         183 :                                                list_make2($5, $1),
   14449                 :                                                COERCE_SQL_SYNTAX,
   14450             183 :                                                @2);
   14451 ECB             :                 }
   14452                 :         /*
   14453                 :          * These operators must be called out explicitly in order to make use
   14454                 :          * of bison's automatic operator-precedence handling.  All other
   14455                 :          * operator names are handled by the generic productions using "Op",
   14456                 :          * below; and all those operators will have the same precedence.
   14457                 :          *
   14458                 :          * If you add more explicitly-known operators, be sure to add them
   14459                 :          * also to b_expr and to the MathOp list below.
   14460                 :          */
   14461                 :             | '+' a_expr                    %prec UMINUS
   14462 GIC           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   14463                 :             | '-' a_expr                    %prec UMINUS
   14464            8882 :                 { $$ = doNegate($2, @1); }
   14465                 :             | a_expr '+' a_expr
   14466           12925 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   14467                 :             | a_expr '-' a_expr
   14468            5148 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   14469                 :             | a_expr '*' a_expr
   14470            4841 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   14471                 :             | a_expr '/' a_expr
   14472            1725 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   14473                 :             | a_expr '%' a_expr
   14474            1261 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   14475                 :             | a_expr '^' a_expr
   14476             490 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   14477                 :             | a_expr '<' a_expr
   14478            5289 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   14479                 :             | a_expr '>' a_expr
   14480           10427 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   14481                 :             | a_expr '=' a_expr
   14482          294145 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   14483                 :             | a_expr LESS_EQUALS a_expr
   14484            2217 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   14485 ECB             :             | a_expr GREATER_EQUALS a_expr
   14486 GIC        2511 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   14487 ECB             :             | a_expr NOT_EQUALS a_expr
   14488 GIC       21784 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   14489                 : 
   14490 ECB             :             | a_expr qual_Op a_expr             %prec Op
   14491 GIC       40860 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   14492 ECB             :             | qual_Op a_expr                    %prec Op
   14493 CBC          96 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   14494 ECB             : 
   14495                 :             | a_expr AND a_expr
   14496 GIC      174289 :                 { $$ = makeAndExpr($1, $3, @2); }
   14497                 :             | a_expr OR a_expr
   14498           26248 :                 { $$ = makeOrExpr($1, $3, @2); }
   14499 ECB             :             | NOT a_expr
   14500 CBC       15115 :                 { $$ = makeNotExpr($2, @1); }
   14501                 :             | NOT_LA a_expr                     %prec NOT
   14502 LBC           0 :                 { $$ = makeNotExpr($2, @1); }
   14503                 : 
   14504                 :             | a_expr LIKE a_expr
   14505                 :                 {
   14506 GIC        1144 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   14507            1144 :                                                    $1, $3, @2);
   14508                 :                 }
   14509                 :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   14510                 :                 {
   14511              48 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14512              48 :                                                  list_make2($3, $5),
   14513                 :                                                  COERCE_EXPLICIT_CALL,
   14514 CBC          48 :                                                  @2);
   14515 GIC          48 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   14516 CBC          48 :                                                    $1, (Node *) n, @2);
   14517                 :                 }
   14518 ECB             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   14519                 :                 {
   14520 CBC          96 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   14521 GIC          96 :                                                    $1, $4, @2);
   14522 ECB             :                 }
   14523                 :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   14524                 :                 {
   14525 GIC          48 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14526 CBC          48 :                                                  list_make2($4, $6),
   14527                 :                                                  COERCE_EXPLICIT_CALL,
   14528              48 :                                                  @2);
   14529 GIC          48 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   14530 CBC          48 :                                                    $1, (Node *) n, @2);
   14531                 :                 }
   14532 ECB             :             | a_expr ILIKE a_expr
   14533                 :                 {
   14534 CBC         111 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   14535 GIC         111 :                                                    $1, $3, @2);
   14536 ECB             :                 }
   14537                 :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   14538                 :                 {
   14539 UIC           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14540 LBC           0 :                                                  list_make2($3, $5),
   14541                 :                                                  COERCE_EXPLICIT_CALL,
   14542 UIC           0 :                                                  @2);
   14543 LBC           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   14544 UIC           0 :                                                    $1, (Node *) n, @2);
   14545 ECB             :                 }
   14546                 :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   14547                 :                 {
   14548 CBC          15 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   14549 GIC          15 :                                                    $1, $4, @2);
   14550 ECB             :                 }
   14551                 :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   14552                 :                 {
   14553 UIC           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   14554 UBC           0 :                                                  list_make2($4, $6),
   14555                 :                                                  COERCE_EXPLICIT_CALL,
   14556 UIC           0 :                                                  @2);
   14557               0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   14558 LBC           0 :                                                    $1, (Node *) n, @2);
   14559 ECB             :                 }
   14560                 : 
   14561                 :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   14562                 :                 {
   14563 CBC          20 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   14564              20 :                                                  list_make1($4),
   14565                 :                                                  COERCE_EXPLICIT_CALL,
   14566              20 :                                                  @2);
   14567              20 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   14568              20 :                                                    $1, (Node *) n, @2);
   14569                 :                 }
   14570                 :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   14571                 :                 {
   14572              15 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   14573              15 :                                                  list_make2($4, $6),
   14574                 :                                                  COERCE_EXPLICIT_CALL,
   14575 GIC          15 :                                                  @2);
   14576              15 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   14577 CBC          15 :                                                    $1, (Node *) n, @2);
   14578 ECB             :                 }
   14579                 :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   14580                 :                 {
   14581 LBC           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   14582               0 :                                                  list_make1($5),
   14583                 :                                                  COERCE_EXPLICIT_CALL,
   14584 UIC           0 :                                                  @2);
   14585               0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   14586 LBC           0 :                                                    $1, (Node *) n, @2);
   14587 ECB             :                 }
   14588                 :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   14589                 :                 {
   14590 UIC           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   14591 UBC           0 :                                                  list_make2($5, $7),
   14592 EUB             :                                                  COERCE_EXPLICIT_CALL,
   14593 UIC           0 :                                                  @2);
   14594 UBC           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   14595               0 :                                                    $1, (Node *) n, @2);
   14596 EUB             :                 }
   14597                 : 
   14598                 :             /* NullTest clause
   14599                 :              * Define SQL-style Null test clause.
   14600 ECB             :              * Allow two forms described in the standard:
   14601                 :              *  a IS NULL
   14602                 :              *  a IS NOT NULL
   14603                 :              * Allow two SQL extensions
   14604                 :              *  a ISNULL
   14605 EUB             :              *  a NOTNULL
   14606                 :              */
   14607                 :             | a_expr IS NULL_P                          %prec IS
   14608                 :                 {
   14609 GBC        3386 :                     NullTest   *n = makeNode(NullTest);
   14610 EUB             : 
   14611 GIC        3386 :                     n->arg = (Expr *) $1;
   14612            3386 :                     n->nulltesttype = IS_NULL;
   14613            3386 :                     n->location = @2;
   14614            3386 :                     $$ = (Node *) n;
   14615 ECB             :                 }
   14616                 :             | a_expr ISNULL
   14617                 :                 {
   14618 CBC          48 :                     NullTest   *n = makeNode(NullTest);
   14619 ECB             : 
   14620 CBC          48 :                     n->arg = (Expr *) $1;
   14621 GIC          48 :                     n->nulltesttype = IS_NULL;
   14622              48 :                     n->location = @2;
   14623              48 :                     $$ = (Node *) n;
   14624 ECB             :                 }
   14625                 :             | a_expr IS NOT NULL_P                      %prec IS
   14626                 :                 {
   14627 CBC       11349 :                     NullTest   *n = makeNode(NullTest);
   14628 ECB             : 
   14629 CBC       11349 :                     n->arg = (Expr *) $1;
   14630 GIC       11349 :                     n->nulltesttype = IS_NOT_NULL;
   14631           11349 :                     n->location = @2;
   14632           11349 :                     $$ = (Node *) n;
   14633 EUB             :                 }
   14634                 :             | a_expr NOTNULL
   14635                 :                 {
   14636 GBC           3 :                     NullTest   *n = makeNode(NullTest);
   14637 EUB             : 
   14638 GBC           3 :                     n->arg = (Expr *) $1;
   14639 GIC           3 :                     n->nulltesttype = IS_NOT_NULL;
   14640               3 :                     n->location = @2;
   14641               3 :                     $$ = (Node *) n;
   14642 EUB             :                 }
   14643                 :             | row OVERLAPS row
   14644                 :                 {
   14645 GBC        2778 :                     if (list_length($1) != 2)
   14646 UBC           0 :                         ereport(ERROR,
   14647 EUB             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14648                 :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   14649                 :                                  parser_errposition(@1)));
   14650 GIC        2778 :                     if (list_length($3) != 2)
   14651 UIC           0 :                         ereport(ERROR,
   14652                 :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14653                 :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   14654                 :                                  parser_errposition(@3)));
   14655 GIC        2778 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   14656            2778 :                                                list_concat($1, $3),
   14657                 :                                                COERCE_SQL_SYNTAX,
   14658            2778 :                                                @2);
   14659                 :                 }
   14660                 :             | a_expr IS TRUE_P                          %prec IS
   14661 ECB             :                 {
   14662 GIC         139 :                     BooleanTest *b = makeNode(BooleanTest);
   14663 ECB             : 
   14664 CBC         139 :                     b->arg = (Expr *) $1;
   14665             139 :                     b->booltesttype = IS_TRUE;
   14666             139 :                     b->location = @2;
   14667 GIC         139 :                     $$ = (Node *) b;
   14668                 :                 }
   14669                 :             | a_expr IS NOT TRUE_P                      %prec IS
   14670 ECB             :                 {
   14671 GIC          21 :                     BooleanTest *b = makeNode(BooleanTest);
   14672 ECB             : 
   14673 CBC          21 :                     b->arg = (Expr *) $1;
   14674              21 :                     b->booltesttype = IS_NOT_TRUE;
   14675              21 :                     b->location = @2;
   14676 GIC          21 :                     $$ = (Node *) b;
   14677                 :                 }
   14678                 :             | a_expr IS FALSE_P                         %prec IS
   14679 ECB             :                 {
   14680 GIC          22 :                     BooleanTest *b = makeNode(BooleanTest);
   14681 ECB             : 
   14682 CBC          22 :                     b->arg = (Expr *) $1;
   14683              22 :                     b->booltesttype = IS_FALSE;
   14684              22 :                     b->location = @2;
   14685 GIC          22 :                     $$ = (Node *) b;
   14686                 :                 }
   14687                 :             | a_expr IS NOT FALSE_P                     %prec IS
   14688 ECB             :                 {
   14689 GIC          15 :                     BooleanTest *b = makeNode(BooleanTest);
   14690 ECB             : 
   14691 CBC          15 :                     b->arg = (Expr *) $1;
   14692              15 :                     b->booltesttype = IS_NOT_FALSE;
   14693              15 :                     b->location = @2;
   14694 GIC          15 :                     $$ = (Node *) b;
   14695                 :                 }
   14696                 :             | a_expr IS UNKNOWN                         %prec IS
   14697 ECB             :                 {
   14698 GBC           8 :                     BooleanTest *b = makeNode(BooleanTest);
   14699                 : 
   14700 GIC           8 :                     b->arg = (Expr *) $1;
   14701               8 :                     b->booltesttype = IS_UNKNOWN;
   14702 CBC           8 :                     b->location = @2;
   14703 GBC           8 :                     $$ = (Node *) b;
   14704                 :                 }
   14705                 :             | a_expr IS NOT UNKNOWN                     %prec IS
   14706                 :                 {
   14707 CBC           6 :                     BooleanTest *b = makeNode(BooleanTest);
   14708 ECB             : 
   14709 GIC           6 :                     b->arg = (Expr *) $1;
   14710 CBC           6 :                     b->booltesttype = IS_NOT_UNKNOWN;
   14711 GIC           6 :                     b->location = @2;
   14712               6 :                     $$ = (Node *) b;
   14713                 :                 }
   14714 ECB             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   14715                 :                 {
   14716 CBC         371 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   14717 ECB             :                 }
   14718                 :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   14719                 :                 {
   14720 GIC          31 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   14721                 :                 }
   14722                 :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   14723 ECB             :                 {
   14724 GIC         226 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   14725 ECB             :                                                    "BETWEEN",
   14726 CBC         226 :                                                    $1,
   14727             226 :                                                    (Node *) list_make2($4, $6),
   14728             226 :                                                    @2);
   14729                 :                 }
   14730                 :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   14731                 :                 {
   14732               6 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   14733                 :                                                    "NOT BETWEEN",
   14734               6 :                                                    $1,
   14735               6 :                                                    (Node *) list_make2($5, $7),
   14736               6 :                                                    @2);
   14737 ECB             :                 }
   14738                 :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   14739                 :                 {
   14740 GIC           6 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   14741 ECB             :                                                    "BETWEEN SYMMETRIC",
   14742 GIC           6 :                                                    $1,
   14743 CBC           6 :                                                    (Node *) list_make2($4, $6),
   14744               6 :                                                    @2);
   14745 ECB             :                 }
   14746                 :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   14747                 :                 {
   14748 GIC           6 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   14749                 :                                                    "NOT BETWEEN SYMMETRIC",
   14750 CBC           6 :                                                    $1,
   14751 GIC           6 :                                                    (Node *) list_make2($5, $7),
   14752 CBC           6 :                                                    @2);
   14753 ECB             :                 }
   14754                 :             | a_expr IN_P in_expr
   14755                 :                 {
   14756                 :                     /* in_expr returns a SubLink or a list of a_exprs */
   14757 GIC       30070 :                     if (IsA($3, SubLink))
   14758                 :                     {
   14759 ECB             :                         /* generate foo = ANY (subquery) */
   14760 GIC        3936 :                         SubLink    *n = (SubLink *) $3;
   14761 ECB             : 
   14762 CBC        3936 :                         n->subLinkType = ANY_SUBLINK;
   14763            3936 :                         n->subLinkId = 0;
   14764            3936 :                         n->testexpr = $1;
   14765 GIC        3936 :                         n->operName = NIL;       /* show it's IN not = ANY */
   14766            3936 :                         n->location = @2;
   14767            3936 :                         $$ = (Node *) n;
   14768 ECB             :                     }
   14769                 :                     else
   14770                 :                     {
   14771                 :                         /* generate scalar IN expression */
   14772 CBC       26134 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "=", $1, $3, @2);
   14773                 :                     }
   14774                 :                 }
   14775                 :             | a_expr NOT_LA IN_P in_expr                        %prec NOT_LA
   14776 ECB             :                 {
   14777                 :                     /* in_expr returns a SubLink or a list of a_exprs */
   14778 CBC        2808 :                     if (IsA($4, SubLink))
   14779 ECB             :                     {
   14780                 :                         /* generate NOT (foo = ANY (subquery)) */
   14781                 :                         /* Make an = ANY node */
   14782 GIC          60 :                         SubLink    *n = (SubLink *) $4;
   14783                 : 
   14784 CBC          60 :                         n->subLinkType = ANY_SUBLINK;
   14785 GIC          60 :                         n->subLinkId = 0;
   14786 CBC          60 :                         n->testexpr = $1;
   14787              60 :                         n->operName = NIL;       /* show it's IN not = ANY */
   14788              60 :                         n->location = @2;
   14789                 :                         /* Stick a NOT on top; must have same parse location */
   14790 GIC          60 :                         $$ = makeNotExpr((Node *) n, @2);
   14791                 :                     }
   14792 ECB             :                     else
   14793                 :                     {
   14794                 :                         /* generate scalar NOT IN expression */
   14795 CBC        2748 :                         $$ = (Node *) makeSimpleA_Expr(AEXPR_IN, "<>", $1, $4, @2);
   14796 ECB             :                     }
   14797                 :                 }
   14798                 :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   14799                 :                 {
   14800 CBC          81 :                     SubLink    *n = makeNode(SubLink);
   14801                 : 
   14802              81 :                     n->subLinkType = $3;
   14803              81 :                     n->subLinkId = 0;
   14804              81 :                     n->testexpr = $1;
   14805 GIC          81 :                     n->operName = $2;
   14806              81 :                     n->subselect = $4;
   14807              81 :                     n->location = @2;
   14808              81 :                     $$ = (Node *) n;
   14809 ECB             :                 }
   14810                 :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   14811                 :                 {
   14812 CBC        7622 :                     if ($3 == ANY_SUBLINK)
   14813 GIC        7472 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   14814 ECB             :                     else
   14815 CBC         150 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   14816 ECB             :                 }
   14817                 :             | UNIQUE opt_unique_null_treatment select_with_parens
   14818                 :                 {
   14819                 :                     /* Not sure how to get rid of the parentheses
   14820                 :                      * but there are lots of shift/reduce errors without them.
   14821                 :                      *
   14822                 :                      * Should be able to implement this by plopping the entire
   14823                 :                      * select into a node, then transforming the target expressions
   14824                 :                      * from whatever they are into count(*), and testing the
   14825                 :                      * entire result equal to one.
   14826                 :                      * But, will probably implement a separate node in the executor.
   14827                 :                      */
   14828 UIC           0 :                     ereport(ERROR,
   14829                 :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14830 ECB             :                              errmsg("UNIQUE predicate is not yet implemented"),
   14831                 :                              parser_errposition(@1)));
   14832                 :                 }
   14833                 :             | a_expr IS DOCUMENT_P                  %prec IS
   14834                 :                 {
   14835 GIC           9 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   14836 CBC           9 :                                      list_make1($1), @2);
   14837 ECB             :                 }
   14838                 :             | a_expr IS NOT DOCUMENT_P              %prec IS
   14839                 :                 {
   14840 CBC           9 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   14841 GIC           9 :                                                  list_make1($1), @2),
   14842 CBC           9 :                                      @2);
   14843                 :                 }
   14844                 :             | a_expr IS NORMALIZED                              %prec IS
   14845                 :                 {
   14846 GIC           6 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   14847 CBC           6 :                                                list_make1($1),
   14848                 :                                                COERCE_SQL_SYNTAX,
   14849 GIC           6 :                                                @2);
   14850                 :                 }
   14851                 :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   14852 ECB             :                 {
   14853 GIC          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   14854 CBC          18 :                                                list_make2($1, makeStringConst($3, @3)),
   14855 ECB             :                                                COERCE_SQL_SYNTAX,
   14856 CBC          18 :                                                @2);
   14857 ECB             :                 }
   14858                 :             | a_expr IS NOT NORMALIZED                          %prec IS
   14859                 :                 {
   14860 LBC           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   14861 UIC           0 :                                                            list_make1($1),
   14862                 :                                                            COERCE_SQL_SYNTAX,
   14863               0 :                                                            @2),
   14864 LBC           0 :                                      @2);
   14865 ECB             :                 }
   14866                 :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   14867                 :                 {
   14868 UIC           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   14869               0 :                                                            list_make2($1, makeStringConst($4, @4)),
   14870                 :                                                            COERCE_SQL_SYNTAX,
   14871               0 :                                                            @2),
   14872               0 :                                      @2);
   14873                 :                 }
   14874                 :             | a_expr IS json_predicate_type_constraint
   14875                 :                     json_key_uniqueness_constraint_opt      %prec IS
   14876                 :                 {
   14877 GNC         142 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14878                 : 
   14879             142 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, @1);
   14880                 :                 }
   14881                 :             /*
   14882                 :              * Required by SQL/JSON, but there are conflicts
   14883                 :             | a_expr
   14884                 :                 FORMAT_LA JSON json_encoding_clause_opt
   14885                 :                 IS  json_predicate_type_constraint
   14886                 :                     json_key_uniqueness_constraint_opt      %prec IS
   14887                 :                 {
   14888                 :                     $3.location = @2;
   14889                 :                     $$ = makeJsonIsPredicate($1, $3, $5, $6, @1);
   14890                 :                 }
   14891                 :             */
   14892                 :             | a_expr IS NOT
   14893                 :                     json_predicate_type_constraint
   14894                 :                     json_key_uniqueness_constraint_opt      %prec IS
   14895                 :                 {
   14896              22 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14897                 : 
   14898              22 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, @1), @1);
   14899                 :                 }
   14900                 :             /*
   14901                 :              * Required by SQL/JSON, but there are conflicts
   14902                 :             | a_expr
   14903                 :                 FORMAT_LA JSON json_encoding_clause_opt
   14904                 :                 IS NOT
   14905                 :                     json_predicate_type_constraint
   14906                 :                     json_key_uniqueness_constraint_opt      %prec IS
   14907                 :                 {
   14908                 :                     $3.location = @2;
   14909                 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $3, $6, $7, @1), @1);
   14910                 :                 }
   14911                 :             */
   14912                 :             | DEFAULT
   14913                 :                 {
   14914                 :                     /*
   14915                 :                      * The SQL spec only allows DEFAULT in "contextually typed
   14916                 :                      * expressions", but for us, it's easier to allow it in
   14917                 :                      * any a_expr and then throw error during parse analysis
   14918 EUB             :                      * if it's in an inappropriate context.  This way also
   14919                 :                      * lets us say something smarter than "syntax error".
   14920                 :                      */
   14921 GIC         661 :                     SetToDefault *n = makeNode(SetToDefault);
   14922                 : 
   14923                 :                     /* parse analysis will fill in the rest */
   14924             661 :                     n->location = @1;
   14925 CBC         661 :                     $$ = (Node *) n;
   14926 ECB             :                 }
   14927                 :         ;
   14928                 : 
   14929                 : /*
   14930                 :  * Restricted expressions
   14931                 :  *
   14932                 :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   14933                 :  *
   14934                 :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   14935                 :  * cause trouble in the places where b_expr is used.  For simplicity, we
   14936                 :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   14937                 :  */
   14938                 : b_expr:     c_expr
   14939 CBC        2495 :                 { $$ = $1; }
   14940                 :             | b_expr TYPECAST Typename
   14941 GIC          67 :                 { $$ = makeTypeCast($1, $3, @2); }
   14942                 :             | '+' b_expr                    %prec UMINUS
   14943 LBC           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   14944 ECB             :             | '-' b_expr                    %prec UMINUS
   14945 GIC          33 :                 { $$ = doNegate($2, @1); }
   14946 ECB             :             | b_expr '+' b_expr
   14947 GIC          15 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   14948                 :             | b_expr '-' b_expr
   14949               6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   14950 EUB             :             | b_expr '*' b_expr
   14951 GBC           6 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   14952                 :             | b_expr '/' b_expr
   14953 UBC           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   14954 EUB             :             | b_expr '%' b_expr
   14955 UIC           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   14956                 :             | b_expr '^' b_expr
   14957 GIC           3 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   14958 EUB             :             | b_expr '<' b_expr
   14959 UBC           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   14960                 :             | b_expr '>' b_expr
   14961               0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   14962 EUB             :             | b_expr '=' b_expr
   14963 UIC           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   14964                 :             | b_expr LESS_EQUALS b_expr
   14965               0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   14966                 :             | b_expr GREATER_EQUALS b_expr
   14967 LBC           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   14968                 :             | b_expr NOT_EQUALS b_expr
   14969               0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   14970                 :             | b_expr qual_Op b_expr             %prec Op
   14971 GIC           6 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   14972                 :             | qual_Op b_expr                    %prec Op
   14973 UIC           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   14974                 :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   14975                 :                 {
   14976               0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   14977                 :                 }
   14978                 :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   14979                 :                 {
   14980               0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   14981                 :                 }
   14982                 :             | b_expr IS DOCUMENT_P                  %prec IS
   14983                 :                 {
   14984               0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   14985               0 :                                      list_make1($1), @2);
   14986 ECB             :                 }
   14987                 :             | b_expr IS NOT DOCUMENT_P              %prec IS
   14988                 :                 {
   14989 UIC           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   14990               0 :                                                  list_make1($1), @2),
   14991               0 :                                      @2);
   14992                 :                 }
   14993                 :         ;
   14994                 : 
   14995                 : /*
   14996                 :  * Productions that can be used in both a_expr and b_expr.
   14997                 :  *
   14998                 :  * Note: productions that refer recursively to a_expr or b_expr mostly
   14999                 :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15000                 :  * inside parentheses, such as function arguments; that cannot introduce
   15001                 :  * ambiguity to the b_expr syntax.
   15002                 :  */
   15003 GIC     1358101 : c_expr:     columnref                               { $$ = $1; }
   15004          882201 :             | AexprConst                            { $$ = $1; }
   15005                 :             | PARAM opt_indirection
   15006                 :                 {
   15007          135122 :                     ParamRef   *p = makeNode(ParamRef);
   15008                 : 
   15009          135122 :                     p->number = $1;
   15010          135122 :                     p->location = @1;
   15011 CBC      135122 :                     if ($2)
   15012                 :                     {
   15013 GIC        2465 :                         A_Indirection *n = makeNode(A_Indirection);
   15014 ECB             : 
   15015 CBC        2465 :                         n->arg = (Node *) p;
   15016 GIC        2465 :                         n->indirection = check_indirection($2, yyscanner);
   15017            2465 :                         $$ = (Node *) n;
   15018                 :                     }
   15019                 :                     else
   15020          132657 :                         $$ = (Node *) p;
   15021                 :                 }
   15022                 :             | '(' a_expr ')' opt_indirection
   15023                 :                 {
   15024          107029 :                     if ($4)
   15025                 :                     {
   15026           34076 :                         A_Indirection *n = makeNode(A_Indirection);
   15027                 : 
   15028           34076 :                         n->arg = $2;
   15029 CBC       34076 :                         n->indirection = check_indirection($4, yyscanner);
   15030 GIC       34076 :                         $$ = (Node *) n;
   15031 ECB             :                     }
   15032                 :                     else
   15033 GBC       72953 :                         $$ = $2;
   15034                 :                 }
   15035 ECB             :             | case_expr
   15036 GIC       50079 :                 { $$ = $1; }
   15037 ECB             :             | func_expr
   15038 GIC      497078 :                 { $$ = $1; }
   15039 ECB             :             | select_with_parens            %prec UMINUS
   15040                 :                 {
   15041 CBC       17015 :                     SubLink    *n = makeNode(SubLink);
   15042                 : 
   15043 GBC       17015 :                     n->subLinkType = EXPR_SUBLINK;
   15044 GIC       17015 :                     n->subLinkId = 0;
   15045 GBC       17015 :                     n->testexpr = NULL;
   15046 GIC       17015 :                     n->operName = NIL;
   15047 CBC       17015 :                     n->subselect = $1;
   15048 GIC       17015 :                     n->location = @1;
   15049 GBC       17015 :                     $$ = (Node *) n;
   15050                 :                 }
   15051 EUB             :             | select_with_parens indirection
   15052                 :                 {
   15053                 :                     /*
   15054                 :                      * Because the select_with_parens nonterminal is designed
   15055                 :                      * to "eat" as many levels of parens as possible, the
   15056                 :                      * '(' a_expr ')' opt_indirection production above will
   15057                 :                      * fail to match a sub-SELECT with indirection decoration;
   15058                 :                      * the sub-SELECT won't be regarded as an a_expr as long
   15059                 :                      * as there are parens around it.  To support applying
   15060                 :                      * subscripting or field selection to a sub-SELECT result,
   15061 ECB             :                      * we need this redundant-looking production.
   15062                 :                      */
   15063 GBC           9 :                     SubLink    *n = makeNode(SubLink);
   15064 GIC           9 :                     A_Indirection *a = makeNode(A_Indirection);
   15065                 : 
   15066 GBC           9 :                     n->subLinkType = EXPR_SUBLINK;
   15067 GIC           9 :                     n->subLinkId = 0;
   15068               9 :                     n->testexpr = NULL;
   15069               9 :                     n->operName = NIL;
   15070 GBC           9 :                     n->subselect = $1;
   15071 GIC           9 :                     n->location = @1;
   15072               9 :                     a->arg = (Node *) n;
   15073               9 :                     a->indirection = check_indirection($2, yyscanner);
   15074 GBC           9 :                     $$ = (Node *) a;
   15075 EUB             :                 }
   15076                 :             | EXISTS select_with_parens
   15077                 :                 {
   15078 GIC        4114 :                     SubLink    *n = makeNode(SubLink);
   15079 EUB             : 
   15080 GBC        4114 :                     n->subLinkType = EXISTS_SUBLINK;
   15081            4114 :                     n->subLinkId = 0;
   15082 GIC        4114 :                     n->testexpr = NULL;
   15083            4114 :                     n->operName = NIL;
   15084            4114 :                     n->subselect = $2;
   15085            4114 :                     n->location = @1;
   15086            4114 :                     $$ = (Node *) n;
   15087                 :                 }
   15088                 :             | ARRAY select_with_parens
   15089                 :                 {
   15090            3918 :                     SubLink    *n = makeNode(SubLink);
   15091                 : 
   15092            3918 :                     n->subLinkType = ARRAY_SUBLINK;
   15093 CBC        3918 :                     n->subLinkId = 0;
   15094            3918 :                     n->testexpr = NULL;
   15095 GIC        3918 :                     n->operName = NIL;
   15096            3918 :                     n->subselect = $2;
   15097 CBC        3918 :                     n->location = @1;
   15098 GIC        3918 :                     $$ = (Node *) n;
   15099 ECB             :                 }
   15100                 :             | ARRAY array_expr
   15101                 :                 {
   15102 GIC        3412 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15103 ECB             : 
   15104                 :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15105 CBC        3412 :                     n->location = @1;
   15106            3412 :                     $$ = (Node *) n;
   15107 ECB             :                 }
   15108                 :             | explicit_row
   15109                 :                 {
   15110 CBC        1832 :                     RowExpr    *r = makeNode(RowExpr);
   15111                 : 
   15112 GIC        1832 :                     r->args = $1;
   15113            1832 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15114 CBC        1832 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15115 GIC        1832 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15116 CBC        1832 :                     r->location = @1;
   15117 GIC        1832 :                     $$ = (Node *) r;
   15118 ECB             :                 }
   15119                 :             | implicit_row
   15120                 :                 {
   15121 GIC        3959 :                     RowExpr    *r = makeNode(RowExpr);
   15122                 : 
   15123 CBC        3959 :                     r->args = $1;
   15124 GIC        3959 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15125            3959 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15126 CBC        3959 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   15127 GIC        3959 :                     r->location = @1;
   15128 CBC        3959 :                     $$ = (Node *) r;
   15129                 :                 }
   15130                 :             | GROUPING '(' expr_list ')'
   15131 ECB             :               {
   15132 GIC         157 :                   GroupingFunc *g = makeNode(GroupingFunc);
   15133 ECB             : 
   15134 CBC         157 :                   g->args = $3;
   15135             157 :                   g->location = @1;
   15136             157 :                   $$ = (Node *) g;
   15137 ECB             :               }
   15138                 :         ;
   15139                 : 
   15140                 : func_application: func_name '(' ')'
   15141                 :                 {
   15142 GIC       61653 :                     $$ = (Node *) makeFuncCall($1, NIL,
   15143                 :                                                COERCE_EXPLICIT_CALL,
   15144           61653 :                                                @1);
   15145                 :                 }
   15146                 :             | func_name '(' func_arg_list opt_sort_clause ')'
   15147                 :                 {
   15148          242684 :                     FuncCall   *n = makeFuncCall($1, $3,
   15149                 :                                                  COERCE_EXPLICIT_CALL,
   15150          242684 :                                                  @1);
   15151                 : 
   15152          242684 :                     n->agg_order = $4;
   15153 CBC      242684 :                     $$ = (Node *) n;
   15154 ECB             :                 }
   15155                 :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   15156                 :                 {
   15157 CBC         269 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   15158 ECB             :                                                  COERCE_EXPLICIT_CALL,
   15159 CBC         269 :                                                  @1);
   15160 ECB             : 
   15161 CBC         269 :                     n->func_variadic = true;
   15162             269 :                     n->agg_order = $5;
   15163             269 :                     $$ = (Node *) n;
   15164 ECB             :                 }
   15165                 :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   15166                 :                 {
   15167 GIC          60 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   15168 ECB             :                                                  COERCE_EXPLICIT_CALL,
   15169 GIC          60 :                                                  @1);
   15170 ECB             : 
   15171 CBC          60 :                     n->func_variadic = true;
   15172              60 :                     n->agg_order = $7;
   15173              60 :                     $$ = (Node *) n;
   15174 ECB             :                 }
   15175                 :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   15176                 :                 {
   15177 UIC           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   15178                 :                                                  COERCE_EXPLICIT_CALL,
   15179               0 :                                                  @1);
   15180 ECB             : 
   15181 UIC           0 :                     n->agg_order = $5;
   15182 ECB             :                     /* Ideally we'd mark the FuncCall node to indicate
   15183                 :                      * "must be an aggregate", but there's no provision
   15184                 :                      * for that in FuncCall at the moment.
   15185                 :                      */
   15186 LBC           0 :                     $$ = (Node *) n;
   15187 ECB             :                 }
   15188                 :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   15189                 :                 {
   15190 GIC         251 :                     FuncCall   *n = makeFuncCall($1, $4,
   15191                 :                                                  COERCE_EXPLICIT_CALL,
   15192 CBC         251 :                                                  @1);
   15193                 : 
   15194 GIC         251 :                     n->agg_order = $5;
   15195 CBC         251 :                     n->agg_distinct = true;
   15196             251 :                     $$ = (Node *) n;
   15197                 :                 }
   15198                 :             | func_name '(' '*' ')'
   15199                 :                 {
   15200 ECB             :                     /*
   15201                 :                      * We consider AGGREGATE(*) to invoke a parameterless
   15202                 :                      * aggregate.  This does the right thing for COUNT(*),
   15203                 :                      * and there are no other aggregates in SQL that accept
   15204                 :                      * '*' as parameter.
   15205                 :                      *
   15206                 :                      * The FuncCall node is also marked agg_star = true,
   15207                 :                      * so that later processing can detect what the argument
   15208                 :                      * really was.
   15209                 :                      */
   15210 GIC        5500 :                     FuncCall   *n = makeFuncCall($1, NIL,
   15211 ECB             :                                                  COERCE_EXPLICIT_CALL,
   15212 GIC        5500 :                                                  @1);
   15213 ECB             : 
   15214 CBC        5500 :                     n->agg_star = true;
   15215            5500 :                     $$ = (Node *) n;
   15216 ECB             :                 }
   15217                 :         ;
   15218                 : 
   15219                 : 
   15220                 : /*
   15221                 :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   15222                 :  * so that we have classifications for "everything that is a function call or
   15223                 :  * looks like one".  This isn't very important, but it saves us having to
   15224                 :  * document which variants are legal in places like "FROM function()" or the
   15225                 :  * backwards-compatible functional-index syntax for CREATE INDEX.
   15226                 :  * (Note that many of the special SQL functions wouldn't actually make any
   15227                 :  * sense as functional index entries, but we ignore that consideration here.)
   15228                 :  */
   15229                 : func_expr: func_application within_group_clause filter_clause over_clause
   15230                 :                 {
   15231 GIC      279933 :                     FuncCall   *n = (FuncCall *) $1;
   15232 ECB             : 
   15233                 :                     /*
   15234                 :                      * The order clause for WITHIN GROUP and the one for
   15235                 :                      * plain-aggregate ORDER BY share a field, so we have to
   15236                 :                      * check here that at most one is present.  We also check
   15237                 :                      * for DISTINCT and VARIADIC here to give a better error
   15238                 :                      * location.  Other consistency checks are deferred to
   15239                 :                      * parse analysis.
   15240                 :                      */
   15241 GIC      279933 :                     if ($2 != NIL)
   15242 ECB             :                     {
   15243 CBC         174 :                         if (n->agg_order != NIL)
   15244 GIC           3 :                             ereport(ERROR,
   15245                 :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15246                 :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   15247 ECB             :                                      parser_errposition(@2)));
   15248 GIC         171 :                         if (n->agg_distinct)
   15249 LBC           0 :                             ereport(ERROR,
   15250                 :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15251 ECB             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   15252                 :                                      parser_errposition(@2)));
   15253 CBC         171 :                         if (n->func_variadic)
   15254 UIC           0 :                             ereport(ERROR,
   15255                 :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   15256                 :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   15257 ECB             :                                      parser_errposition(@2)));
   15258 GIC         171 :                         n->agg_order = $2;
   15259 CBC         171 :                         n->agg_within_group = true;
   15260                 :                     }
   15261          279930 :                     n->agg_filter = $3;
   15262          279930 :                     n->over = $4;
   15263          279930 :                     $$ = (Node *) n;
   15264                 :                 }
   15265                 :             | json_aggregate_func filter_clause over_clause
   15266                 :                 {
   15267 GNC         270 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   15268             135 :                         ((JsonObjectAgg *) $1)->constructor :
   15269              75 :                         ((JsonArrayAgg *) $1)->constructor;
   15270                 : 
   15271             135 :                     n->agg_filter = $2;
   15272             135 :                     n->over = $3;
   15273             135 :                     $$ = (Node *) $1;
   15274                 :                 }
   15275                 :             | func_expr_common_subexpr
   15276 GIC      217013 :                 { $$ = $1; }
   15277 EUB             :         ;
   15278                 : 
   15279                 : /*
   15280                 :  * As func_expr but does not accept WINDOW functions directly
   15281                 :  * (but they can still be contained in arguments for functions etc).
   15282                 :  * Use this when window expressions are not allowed, where needed to
   15283                 :  * disambiguate the grammar (e.g. in CREATE INDEX).
   15284                 :  */
   15285                 : func_expr_windowless:
   15286 GBC       30232 :             func_application                        { $$ = $1; }
   15287 GIC          72 :             | func_expr_common_subexpr              { $$ = $1; }
   15288 UNC           0 :             | json_aggregate_func                   { $$ = $1; }
   15289                 :         ;
   15290                 : 
   15291 ECB             : /*
   15292                 :  * Special expressions that are considered to be functions.
   15293                 :  */
   15294                 : func_expr_common_subexpr:
   15295                 :             COLLATION FOR '(' a_expr ')'
   15296                 :                 {
   15297 CBC          15 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   15298 GIC          15 :                                                list_make1($4),
   15299                 :                                                COERCE_SQL_SYNTAX,
   15300              15 :                                                @1);
   15301                 :                 }
   15302                 :             | CURRENT_DATE
   15303                 :                 {
   15304 GNC         634 :                     $$ = (Node *) makeFuncCall(SystemFuncName("current_date"),
   15305                 :                                                NIL,
   15306                 :                                                COERCE_SQL_SYNTAX,
   15307                 :                                                @1);
   15308                 :                 }
   15309                 :             | CURRENT_TIME
   15310                 :                 {
   15311              12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("current_time"),
   15312                 :                                                NIL,
   15313                 :                                                COERCE_SQL_SYNTAX,
   15314                 :                                                @1);
   15315                 :                 }
   15316                 :             | CURRENT_TIME '(' Iconst ')'
   15317 ECB             :                 {
   15318 GNC          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("current_time"),
   15319              12 :                                                list_make1(makeIntConst($3, @3)),
   15320                 :                                                COERCE_SQL_SYNTAX,
   15321              12 :                                                @1);
   15322 ECB             :                 }
   15323                 :             | CURRENT_TIMESTAMP
   15324                 :                 {
   15325 GNC         139 :                     $$ = (Node *) makeFuncCall(SystemFuncName("current_timestamp"),
   15326                 :                                                NIL,
   15327                 :                                                COERCE_SQL_SYNTAX,
   15328                 :                                                @1);
   15329                 :                 }
   15330                 :             | CURRENT_TIMESTAMP '(' Iconst ')'
   15331                 :                 {
   15332             318 :                     $$ = (Node *) makeFuncCall(SystemFuncName("current_timestamp"),
   15333             318 :                                                list_make1(makeIntConst($3, @3)),
   15334                 :                                                COERCE_SQL_SYNTAX,
   15335             318 :                                                @1);
   15336                 :                 }
   15337                 :             | LOCALTIME
   15338                 :                 {
   15339              12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("localtime"),
   15340                 :                                                NIL,
   15341                 :                                                COERCE_SQL_SYNTAX,
   15342                 :                                                @1);
   15343                 :                 }
   15344                 :             | LOCALTIME '(' Iconst ')'
   15345                 :                 {
   15346              12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("localtime"),
   15347              12 :                                                list_make1(makeIntConst($3, @3)),
   15348                 :                                                COERCE_SQL_SYNTAX,
   15349              12 :                                                @1);
   15350                 :                 }
   15351                 :             | LOCALTIMESTAMP
   15352                 :                 {
   15353              18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("localtimestamp"),
   15354                 :                                                NIL,
   15355                 :                                                COERCE_SQL_SYNTAX,
   15356                 :                                                @1);
   15357                 :                 }
   15358                 :             | LOCALTIMESTAMP '(' Iconst ')'
   15359                 :                 {
   15360              12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("localtimestamp"),
   15361              12 :                                                list_make1(makeIntConst($3, @3)),
   15362                 :                                                COERCE_SQL_SYNTAX,
   15363              12 :                                                @1);
   15364                 :                 }
   15365                 :             | CURRENT_ROLE
   15366                 :                 {
   15367              34 :                     $$ = (Node *) makeFuncCall(SystemFuncName("current_role"),
   15368                 :                                                NIL,
   15369                 :                                                COERCE_SQL_SYNTAX,
   15370                 :                                                @1);
   15371                 :                 }
   15372 ECB             :             | CURRENT_USER
   15373                 :                 {
   15374 GNC        1463 :                     $$ = (Node *) makeFuncCall(SystemFuncName("current_user"),
   15375                 :                                                NIL,
   15376                 :                                                COERCE_SQL_SYNTAX,
   15377                 :                                                @1);
   15378 ECB             :                 }
   15379                 :             | SESSION_USER
   15380                 :                 {
   15381 GNC          53 :                     $$ = (Node *) makeFuncCall(SystemFuncName("session_user"),
   15382                 :                                                NIL,
   15383                 :                                                COERCE_SQL_SYNTAX,
   15384                 :                                                @1);
   15385                 :                 }
   15386                 :             | SYSTEM_USER
   15387                 :                 {
   15388              12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   15389                 :                                                NIL,
   15390                 :                                                COERCE_SQL_SYNTAX,
   15391                 :                                                @1);
   15392 ECB             :                 }
   15393 EUB             :             | USER
   15394                 :                 {
   15395 GNC          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("user"),
   15396                 :                                                NIL,
   15397                 :                                                COERCE_SQL_SYNTAX,
   15398                 :                                                @1);
   15399                 :                 }
   15400 ECB             :             | CURRENT_CATALOG
   15401 EUB             :                 {
   15402 GNC          15 :                     $$ = (Node *) makeFuncCall(SystemFuncName("current_catalog"),
   15403                 :                                                NIL,
   15404                 :                                                COERCE_SQL_SYNTAX,
   15405                 :                                                @1);
   15406                 :                 }
   15407                 :             | CURRENT_SCHEMA
   15408 ECB             :                 {
   15409 GNC          15 :                     $$ = (Node *) makeFuncCall(SystemFuncName("current_schema"),
   15410                 :                                                NIL,
   15411                 :                                                COERCE_SQL_SYNTAX,
   15412                 :                                                @1);
   15413                 :                 }
   15414 ECB             :             | CAST '(' a_expr AS Typename ')'
   15415 CBC      201838 :                 { $$ = makeTypeCast($3, $5, @1); }
   15416 ECB             :             | EXTRACT '(' extract_list ')'
   15417                 :                 {
   15418 GIC        1636 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   15419            1636 :                                                $3,
   15420 ECB             :                                                COERCE_SQL_SYNTAX,
   15421 CBC        1636 :                                                @1);
   15422 ECB             :                 }
   15423                 :             | NORMALIZE '(' a_expr ')'
   15424                 :                 {
   15425 CBC           9 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15426               9 :                                                list_make1($3),
   15427                 :                                                COERCE_SQL_SYNTAX,
   15428 GIC           9 :                                                @1);
   15429 ECB             :                 }
   15430                 :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   15431                 :                 {
   15432 GIC          18 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   15433              18 :                                                list_make2($3, makeStringConst($5, @5)),
   15434                 :                                                COERCE_SQL_SYNTAX,
   15435              18 :                                                @1);
   15436                 :                 }
   15437                 :             | OVERLAY '(' overlay_list ')'
   15438                 :                 {
   15439 CBC          41 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   15440              41 :                                                $3,
   15441 EUB             :                                                COERCE_SQL_SYNTAX,
   15442 GIC          41 :                                                @1);
   15443                 :                 }
   15444                 :             | OVERLAY '(' func_arg_list_opt ')'
   15445                 :                 {
   15446                 :                     /*
   15447                 :                      * allow functions named overlay() to be called without
   15448                 :                      * special syntax
   15449                 :                      */
   15450 LBC           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   15451               0 :                                                $3,
   15452                 :                                                COERCE_EXPLICIT_CALL,
   15453               0 :                                                @1);
   15454                 :                 }
   15455                 :             | POSITION '(' position_list ')'
   15456                 :                 {
   15457 ECB             :                     /*
   15458                 :                      * position(A in B) is converted to position(B, A)
   15459                 :                      *
   15460                 :                      * We deliberately don't offer a "plain syntax" option
   15461                 :                      * for position(), because the reversal of the arguments
   15462                 :                      * creates too much risk of confusion.
   15463                 :                      */
   15464 CBC         440 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   15465 GIC         440 :                                                $3,
   15466                 :                                                COERCE_SQL_SYNTAX,
   15467             440 :                                                @1);
   15468                 :                 }
   15469                 :             | SUBSTRING '(' substr_list ')'
   15470                 :                 {
   15471 ECB             :                     /* substring(A from B for C) is converted to
   15472                 :                      * substring(A, B, C) - thomas 2000-11-28
   15473                 :                      */
   15474 CBC        1678 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   15475 GIC        1678 :                                                $3,
   15476                 :                                                COERCE_SQL_SYNTAX,
   15477            1678 :                                                @1);
   15478 ECB             :                 }
   15479                 :             | SUBSTRING '(' func_arg_list_opt ')'
   15480                 :                 {
   15481                 :                     /*
   15482                 :                      * allow functions named substring() to be called without
   15483                 :                      * special syntax
   15484                 :                      */
   15485 CBC         359 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   15486             359 :                                                $3,
   15487                 :                                                COERCE_EXPLICIT_CALL,
   15488             359 :                                                @1);
   15489                 :                 }
   15490                 :             | TREAT '(' a_expr AS Typename ')'
   15491                 :                 {
   15492 ECB             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   15493                 :                      * which is defined to be a subtype of the original expression.
   15494                 :                      * In SQL99, this is intended for use with structured UDTs,
   15495                 :                      * but let's make this a generally useful form allowing stronger
   15496                 :                      * coercions than are handled by implicit casting.
   15497                 :                      *
   15498                 :                      * Convert SystemTypeName() to SystemFuncName() even though
   15499                 :                      * at the moment they result in the same thing.
   15500                 :                      */
   15501 UIC           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   15502 LBC           0 :                                                list_make1($3),
   15503                 :                                                COERCE_EXPLICIT_CALL,
   15504 UIC           0 :                                                @1);
   15505                 :                 }
   15506 ECB             :             | TRIM '(' BOTH trim_list ')'
   15507                 :                 {
   15508                 :                     /* various trim expressions are defined in SQL
   15509                 :                      * - thomas 1997-07-19
   15510                 :                      */
   15511 GIC           6 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15512               6 :                                                $4,
   15513 ECB             :                                                COERCE_SQL_SYNTAX,
   15514 CBC           6 :                                                @1);
   15515                 :                 }
   15516 ECB             :             | TRIM '(' LEADING trim_list ')'
   15517                 :                 {
   15518 GIC          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   15519              12 :                                                $4,
   15520 ECB             :                                                COERCE_SQL_SYNTAX,
   15521 GIC          12 :                                                @1);
   15522                 :                 }
   15523                 :             | TRIM '(' TRAILING trim_list ')'
   15524                 :                 {
   15525             530 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   15526             530 :                                                $4,
   15527 ECB             :                                                COERCE_SQL_SYNTAX,
   15528 GIC         530 :                                                @1);
   15529                 :                 }
   15530                 :             | TRIM '(' trim_list ')'
   15531                 :                 {
   15532              49 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   15533              49 :                                                $3,
   15534 ECB             :                                                COERCE_SQL_SYNTAX,
   15535 GIC          49 :                                                @1);
   15536                 :                 }
   15537                 :             | NULLIF '(' a_expr ',' a_expr ')'
   15538                 :                 {
   15539             400 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   15540                 :                 }
   15541 ECB             :             | COALESCE '(' expr_list ')'
   15542                 :                 {
   15543 GIC        6385 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   15544                 : 
   15545            6385 :                     c->args = $3;
   15546            6385 :                     c->location = @1;
   15547            6385 :                     $$ = (Node *) c;
   15548 ECB             :                 }
   15549                 :             | GREATEST '(' expr_list ')'
   15550                 :                 {
   15551 GIC          80 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   15552                 : 
   15553              80 :                     v->args = $3;
   15554              80 :                     v->op = IS_GREATEST;
   15555 CBC          80 :                     v->location = @1;
   15556 GIC          80 :                     $$ = (Node *) v;
   15557                 :                 }
   15558                 :             | LEAST '(' expr_list ')'
   15559                 :                 {
   15560              71 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   15561                 : 
   15562 CBC          71 :                     v->args = $3;
   15563 GIC          71 :                     v->op = IS_LEAST;
   15564              71 :                     v->location = @1;
   15565              71 :                     $$ = (Node *) v;
   15566                 :                 }
   15567                 :             | XMLCONCAT '(' expr_list ')'
   15568 ECB             :                 {
   15569 GIC          31 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   15570                 :                 }
   15571 ECB             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   15572                 :                 {
   15573 GIC           3 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   15574 ECB             :                 }
   15575                 :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   15576                 :                 {
   15577 GIC          18 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   15578 ECB             :                 }
   15579                 :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   15580                 :                 {
   15581 CBC          58 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   15582                 :                 }
   15583                 :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   15584                 :                 {
   15585              10 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   15586 ECB             :                 }
   15587                 :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   15588                 :                 {
   15589                 :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   15590                 :                      * converted to xmlexists(A, B)*/
   15591 GIC          27 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   15592 CBC          27 :                                                list_make2($3, $4),
   15593 ECB             :                                                COERCE_SQL_SYNTAX,
   15594 GIC          27 :                                                @1);
   15595 ECB             :                 }
   15596                 :             | XMLFOREST '(' xml_attribute_list ')'
   15597                 :                 {
   15598 GIC          16 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   15599                 :                 }
   15600                 :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   15601                 :                 {
   15602                 :                     XmlExpr *x = (XmlExpr *)
   15603 GBC          70 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   15604              70 :                                     list_make2($4, makeBoolAConst($5, -1)),
   15605 GIC          70 :                                     @1);
   15606 EUB             : 
   15607 GIC          70 :                     x->xmloption = $3;
   15608              70 :                     $$ = (Node *) x;
   15609                 :                 }
   15610                 :             | XMLPI '(' NAME_P ColLabel ')'
   15611                 :                 {
   15612              15 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   15613                 :                 }
   15614                 :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   15615                 :                 {
   15616              25 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   15617 ECB             :                 }
   15618                 :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   15619                 :                 {
   15620 CBC          34 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   15621 GIC          34 :                                      list_make3($3, $5, $6), @1);
   15622                 :                 }
   15623                 :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   15624                 :                 {
   15625              95 :                     XmlSerialize *n = makeNode(XmlSerialize);
   15626                 : 
   15627 CBC          95 :                     n->xmloption = $3;
   15628              95 :                     n->expr = $4;
   15629 GIC          95 :                     n->typeName = $6;
   15630 GNC          95 :                     n->indent = $7;
   15631              95 :                     n->location = @1;
   15632              95 :                     $$ = (Node *) n;
   15633                 :                 }
   15634                 :             | JSON_OBJECT '(' func_arg_list ')'
   15635                 :                 {
   15636                 :                     /* Support for legacy (non-standard) json_object() */
   15637              45 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   15638              45 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   15639                 :                 }
   15640                 :             | JSON_OBJECT '(' json_name_and_value_list
   15641                 :                 json_object_constructor_null_clause_opt
   15642                 :                 json_key_uniqueness_constraint_opt
   15643                 :                 json_output_clause_opt ')'
   15644                 :                 {
   15645             141 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   15646                 : 
   15647             141 :                     n->exprs = $3;
   15648             141 :                     n->absent_on_null = $4;
   15649             141 :                     n->unique = $5;
   15650             141 :                     n->output = (JsonOutput *) $6;
   15651             141 :                     n->location = @1;
   15652             141 :                     $$ = (Node *) n;
   15653                 :                 }
   15654                 :             | JSON_OBJECT '(' json_output_clause_opt ')'
   15655                 :                 {
   15656              41 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   15657                 : 
   15658              41 :                     n->exprs = NULL;
   15659              41 :                     n->absent_on_null = false;
   15660              41 :                     n->unique = false;
   15661              41 :                     n->output = (JsonOutput *) $3;
   15662              41 :                     n->location = @1;
   15663              41 :                     $$ = (Node *) n;
   15664                 :                 }
   15665                 :             | JSON_ARRAY '('
   15666                 :                 json_value_expr_list
   15667                 :                 json_array_constructor_null_clause_opt
   15668                 :                 json_output_clause_opt
   15669                 :             ')'
   15670                 :                 {
   15671              48 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   15672                 : 
   15673              48 :                     n->exprs = $3;
   15674              48 :                     n->absent_on_null = $4;
   15675              48 :                     n->output = (JsonOutput *) $5;
   15676              48 :                     n->location = @1;
   15677              48 :                     $$ = (Node *) n;
   15678                 :                 }
   15679                 :             | JSON_ARRAY '('
   15680                 :                 select_no_parens
   15681                 :                 json_format_clause_opt
   15682                 :                 /* json_array_constructor_null_clause_opt */
   15683                 :                 json_output_clause_opt
   15684                 :             ')'
   15685                 :                 {
   15686              27 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   15687                 : 
   15688              27 :                     n->query = $3;
   15689              27 :                     n->format = (JsonFormat *) $4;
   15690              27 :                     n->absent_on_null = true;    /* XXX */
   15691              27 :                     n->output = (JsonOutput *) $5;
   15692              27 :                     n->location = @1;
   15693              27 :                     $$ = (Node *) n;
   15694                 :                 }
   15695                 :             | JSON_ARRAY '('
   15696                 :                 json_output_clause_opt
   15697                 :             ')'
   15698                 :                 {
   15699              41 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   15700                 : 
   15701              41 :                     n->exprs = NIL;
   15702              41 :                     n->absent_on_null = true;
   15703              41 :                     n->output = (JsonOutput *) $3;
   15704 CBC          41 :                     n->location = @1;
   15705 GIC          41 :                     $$ = (Node *) n;
   15706                 :                 }
   15707                 :         ;
   15708                 : 
   15709                 : /*
   15710                 :  * SQL/XML support
   15711                 :  */
   15712 ECB             : xml_root_version: VERSION_P a_expr
   15713 CBC          12 :                 { $$ = $2; }
   15714                 :             | VERSION_P NO VALUE_P
   15715              22 :                 { $$ = makeNullAConst(-1); }
   15716                 :         ;
   15717                 : 
   15718                 : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   15719 GIC          13 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   15720                 :             | ',' STANDALONE_P NO
   15721               6 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   15722                 :             | ',' STANDALONE_P NO VALUE_P
   15723               6 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   15724                 :             | /*EMPTY*/
   15725               9 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   15726                 :         ;
   15727                 : 
   15728 GBC          28 : xml_attributes: XMLATTRIBUTES '(' xml_attribute_list ')'    { $$ = $3; }
   15729 EUB             :         ;
   15730                 : 
   15731 GBC          44 : xml_attribute_list: xml_attribute_el                    { $$ = list_make1($1); }
   15732 GIC          72 :             | xml_attribute_list ',' xml_attribute_el   { $$ = lappend($1, $3); }
   15733                 :         ;
   15734                 : 
   15735                 : xml_attribute_el: a_expr AS ColLabel
   15736                 :                 {
   15737              53 :                     $$ = makeNode(ResTarget);
   15738 CBC          53 :                     $$->name = $3;
   15739              53 :                     $$->indirection = NIL;
   15740 GIC          53 :                     $$->val = (Node *) $1;
   15741 CBC          53 :                     $$->location = @1;
   15742                 :                 }
   15743                 :             | a_expr
   15744                 :                 {
   15745              63 :                     $$ = makeNode(ResTarget);
   15746              63 :                     $$->name = NULL;
   15747 GIC          63 :                     $$->indirection = NIL;
   15748 CBC          63 :                     $$->val = (Node *) $1;
   15749 GIC          63 :                     $$->location = @1;
   15750                 :                 }
   15751                 :         ;
   15752 ECB             : 
   15753 CBC          81 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   15754 GIC          90 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   15755 ECB             :         ;
   15756                 : 
   15757 GNC          60 : xml_indent_option: INDENT                           { $$ = true; }
   15758              12 :             | NO INDENT                             { $$ = false; }
   15759              23 :             | /*EMPTY*/                             { $$ = false; }
   15760                 :         ;
   15761                 : 
   15762 UIC           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   15763 GIC           1 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   15764 CBC          69 :             | /*EMPTY*/                             { $$ = false; }
   15765 ECB             :         ;
   15766                 : 
   15767                 : /* We allow several variants for SQL and other compatibility. */
   15768                 : xmlexists_argument:
   15769                 :             PASSING c_expr
   15770                 :                 {
   15771 CBC         110 :                     $$ = $2;
   15772                 :                 }
   15773                 :             | PASSING c_expr xml_passing_mech
   15774                 :                 {
   15775 LBC           0 :                     $$ = $2;
   15776                 :                 }
   15777 ECB             :             | PASSING xml_passing_mech c_expr
   15778                 :                 {
   15779 CBC          21 :                     $$ = $3;
   15780                 :                 }
   15781                 :             | PASSING xml_passing_mech c_expr xml_passing_mech
   15782                 :                 {
   15783               3 :                     $$ = $3;
   15784                 :                 }
   15785 ECB             :         ;
   15786                 : 
   15787                 : xml_passing_mech:
   15788                 :             BY REF_P
   15789                 :             | BY VALUE_P
   15790                 :         ;
   15791                 : 
   15792                 : 
   15793                 : /*
   15794                 :  * Aggregate decoration clauses
   15795                 :  */
   15796                 : within_group_clause:
   15797 CBC         174 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   15798 GIC      279762 :             | /*EMPTY*/                             { $$ = NIL; }
   15799                 :         ;
   15800                 : 
   15801 ECB             : filter_clause:
   15802 GIC         360 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   15803          279711 :             | /*EMPTY*/                             { $$ = NULL; }
   15804                 :         ;
   15805 ECB             : 
   15806                 : 
   15807                 : /*
   15808                 :  * Window Definitions
   15809                 :  */
   15810                 : window_clause:
   15811 GIC         189 :             WINDOW window_definition_list           { $$ = $2; }
   15812          268275 :             | /*EMPTY*/                             { $$ = NIL; }
   15813 ECB             :         ;
   15814                 : 
   15815                 : window_definition_list:
   15816 GIC         189 :             window_definition                       { $$ = list_make1($1); }
   15817 ECB             :             | window_definition_list ',' window_definition
   15818 GIC           6 :                                                     { $$ = lappend($1, $3); }
   15819                 :         ;
   15820                 : 
   15821                 : window_definition:
   15822                 :             ColId AS window_specification
   15823 ECB             :                 {
   15824 CBC         195 :                     WindowDef  *n = $3;
   15825                 : 
   15826             195 :                     n->name = $1;
   15827 GIC         195 :                     $$ = n;
   15828                 :                 }
   15829                 :         ;
   15830 ECB             : 
   15831                 : over_clause: OVER window_specification
   15832 GIC        1419 :                 { $$ = $2; }
   15833                 :             | OVER ColId
   15834                 :                 {
   15835 CBC         321 :                     WindowDef  *n = makeNode(WindowDef);
   15836 ECB             : 
   15837 CBC         321 :                     n->name = $2;
   15838 GIC         321 :                     n->refname = NULL;
   15839 CBC         321 :                     n->partitionClause = NIL;
   15840             321 :                     n->orderClause = NIL;
   15841 GIC         321 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   15842             321 :                     n->startOffset = NULL;
   15843             321 :                     n->endOffset = NULL;
   15844 CBC         321 :                     n->location = @2;
   15845 GIC         321 :                     $$ = n;
   15846                 :                 }
   15847                 :             | /*EMPTY*/
   15848 CBC      278328 :                 { $$ = NULL; }
   15849                 :         ;
   15850                 : 
   15851                 : window_specification: '(' opt_existing_window_name opt_partition_clause
   15852 ECB             :                         opt_sort_clause opt_frame_clause ')'
   15853                 :                 {
   15854 GIC        1614 :                     WindowDef  *n = makeNode(WindowDef);
   15855                 : 
   15856            1614 :                     n->name = NULL;
   15857 CBC        1614 :                     n->refname = $2;
   15858 GIC        1614 :                     n->partitionClause = $3;
   15859 CBC        1614 :                     n->orderClause = $4;
   15860 ECB             :                     /* copy relevant fields of opt_frame_clause */
   15861 CBC        1614 :                     n->frameOptions = $5->frameOptions;
   15862            1614 :                     n->startOffset = $5->startOffset;
   15863            1614 :                     n->endOffset = $5->endOffset;
   15864            1614 :                     n->location = @1;
   15865 GIC        1614 :                     $$ = n;
   15866                 :                 }
   15867                 :         ;
   15868                 : 
   15869 ECB             : /*
   15870                 :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   15871                 :  * of a window_specification, we want the assumption to be that there is
   15872                 :  * no existing_window_name; but those keywords are unreserved and so could
   15873                 :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   15874                 :  * and giving the empty production here a slightly higher precedence, so
   15875                 :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   15876                 :  * These keywords are thus precluded from being an existing_window_name but
   15877                 :  * are not reserved for any other purpose.
   15878                 :  */
   15879 CBC          15 : opt_existing_window_name: ColId                     { $$ = $1; }
   15880            1602 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   15881 ECB             :         ;
   15882                 : 
   15883 CBC         672 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   15884             942 :             | /*EMPTY*/                             { $$ = NIL; }
   15885                 :         ;
   15886                 : 
   15887                 : /*
   15888 ECB             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   15889                 :  * frameOptions, startOffset, and endOffset.
   15890                 :  */
   15891                 : opt_frame_clause:
   15892                 :             RANGE frame_extent opt_window_exclusion_clause
   15893                 :                 {
   15894 CBC         320 :                     WindowDef  *n = $2;
   15895 ECB             : 
   15896 GIC         320 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   15897             320 :                     n->frameOptions |= $3;
   15898             320 :                     $$ = n;
   15899                 :                 }
   15900                 :             | ROWS frame_extent opt_window_exclusion_clause
   15901                 :                 {
   15902             285 :                     WindowDef  *n = $2;
   15903 ECB             : 
   15904 GIC         285 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   15905 CBC         285 :                     n->frameOptions |= $3;
   15906             285 :                     $$ = n;
   15907 ECB             :                 }
   15908                 :             | GROUPS frame_extent opt_window_exclusion_clause
   15909                 :                 {
   15910 GIC         102 :                     WindowDef  *n = $2;
   15911                 : 
   15912             102 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   15913             102 :                     n->frameOptions |= $3;
   15914             102 :                     $$ = n;
   15915                 :                 }
   15916                 :             | /*EMPTY*/
   15917                 :                 {
   15918 CBC         907 :                     WindowDef  *n = makeNode(WindowDef);
   15919                 : 
   15920             907 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   15921             907 :                     n->startOffset = NULL;
   15922             907 :                     n->endOffset = NULL;
   15923             907 :                     $$ = n;
   15924 ECB             :                 }
   15925                 :         ;
   15926                 : 
   15927                 : frame_extent: frame_bound
   15928                 :                 {
   15929 GIC           3 :                     WindowDef  *n = $1;
   15930                 : 
   15931 ECB             :                     /* reject invalid cases */
   15932 GIC           3 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   15933 LBC           0 :                         ereport(ERROR,
   15934 ECB             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   15935                 :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   15936                 :                                  parser_errposition(@1)));
   15937 CBC           3 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   15938 UIC           0 :                         ereport(ERROR,
   15939                 :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   15940                 :                                  errmsg("frame starting from following row cannot end with current row"),
   15941                 :                                  parser_errposition(@1)));
   15942 GIC           3 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   15943               3 :                     $$ = n;
   15944                 :                 }
   15945 ECB             :             | BETWEEN frame_bound AND frame_bound
   15946                 :                 {
   15947 CBC         704 :                     WindowDef  *n1 = $2;
   15948 GIC         704 :                     WindowDef  *n2 = $4;
   15949                 : 
   15950                 :                     /* form merged options */
   15951 CBC         704 :                     int     frameOptions = n1->frameOptions;
   15952                 :                     /* shift converts START_ options to END_ options */
   15953             704 :                     frameOptions |= n2->frameOptions << 1;
   15954 GIC         704 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   15955 ECB             :                     /* reject invalid cases */
   15956 GIC         704 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   15957 LBC           0 :                         ereport(ERROR,
   15958                 :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   15959                 :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   15960 ECB             :                                  parser_errposition(@2)));
   15961 GIC         704 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   15962 UIC           0 :                         ereport(ERROR,
   15963 ECB             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   15964                 :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   15965                 :                                  parser_errposition(@4)));
   15966 GIC         704 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   15967             218 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   15968 UIC           0 :                         ereport(ERROR,
   15969 ECB             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   15970                 :                                  errmsg("frame starting from current row cannot have preceding rows"),
   15971                 :                                  parser_errposition(@4)));
   15972 CBC         704 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   15973              54 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   15974                 :                                          FRAMEOPTION_END_CURRENT_ROW)))
   15975 UIC           0 :                         ereport(ERROR,
   15976                 :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   15977 ECB             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   15978                 :                                  parser_errposition(@4)));
   15979 CBC         704 :                     n1->frameOptions = frameOptions;
   15980             704 :                     n1->endOffset = n2->startOffset;
   15981             704 :                     $$ = n1;
   15982                 :                 }
   15983                 :         ;
   15984                 : 
   15985 ECB             : /*
   15986                 :  * This is used for both frame start and frame end, with output set up on
   15987                 :  * the assumption it's frame start; the frame_extent productions must reject
   15988                 :  * invalid cases.
   15989                 :  */
   15990                 : frame_bound:
   15991                 :             UNBOUNDED PRECEDING
   15992                 :                 {
   15993 GIC          90 :                     WindowDef  *n = makeNode(WindowDef);
   15994 EUB             : 
   15995 CBC          90 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   15996              90 :                     n->startOffset = NULL;
   15997 GIC          90 :                     n->endOffset = NULL;
   15998              90 :                     $$ = n;
   15999                 :                 }
   16000                 :             | UNBOUNDED FOLLOWING
   16001                 :                 {
   16002             182 :                     WindowDef  *n = makeNode(WindowDef);
   16003 ECB             : 
   16004 GIC         182 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16005             182 :                     n->startOffset = NULL;
   16006             182 :                     n->endOffset = NULL;
   16007 GBC         182 :                     $$ = n;
   16008                 :                 }
   16009                 :             | CURRENT_P ROW
   16010                 :                 {
   16011 CBC         284 :                     WindowDef  *n = makeNode(WindowDef);
   16012                 : 
   16013 GIC         284 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16014             284 :                     n->startOffset = NULL;
   16015 CBC         284 :                     n->endOffset = NULL;
   16016 GIC         284 :                     $$ = n;
   16017                 :                 }
   16018                 :             | a_expr PRECEDING
   16019                 :                 {
   16020             384 :                     WindowDef  *n = makeNode(WindowDef);
   16021                 : 
   16022             384 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16023             384 :                     n->startOffset = $1;
   16024             384 :                     n->endOffset = NULL;
   16025             384 :                     $$ = n;
   16026                 :                 }
   16027                 :             | a_expr FOLLOWING
   16028                 :                 {
   16029 CBC         471 :                     WindowDef  *n = makeNode(WindowDef);
   16030 ECB             : 
   16031 GIC         471 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16032             471 :                     n->startOffset = $1;
   16033             471 :                     n->endOffset = NULL;
   16034 CBC         471 :                     $$ = n;
   16035 ECB             :                 }
   16036                 :         ;
   16037                 : 
   16038                 : opt_window_exclusion_clause:
   16039 GIC          42 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16040              48 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16041              75 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16042               9 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16043 CBC         533 :             | /*EMPTY*/             { $$ = 0; }
   16044 ECB             :         ;
   16045                 : 
   16046                 : 
   16047                 : /*
   16048                 :  * Supporting nonterminals for expressions.
   16049                 :  */
   16050                 : 
   16051                 : /* Explicit row production.
   16052                 :  *
   16053                 :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   16054                 :  * without conflicting with the parenthesized a_expr production.  Without the
   16055                 :  * ROW keyword, there must be more than one a_expr inside the parens.
   16056                 :  */
   16057 UIC           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   16058 LBC           0 :             | ROW '(' ')'                           { $$ = NIL; }
   16059 CBC        5556 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   16060                 :         ;
   16061                 : 
   16062 GIC        1817 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   16063              15 :             | ROW '(' ')'                           { $$ = NIL; }
   16064 ECB             :         ;
   16065                 : 
   16066 GIC        3959 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   16067 ECB             :         ;
   16068                 : 
   16069 CBC        7541 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   16070 LBC           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   16071 CBC         162 :             | ALL                                   { $$ = ALL_SUBLINK; }
   16072 ECB             :         ;
   16073                 : 
   16074 CBC        4512 : all_Op:     Op                                      { $$ = $1; }
   16075           12692 :             | MathOp                                { $$ = $1; }
   16076 ECB             :         ;
   16077                 : 
   16078 GIC         325 : MathOp:      '+'                                    { $$ = "+"; }
   16079             329 :             | '-'                                   { $$ = "-"; }
   16080 CBC           6 :             | '*'                                   { $$ = "*"; }
   16081 UIC           0 :             | '/'                                   { $$ = "/"; }
   16082 GIC           4 :             | '%'                                   { $$ = "%"; }
   16083 UIC           0 :             | '^'                                   { $$ = "^"; }
   16084 GIC         367 :             | '<'                                    { $$ = "<"; }
   16085             288 :             | '>'                                    { $$ = ">"; }
   16086 CBC       10562 :             | '='                                   { $$ = "="; }
   16087 GIC         299 :             | LESS_EQUALS                           { $$ = "<="; }
   16088 CBC         295 :             | GREATER_EQUALS                        { $$ = ">="; }
   16089             217 :             | NOT_EQUALS                            { $$ = "<>"; }
   16090 ECB             :         ;
   16091                 : 
   16092                 : qual_Op:    Op
   16093 CBC       34422 :                     { $$ = list_make1(makeString($1)); }
   16094 ECB             :             | OPERATOR '(' any_operator ')'
   16095 CBC        6543 :                     { $$ = $3; }
   16096 ECB             :         ;
   16097                 : 
   16098                 : qual_all_Op:
   16099                 :             all_Op
   16100 GIC         677 :                     { $$ = list_make1(makeString($1)); }
   16101                 :             | OPERATOR '(' any_operator ')'
   16102              17 :                     { $$ = $3; }
   16103                 :         ;
   16104                 : 
   16105                 : subquery_Op:
   16106                 :             all_Op
   16107            7607 :                     { $$ = list_make1(makeString($1)); }
   16108                 :             | OPERATOR '(' any_operator ')'
   16109              79 :                     { $$ = $3; }
   16110                 :             | LIKE
   16111 CBC          12 :                     { $$ = list_make1(makeString("~~")); }
   16112 ECB             :             | NOT_LA LIKE
   16113 GIC           6 :                     { $$ = list_make1(makeString("!~~")); }
   16114                 :             | ILIKE
   16115 CBC           6 :                     { $$ = list_make1(makeString("~~*")); }
   16116 ECB             :             | NOT_LA ILIKE
   16117 UIC           0 :                     { $$ = list_make1(makeString("!~~*")); }
   16118                 : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   16119                 :  * the regular expression is preprocessed by a function (similar_to_escape),
   16120                 :  * and the ~ operator for posix regular expressions is used.
   16121                 :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   16122                 :  * this transformation is made on the fly by the parser upwards.
   16123                 :  * however the SubLink structure which handles any/some/all stuff
   16124                 :  * is not ready for such a thing.
   16125                 :  */
   16126 ECB             :             ;
   16127                 : 
   16128                 : expr_list:  a_expr
   16129                 :                 {
   16130 CBC      185898 :                     $$ = list_make1($1);
   16131                 :                 }
   16132                 :             | expr_list ',' a_expr
   16133                 :                 {
   16134          146500 :                     $$ = lappend($1, $3);
   16135                 :                 }
   16136 ECB             :         ;
   16137                 : 
   16138                 : /* function arguments can have names */
   16139                 : func_arg_list:  func_arg_expr
   16140                 :                 {
   16141 GIC      243399 :                     $$ = list_make1($1);
   16142 ECB             :                 }
   16143                 :             | func_arg_list ',' func_arg_expr
   16144                 :                 {
   16145 CBC      152330 :                     $$ = lappend($1, $3);
   16146 ECB             :                 }
   16147                 :         ;
   16148                 : 
   16149                 : func_arg_expr:  a_expr
   16150                 :                 {
   16151 GIC      378711 :                     $$ = $1;
   16152 ECB             :                 }
   16153                 :             | param_name COLON_EQUALS a_expr
   16154                 :                 {
   16155 CBC       16951 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16156                 : 
   16157 GIC       16951 :                     na->name = $1;
   16158           16951 :                     na->arg = (Expr *) $3;
   16159           16951 :                     na->argnumber = -1;      /* until determined */
   16160           16951 :                     na->location = @1;
   16161 CBC       16951 :                     $$ = (Node *) na;
   16162                 :                 }
   16163                 :             | param_name EQUALS_GREATER a_expr
   16164 ECB             :                 {
   16165 GBC         396 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   16166                 : 
   16167 GIC         396 :                     na->name = $1;
   16168             396 :                     na->arg = (Expr *) $3;
   16169 CBC         396 :                     na->argnumber = -1;      /* until determined */
   16170 GBC         396 :                     na->location = @1;
   16171 GIC         396 :                     $$ = (Node *) na;
   16172                 :                 }
   16173                 :         ;
   16174 ECB             : 
   16175 CBC         359 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   16176 UIC           0 :             | /*EMPTY*/                             { $$ = NIL; }
   16177                 :         ;
   16178                 : 
   16179 CBC         799 : type_list:  Typename                                { $$ = list_make1($1); }
   16180             165 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   16181                 :         ;
   16182                 : 
   16183 ECB             : array_expr: '[' expr_list ']'
   16184                 :                 {
   16185 CBC        3533 :                     $$ = makeAArrayExpr($2, @1);
   16186 ECB             :                 }
   16187                 :             | '[' array_expr_list ']'
   16188                 :                 {
   16189 GBC         203 :                     $$ = makeAArrayExpr($2, @1);
   16190                 :                 }
   16191                 :             | '[' ']'
   16192                 :                 {
   16193 CBC          44 :                     $$ = makeAArrayExpr(NIL, @1);
   16194 EUB             :                 }
   16195                 :         ;
   16196                 : 
   16197 GIC         203 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   16198 CBC         165 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   16199 ECB             :         ;
   16200 EUB             : 
   16201                 : 
   16202                 : extract_list:
   16203                 :             extract_arg FROM a_expr
   16204 ECB             :                 {
   16205 CBC        1636 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   16206                 :                 }
   16207 EUB             :         ;
   16208                 : 
   16209                 : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   16210                 :  * - thomas 2001-04-12
   16211 ECB             :  */
   16212                 : extract_arg:
   16213 CBC        1531 :             IDENT                                   { $$ = $1; }
   16214 GIC          27 :             | YEAR_P                                { $$ = "year"; }
   16215              18 :             | MONTH_P                               { $$ = "month"; }
   16216              24 :             | DAY_P                                 { $$ = "day"; }
   16217              12 :             | HOUR_P                                { $$ = "hour"; }
   16218              12 :             | MINUTE_P                              { $$ = "minute"; }
   16219              12 :             | SECOND_P                              { $$ = "second"; }
   16220 UIC           0 :             | Sconst                                { $$ = $1; }
   16221                 :         ;
   16222                 : 
   16223                 : unicode_normal_form:
   16224 GIC          12 :             NFC                                     { $$ = "NFC"; }
   16225 CBC           6 :             | NFD                                   { $$ = "NFD"; }
   16226 GIC           9 :             | NFKC                                  { $$ = "NFKC"; }
   16227 CBC           9 :             | NFKD                                  { $$ = "NFKD"; }
   16228 ECB             :         ;
   16229                 : 
   16230                 : /* OVERLAY() arguments */
   16231                 : overlay_list:
   16232                 :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   16233                 :                 {
   16234                 :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   16235 GIC          17 :                     $$ = list_make4($1, $3, $5, $7);
   16236 ECB             :                 }
   16237                 :             | a_expr PLACING a_expr FROM a_expr
   16238                 :                 {
   16239                 :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   16240 GIC          24 :                     $$ = list_make3($1, $3, $5);
   16241                 :                 }
   16242                 :         ;
   16243 ECB             : 
   16244                 : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   16245                 : position_list:
   16246 CBC         440 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   16247 ECB             :         ;
   16248                 : 
   16249                 : /*
   16250                 :  * SUBSTRING() arguments
   16251                 :  *
   16252                 :  * Note that SQL:1999 has both
   16253                 :  *     text FROM int FOR int
   16254                 :  * and
   16255                 :  *     text FROM pattern FOR escape
   16256                 :  *
   16257                 :  * In the parser we map them both to a call to the substring() function and
   16258                 :  * rely on type resolution to pick the right one.
   16259                 :  *
   16260                 :  * In SQL:2003, the second variant was changed to
   16261                 :  *     text SIMILAR pattern ESCAPE escape
   16262                 :  * We could in theory map that to a different function internally, but
   16263                 :  * since we still support the SQL:1999 version, we don't.  However,
   16264                 :  * ruleutils.c will reverse-list the call in the newer style.
   16265                 :  */
   16266                 : substr_list:
   16267                 :             a_expr FROM a_expr FOR a_expr
   16268                 :                 {
   16269 GIC          61 :                     $$ = list_make3($1, $3, $5);
   16270                 :                 }
   16271 ECB             :             | a_expr FOR a_expr FROM a_expr
   16272                 :                 {
   16273                 :                     /* not legal per SQL, but might as well allow it */
   16274 LBC           0 :                     $$ = list_make3($1, $5, $3);
   16275 ECB             :                 }
   16276                 :             | a_expr FROM a_expr
   16277                 :                 {
   16278                 :                     /*
   16279                 :                      * Because we aren't restricting data types here, this
   16280                 :                      * syntax can end up resolving to textregexsubstr().
   16281                 :                      * We've historically allowed that to happen, so continue
   16282                 :                      * to accept it.  However, ruleutils.c will reverse-list
   16283                 :                      * such a call in regular function call syntax.
   16284                 :                      */
   16285 GIC        1253 :                     $$ = list_make2($1, $3);
   16286                 :                 }
   16287                 :             | a_expr FOR a_expr
   16288                 :                 {
   16289 EUB             :                     /* not legal per SQL */
   16290                 : 
   16291 ECB             :                     /*
   16292                 :                      * Since there are no cases where this syntax allows
   16293                 :                      * a textual FOR value, we forcibly cast the argument
   16294                 :                      * to int4.  The possible matches in pg_proc are
   16295                 :                      * substring(text,int4) and substring(text,text),
   16296                 :                      * and we don't want the parser to choose the latter,
   16297                 :                      * which it is likely to do if the second argument
   16298                 :                      * is unknown or doesn't have an implicit cast to int4.
   16299                 :                      */
   16300 GIC          18 :                     $$ = list_make3($1, makeIntConst(1, -1),
   16301 ECB             :                                     makeTypeCast($3,
   16302 EUB             :                                                  SystemTypeName("int4"), -1));
   16303 ECB             :                 }
   16304                 :             | a_expr SIMILAR a_expr ESCAPE a_expr
   16305                 :                 {
   16306 CBC         346 :                     $$ = list_make3($1, $3, $5);
   16307 ECB             :                 }
   16308                 :         ;
   16309                 : 
   16310 CBC         542 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   16311              12 :             | FROM expr_list                        { $$ = $2; }
   16312              43 :             | expr_list                             { $$ = $1; }
   16313 EUB             :         ;
   16314 ECB             : 
   16315 EUB             : in_expr:    select_with_parens
   16316 ECB             :                 {
   16317 CBC        3996 :                     SubLink    *n = makeNode(SubLink);
   16318 ECB             : 
   16319 CBC        3996 :                     n->subselect = $1;
   16320 ECB             :                     /* other fields will be filled later */
   16321 CBC        3996 :                     $$ = (Node *) n;
   16322                 :                 }
   16323 GIC       28882 :             | '(' expr_list ')'                     { $$ = (Node *) $2; }
   16324                 :         ;
   16325 ECB             : 
   16326                 : /*
   16327                 :  * Define SQL-style CASE clause.
   16328                 :  * - Full specification
   16329                 :  *  CASE WHEN a = b THEN c ... ELSE d END
   16330                 :  * - Implicit argument
   16331                 :  *  CASE a WHEN b THEN c ... ELSE d END
   16332                 :  */
   16333                 : case_expr:  CASE case_arg when_clause_list case_default END_P
   16334                 :                 {
   16335 GIC       50079 :                     CaseExpr   *c = makeNode(CaseExpr);
   16336                 : 
   16337           50079 :                     c->casetype = InvalidOid; /* not analyzed yet */
   16338           50079 :                     c->arg = (Expr *) $2;
   16339 CBC       50079 :                     c->args = $3;
   16340 GIC       50079 :                     c->defresult = (Expr *) $4;
   16341 CBC       50079 :                     c->location = @1;
   16342 GIC       50079 :                     $$ = (Node *) c;
   16343 ECB             :                 }
   16344                 :         ;
   16345                 : 
   16346                 : when_clause_list:
   16347                 :             /* There must be at least one */
   16348 GIC       50079 :             when_clause                             { $$ = list_make1($1); }
   16349 GBC       51599 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   16350                 :         ;
   16351                 : 
   16352                 : when_clause:
   16353                 :             WHEN a_expr THEN a_expr
   16354                 :                 {
   16355 GIC      101678 :                     CaseWhen   *w = makeNode(CaseWhen);
   16356                 : 
   16357          101678 :                     w->expr = (Expr *) $2;
   16358          101678 :                     w->result = (Expr *) $4;
   16359          101678 :                     w->location = @1;
   16360          101678 :                     $$ = (Node *) w;
   16361                 :                 }
   16362 ECB             :         ;
   16363                 : 
   16364                 : case_default:
   16365 GIC       35158 :             ELSE a_expr                             { $$ = $2; }
   16366 CBC       14921 :             | /*EMPTY*/                             { $$ = NULL; }
   16367                 :         ;
   16368                 : 
   16369 GIC        8589 : case_arg:   a_expr                                  { $$ = $1; }
   16370           41490 :             | /*EMPTY*/                             { $$ = NULL; }
   16371                 :         ;
   16372                 : 
   16373 ECB             : columnref:  ColId
   16374                 :                 {
   16375 GIC      403292 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   16376                 :                 }
   16377 ECB             :             | ColId indirection
   16378                 :                 {
   16379 GIC      954809 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   16380                 :                 }
   16381                 :         ;
   16382                 : 
   16383 ECB             : indirection_el:
   16384                 :             '.' attr_name
   16385                 :                 {
   16386 GIC     1117706 :                     $$ = (Node *) makeString($2);
   16387 ECB             :                 }
   16388                 :             | '.' '*'
   16389                 :                 {
   16390 CBC        5082 :                     $$ = (Node *) makeNode(A_Star);
   16391 ECB             :                 }
   16392                 :             | '[' a_expr ']'
   16393                 :                 {
   16394 GIC        9644 :                     A_Indices *ai = makeNode(A_Indices);
   16395                 : 
   16396            9644 :                     ai->is_slice = false;
   16397 CBC        9644 :                     ai->lidx = NULL;
   16398 GIC        9644 :                     ai->uidx = $2;
   16399 CBC        9644 :                     $$ = (Node *) ai;
   16400 ECB             :                 }
   16401                 :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   16402                 :                 {
   16403 CBC         276 :                     A_Indices *ai = makeNode(A_Indices);
   16404                 : 
   16405 GIC         276 :                     ai->is_slice = true;
   16406             276 :                     ai->lidx = $2;
   16407 CBC         276 :                     ai->uidx = $4;
   16408 GBC         276 :                     $$ = (Node *) ai;
   16409                 :                 }
   16410                 :         ;
   16411 ECB             : 
   16412                 : opt_slice_bound:
   16413 GIC         462 :             a_expr                                  { $$ = $1; }
   16414              90 :             | /*EMPTY*/                             { $$ = NULL; }
   16415                 :         ;
   16416                 : 
   16417 ECB             : indirection:
   16418 GIC     1092203 :             indirection_el                          { $$ = list_make1($1); }
   16419            1013 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   16420                 :         ;
   16421 ECB             : 
   16422                 : opt_indirection:
   16423 GIC      279470 :             /*EMPTY*/                               { $$ = NIL; }
   16424           39492 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   16425 ECB             :         ;
   16426                 : 
   16427                 : opt_asymmetric: ASYMMETRIC
   16428                 :             | /*EMPTY*/
   16429                 :         ;
   16430                 : 
   16431                 : /* SQL/JSON support */
   16432                 : json_value_expr:
   16433                 :             a_expr json_format_clause_opt
   16434                 :             {
   16435 GNC         499 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, castNode(JsonFormat, $2));
   16436                 :             }
   16437                 :         ;
   16438                 : 
   16439                 : json_format_clause_opt:
   16440                 :             FORMAT_LA JSON json_encoding_clause_opt
   16441                 :                 {
   16442             116 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, $3, @1);
   16443                 :                 }
   16444                 :             | /* EMPTY */
   16445                 :                 {
   16446             631 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   16447                 :                 }
   16448                 :         ;
   16449                 : 
   16450                 : json_encoding_clause_opt:
   16451              39 :             ENCODING name                   { $$ = makeJsonEncoding($2); }
   16452              83 :             | /* EMPTY */                   { $$ = JS_ENC_DEFAULT; }
   16453                 :         ;
   16454                 : 
   16455                 : json_output_clause_opt:
   16456                 :             RETURNING Typename json_format_clause_opt
   16457                 :                 {
   16458             221 :                     JsonOutput *n = makeNode(JsonOutput);
   16459                 : 
   16460             221 :                     n->typeName = $2;
   16461             221 :                     n->returning = makeNode(JsonReturning);
   16462             221 :                     n->returning->format = (JsonFormat *) $3;
   16463             221 :                     $$ = (Node *) n;
   16464                 :                 }
   16465             212 :             | /* EMPTY */                           { $$ = NULL; }
   16466                 :         ;
   16467                 : 
   16468                 : json_predicate_type_constraint:
   16469              94 :             JSON                                    { $$ = JS_TYPE_ANY; }
   16470              13 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   16471              19 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   16472              19 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   16473              19 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   16474                 :         ;
   16475                 : 
   16476                 : /* KEYS is a noise word here */
   16477                 : json_key_uniqueness_constraint_opt:
   16478              28 :             WITH UNIQUE KEYS                            { $$ = true; }
   16479              40 :             | WITH UNIQUE                               { $$ = true; }
   16480              14 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   16481               7 :             | WITHOUT UNIQUE                            { $$ = false; }
   16482             276 :             | /* EMPTY */               %prec KEYS      { $$ = false; }
   16483                 :         ;
   16484                 : 
   16485                 : json_name_and_value_list:
   16486                 :             json_name_and_value
   16487             141 :                 { $$ = list_make1($1); }
   16488                 :             | json_name_and_value_list ',' json_name_and_value
   16489             112 :                 { $$ = lappend($1, $3); }
   16490                 :         ;
   16491                 : 
   16492                 : json_name_and_value:
   16493                 : /* Supporting this syntax seems to require major surgery
   16494                 :             KEY c_expr VALUE_P json_value_expr
   16495                 :                 { $$ = makeJsonKeyValue($2, $4); }
   16496                 :             |
   16497                 : */
   16498                 :             c_expr VALUE_P json_value_expr
   16499              12 :                 { $$ = makeJsonKeyValue($1, $3); }
   16500                 :             |
   16501                 :             a_expr ':' json_value_expr
   16502             301 :                 { $$ = makeJsonKeyValue($1, $3); }
   16503                 :         ;
   16504                 : 
   16505                 : /* empty means false for objects, true for arrays */
   16506                 : json_object_constructor_null_clause_opt:
   16507              15 :             NULL_P ON NULL_P                    { $$ = false; }
   16508              41 :             | ABSENT ON NULL_P                  { $$ = true; }
   16509             145 :             | /* EMPTY */                       { $$ = false; }
   16510                 :         ;
   16511                 : 
   16512                 : json_array_constructor_null_clause_opt:
   16513              27 :             NULL_P ON NULL_P                        { $$ = false; }
   16514              18 :             | ABSENT ON NULL_P                      { $$ = true; }
   16515              78 :             | /* EMPTY */                           { $$ = true; }
   16516                 :         ;
   16517                 : 
   16518                 : json_value_expr_list:
   16519              48 :             json_value_expr                             { $$ = list_make1($1); }
   16520              63 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   16521                 :         ;
   16522                 : 
   16523                 : json_aggregate_func:
   16524                 :             JSON_OBJECTAGG '('
   16525                 :                 json_name_and_value
   16526                 :                 json_object_constructor_null_clause_opt
   16527                 :                 json_key_uniqueness_constraint_opt
   16528                 :                 json_output_clause_opt
   16529                 :             ')'
   16530                 :                 {
   16531              60 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   16532                 : 
   16533              60 :                     n->arg = (JsonKeyValue *) $3;
   16534              60 :                     n->absent_on_null = $4;
   16535              60 :                     n->unique = $5;
   16536              60 :                     n->constructor = makeNode(JsonAggConstructor);
   16537              60 :                     n->constructor->output = (JsonOutput *) $6;
   16538              60 :                     n->constructor->agg_order = NULL;
   16539              60 :                     n->constructor->location = @1;
   16540              60 :                     $$ = (Node *) n;
   16541                 :                 }
   16542                 :             | JSON_ARRAYAGG '('
   16543                 :                 json_value_expr
   16544                 :                 json_array_aggregate_order_by_clause_opt
   16545                 :                 json_array_constructor_null_clause_opt
   16546                 :                 json_output_clause_opt
   16547                 :             ')'
   16548                 :                 {
   16549              75 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   16550                 : 
   16551              75 :                     n->arg = (JsonValueExpr *) $3;
   16552              75 :                     n->absent_on_null = $5;
   16553              75 :                     n->constructor = makeNode(JsonAggConstructor);
   16554              75 :                     n->constructor->agg_order = $4;
   16555              75 :                     n->constructor->output = (JsonOutput *) $6;
   16556              75 :                     n->constructor->location = @1;
   16557              75 :                     $$ = (Node *) n;
   16558                 :                 }
   16559                 :         ;
   16560                 : 
   16561                 : json_array_aggregate_order_by_clause_opt:
   16562               9 :             ORDER BY sortby_list                    { $$ = $3; }
   16563              66 :             | /* EMPTY */                           { $$ = NIL; }
   16564                 :         ;
   16565                 : 
   16566                 : /*****************************************************************************
   16567                 :  *
   16568                 :  *  target list for SELECT
   16569                 :  *
   16570                 :  *****************************************************************************/
   16571 ECB             : 
   16572 GIC      264318 : opt_target_list: target_list                        { $$ = $1; }
   16573             153 :             | /* EMPTY */                           { $$ = NIL; }
   16574                 :         ;
   16575                 : 
   16576                 : target_list:
   16577          269549 :             target_el                               { $$ = list_make1($1); }
   16578          603288 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   16579 ECB             :         ;
   16580                 : 
   16581                 : target_el:  a_expr AS ColLabel
   16582                 :                 {
   16583 CBC      362409 :                     $$ = makeNode(ResTarget);
   16584          362409 :                     $$->name = $3;
   16585          362409 :                     $$->indirection = NIL;
   16586 GBC      362409 :                     $$->val = (Node *) $1;
   16587 GIC      362409 :                     $$->location = @1;
   16588                 :                 }
   16589                 :             | a_expr BareColLabel
   16590 ECB             :                 {
   16591 CBC        1690 :                     $$ = makeNode(ResTarget);
   16592            1690 :                     $$->name = $2;
   16593            1690 :                     $$->indirection = NIL;
   16594 GIC        1690 :                     $$->val = (Node *) $1;
   16595            1690 :                     $$->location = @1;
   16596                 :                 }
   16597                 :             | a_expr
   16598                 :                 {
   16599          478576 :                     $$ = makeNode(ResTarget);
   16600          478576 :                     $$->name = NULL;
   16601 CBC      478576 :                     $$->indirection = NIL;
   16602 GIC      478576 :                     $$->val = (Node *) $1;
   16603          478576 :                     $$->location = @1;
   16604                 :                 }
   16605                 :             | '*'
   16606 ECB             :                 {
   16607 GIC       30162 :                     ColumnRef  *n = makeNode(ColumnRef);
   16608                 : 
   16609           30162 :                     n->fields = list_make1(makeNode(A_Star));
   16610           30162 :                     n->location = @1;
   16611                 : 
   16612 CBC       30162 :                     $$ = makeNode(ResTarget);
   16613 GIC       30162 :                     $$->name = NULL;
   16614           30162 :                     $$->indirection = NIL;
   16615           30162 :                     $$->val = (Node *) n;
   16616           30162 :                     $$->location = @1;
   16617                 :                 }
   16618                 :         ;
   16619                 : 
   16620                 : 
   16621                 : /*****************************************************************************
   16622                 :  *
   16623                 :  *  Names and constants
   16624                 :  *
   16625                 :  *****************************************************************************/
   16626                 : 
   16627                 : qualified_name_list:
   16628           27362 :             qualified_name                          { $$ = list_make1($1); }
   16629             145 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   16630                 :         ;
   16631                 : 
   16632                 : /*
   16633                 :  * The production for a qualified relation name has to exactly match the
   16634                 :  * production for a qualified func_name, because in a FROM clause we cannot
   16635 ECB             :  * tell which we are parsing until we see what comes after it ('(' for a
   16636                 :  * func_name, something else for a relation). Therefore we allow 'indirection'
   16637                 :  * which may contain subscripts, and reject that case in the C code.
   16638                 :  */
   16639                 : qualified_name:
   16640 EUB             :             ColId
   16641                 :                 {
   16642 GIC      398845 :                     $$ = makeRangeVar(NULL, $1, @1);
   16643                 :                 }
   16644                 :             | ColId indirection
   16645                 :                 {
   16646           90679 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   16647                 :                 }
   16648                 :         ;
   16649                 : 
   16650                 : name_list:  name
   16651 CBC       40132 :                     { $$ = list_make1(makeString($1)); }
   16652                 :             | name_list ',' name
   16653 GIC      164514 :                     { $$ = lappend($1, makeString($3)); }
   16654                 :         ;
   16655                 : 
   16656                 : 
   16657          269473 : name:       ColId                                   { $$ = $1; };
   16658                 : 
   16659         1153050 : attr_name:  ColLabel                                { $$ = $1; };
   16660                 : 
   16661              26 : file_name:  Sconst                                  { $$ = $1; };
   16662                 : 
   16663                 : /*
   16664                 :  * The production for a qualified func_name has to exactly match the
   16665                 :  * production for a qualified columnref, because we cannot tell which we
   16666 ECB             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   16667                 :  * anything else for a columnref).  Therefore we allow 'indirection' which
   16668                 :  * may contain subscripts, and reject that case in the C code.  (If we
   16669                 :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   16670                 :  */
   16671                 : func_name:  type_function_name
   16672 CBC      330711 :                     { $$ = list_make1(makeString($1)); }
   16673                 :             | ColId indirection
   16674                 :                     {
   16675 GIC       46679 :                         $$ = check_func_name(lcons(makeString($1), $2),
   16676 ECB             :                                              yyscanner);
   16677                 :                     }
   16678                 :         ;
   16679                 : 
   16680                 : 
   16681                 : /*
   16682                 :  * Constants
   16683                 :  */
   16684                 : AexprConst: Iconst
   16685                 :                 {
   16686 GIC      263091 :                     $$ = makeIntConst($1, @1);
   16687 ECB             :                 }
   16688                 :             | FCONST
   16689                 :                 {
   16690 GIC        5276 :                     $$ = makeFloatConst($1, @1);
   16691                 :                 }
   16692                 :             | Sconst
   16693                 :                 {
   16694          479676 :                     $$ = makeStringConst($1, @1);
   16695                 :                 }
   16696                 :             | BCONST
   16697                 :                 {
   16698             370 :                     $$ = makeBitStringConst($1, @1);
   16699                 :                 }
   16700                 :             | XCONST
   16701 ECB             :                 {
   16702                 :                     /* This is a bit constant per SQL99:
   16703                 :                      * Without Feature F511, "BIT data type",
   16704                 :                      * a <general literal> shall not be a
   16705                 :                      * <bit string literal> or a <hex string literal>.
   16706                 :                      */
   16707 CBC        1653 :                     $$ = makeBitStringConst($1, @1);
   16708 ECB             :                 }
   16709                 :             | func_name Sconst
   16710                 :                 {
   16711                 :                     /* generic type 'literal' syntax */
   16712 GIC        3848 :                     TypeName   *t = makeTypeNameFromNameList($1);
   16713                 : 
   16714 CBC        3848 :                     t->location = @1;
   16715            3848 :                     $$ = makeStringConstCast($2, @2, t);
   16716                 :                 }
   16717                 :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   16718                 :                 {
   16719                 :                     /* generic syntax with a type modifier */
   16720 UIC           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   16721 ECB             :                     ListCell   *lc;
   16722                 : 
   16723                 :                     /*
   16724                 :                      * We must use func_arg_list and opt_sort_clause in the
   16725                 :                      * production to avoid reduce/reduce conflicts, but we
   16726                 :                      * don't actually wish to allow NamedArgExpr in this
   16727                 :                      * context, nor ORDER BY.
   16728                 :                      */
   16729 UIC           0 :                     foreach(lc, $3)
   16730                 :                     {
   16731 LBC           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   16732 ECB             : 
   16733 UIC           0 :                         if (IsA(arg, NamedArgExpr))
   16734               0 :                             ereport(ERROR,
   16735 ECB             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   16736                 :                                      errmsg("type modifier cannot have parameter name"),
   16737                 :                                      parser_errposition(arg->location)));
   16738                 :                     }
   16739 UIC           0 :                     if ($4 != NIL)
   16740               0 :                             ereport(ERROR,
   16741 ECB             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   16742                 :                                      errmsg("type modifier cannot have ORDER BY"),
   16743                 :                                      parser_errposition(@4)));
   16744                 : 
   16745 LBC           0 :                     t->typmods = $3;
   16746 UIC           0 :                     t->location = @1;
   16747               0 :                     $$ = makeStringConstCast($6, @6, t);
   16748                 :                 }
   16749                 :             | ConstTypename Sconst
   16750                 :                 {
   16751 GIC        1139 :                     $$ = makeStringConstCast($2, @2, $1);
   16752 ECB             :                 }
   16753                 :             | ConstInterval Sconst opt_interval
   16754                 :                 {
   16755 GIC        1172 :                     TypeName   *t = $1;
   16756 ECB             : 
   16757 GIC        1172 :                     t->typmods = $3;
   16758            1172 :                     $$ = makeStringConstCast($2, @2, t);
   16759                 :                 }
   16760 ECB             :             | ConstInterval '(' Iconst ')' Sconst
   16761                 :                 {
   16762 CBC           6 :                     TypeName   *t = $1;
   16763 ECB             : 
   16764 CBC           6 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   16765 ECB             :                                             makeIntConst($3, @3));
   16766 GIC           6 :                     $$ = makeStringConstCast($5, @5, t);
   16767                 :                 }
   16768                 :             | TRUE_P
   16769 ECB             :                 {
   16770 GIC       10462 :                     $$ = makeBoolAConst(true, @1);
   16771 ECB             :                 }
   16772                 :             | FALSE_P
   16773                 :                 {
   16774 CBC       19065 :                     $$ = makeBoolAConst(false, @1);
   16775                 :                 }
   16776                 :             | NULL_P
   16777                 :                 {
   16778 GIC       96509 :                     $$ = makeNullAConst(@1);
   16779 ECB             :                 }
   16780                 :         ;
   16781                 : 
   16782 GIC      288122 : Iconst:     ICONST                                  { $$ = $1; };
   16783          536743 : Sconst:     SCONST                                  { $$ = $1; };
   16784 ECB             : 
   16785 CBC       20682 : SignedIconst: Iconst                                { $$ = $1; }
   16786 UIC           0 :             | '+' Iconst                            { $$ = + $2; }
   16787 GIC         133 :             | '-' Iconst                            { $$ = - $2; }
   16788                 :         ;
   16789 ECB             : 
   16790                 : /* Role specifications */
   16791                 : RoleId:     RoleSpec
   16792                 :                 {
   16793 GIC         834 :                     RoleSpec   *spc = (RoleSpec *) $1;
   16794                 : 
   16795             834 :                     switch (spc->roletype)
   16796                 :                     {
   16797             829 :                         case ROLESPEC_CSTRING:
   16798             829 :                             $$ = spc->rolename;
   16799             829 :                             break;
   16800               2 :                         case ROLESPEC_PUBLIC:
   16801 CBC           2 :                             ereport(ERROR,
   16802                 :                                     (errcode(ERRCODE_RESERVED_NAME),
   16803                 :                                      errmsg("role name \"%s\" is reserved",
   16804                 :                                             "public"),
   16805                 :                                      parser_errposition(@1)));
   16806                 :                             break;
   16807 GIC           1 :                         case ROLESPEC_SESSION_USER:
   16808 CBC           1 :                             ereport(ERROR,
   16809                 :                                     (errcode(ERRCODE_RESERVED_NAME),
   16810                 :                                      errmsg("%s cannot be used as a role name here",
   16811                 :                                             "SESSION_USER"),
   16812 ECB             :                                      parser_errposition(@1)));
   16813                 :                             break;
   16814 GIC           1 :                         case ROLESPEC_CURRENT_USER:
   16815               1 :                             ereport(ERROR,
   16816                 :                                     (errcode(ERRCODE_RESERVED_NAME),
   16817 ECB             :                                      errmsg("%s cannot be used as a role name here",
   16818                 :                                             "CURRENT_USER"),
   16819                 :                                      parser_errposition(@1)));
   16820                 :                             break;
   16821 GIC           1 :                         case ROLESPEC_CURRENT_ROLE:
   16822               1 :                             ereport(ERROR,
   16823                 :                                     (errcode(ERRCODE_RESERVED_NAME),
   16824 ECB             :                                      errmsg("%s cannot be used as a role name here",
   16825                 :                                             "CURRENT_ROLE"),
   16826                 :                                      parser_errposition(@1)));
   16827                 :                             break;
   16828                 :                     }
   16829                 :                 }
   16830                 :             ;
   16831                 : 
   16832                 : RoleSpec:   NonReservedWord
   16833                 :                 {
   16834                 :                     /*
   16835                 :                      * "public" and "none" are not keywords, but they must
   16836                 :                      * be treated specially here.
   16837                 :                      */
   16838                 :                     RoleSpec   *n;
   16839                 : 
   16840 GIC       54442 :                     if (strcmp($1, "public") == 0)
   16841                 :                     {
   16842           44129 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   16843           44129 :                         n->roletype = ROLESPEC_PUBLIC;
   16844 ECB             :                     }
   16845 CBC       10313 :                     else if (strcmp($1, "none") == 0)
   16846 ECB             :                     {
   16847 CBC          13 :                         ereport(ERROR,
   16848 ECB             :                                 (errcode(ERRCODE_RESERVED_NAME),
   16849                 :                                  errmsg("role name \"%s\" is reserved",
   16850                 :                                         "none"),
   16851                 :                                  parser_errposition(@1)));
   16852                 :                     }
   16853                 :                     else
   16854                 :                     {
   16855 CBC       10300 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   16856 GIC       10300 :                         n->rolename = pstrdup($1);
   16857                 :                     }
   16858           54429 :                     $$ = n;
   16859                 :                 }
   16860                 :             | CURRENT_ROLE
   16861                 :                 {
   16862              28 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   16863                 :                 }
   16864                 :             | CURRENT_USER
   16865 ECB             :                 {
   16866 GIC         102 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   16867                 :                 }
   16868 ECB             :             | SESSION_USER
   16869                 :                 {
   16870 GIC          18 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   16871                 :                 }
   16872                 :         ;
   16873 ECB             : 
   16874                 : role_list:  RoleSpec
   16875 CBC        2258 :                 { $$ = list_make1($1); }
   16876                 :             | role_list ',' RoleSpec
   16877 GIC         123 :                 { $$ = lappend($1, $3); }
   16878                 :         ;
   16879 ECB             : 
   16880                 : 
   16881                 : /*****************************************************************************
   16882                 :  *
   16883                 :  * PL/pgSQL extensions
   16884                 :  *
   16885                 :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   16886                 :  * historically it can include just about anything that can follow SELECT.
   16887                 :  * Therefore the returned struct is a SelectStmt.
   16888                 :  *****************************************************************************/
   16889                 : 
   16890                 : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   16891                 :             from_clause where_clause
   16892                 :             group_clause having_clause window_clause
   16893                 :             opt_sort_clause opt_select_limit opt_for_locking_clause
   16894                 :                 {
   16895 GIC       17582 :                     SelectStmt *n = makeNode(SelectStmt);
   16896                 : 
   16897 CBC       17582 :                     n->distinctClause = $1;
   16898 GIC       17582 :                     n->targetList = $2;
   16899 CBC       17582 :                     n->fromClause = $3;
   16900           17582 :                     n->whereClause = $4;
   16901           17582 :                     n->groupClause = ($5)->list;
   16902           17582 :                     n->groupDistinct = ($5)->distinct;
   16903           17582 :                     n->havingClause = $6;
   16904           17582 :                     n->windowClause = $7;
   16905           17582 :                     n->sortClause = $8;
   16906           17582 :                     if ($9)
   16907                 :                     {
   16908 GIC           2 :                         n->limitOffset = $9->limitOffset;
   16909               2 :                         n->limitCount = $9->limitCount;
   16910               2 :                         if (!n->sortClause &&
   16911               2 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   16912 UIC           0 :                             ereport(ERROR,
   16913                 :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   16914                 :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause")));
   16915 CBC           2 :                         n->limitOption = $9->limitOption;
   16916                 :                     }
   16917           17582 :                     n->lockingClause = $10;
   16918           17582 :                     $$ = (Node *) n;
   16919 ECB             :                 }
   16920                 :         ;
   16921                 : 
   16922                 : /*
   16923                 :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   16924                 :  */
   16925                 : 
   16926                 : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   16927                 :                 {
   16928 CBC        3251 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   16929 ECB             : 
   16930 GIC        3251 :                     n->name = $1;
   16931            3251 :                     n->indirection = check_indirection($2, yyscanner);
   16932                 :                     /* nnames will be filled by calling production */
   16933            3226 :                     n->val = (SelectStmt *) $4;
   16934            3226 :                     n->location = @1;
   16935            3226 :                     $$ = (Node *) n;
   16936                 :                 }
   16937                 :         ;
   16938 ECB             : 
   16939 CBC        3239 : plassign_target: ColId                          { $$ = $1; }
   16940 GIC          12 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   16941                 :         ;
   16942                 : 
   16943 ECB             : plassign_equals: COLON_EQUALS
   16944                 :             | '='
   16945                 :         ;
   16946                 : 
   16947                 : 
   16948                 : /*
   16949                 :  * Name classification hierarchy.
   16950                 :  *
   16951                 :  * IDENT is the lexeme returned by the lexer for identifiers that match
   16952                 :  * no known keyword.  In most cases, we can accept certain keywords as
   16953                 :  * names, not only IDENTs.  We prefer to accept as many such keywords
   16954                 :  * as possible to minimize the impact of "reserved words" on programmers.
   16955                 :  * So, we divide names into several possible classes.  The classification
   16956                 :  * is chosen in part to make keywords acceptable as names wherever possible.
   16957                 :  */
   16958                 : 
   16959                 : /* Column identifier --- names that can be column, table, etc names.
   16960                 :  */
   16961 CBC     2594178 : ColId:      IDENT                                   { $$ = $1; }
   16962 GIC       65792 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   16963           17502 :             | col_name_keyword                      { $$ = pstrdup($1); }
   16964                 :         ;
   16965 ECB             : 
   16966                 : /* Type/function identifier --- names that can be type or function names.
   16967                 :  */
   16968 CBC      780167 : type_function_name: IDENT                           { $$ = $1; }
   16969           71539 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   16970 GIC          21 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   16971                 :         ;
   16972                 : 
   16973 ECB             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   16974                 :  */
   16975 CBC       83574 : NonReservedWord:    IDENT                           { $$ = $1; }
   16976           26612 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   16977 GIC          11 :             | col_name_keyword                      { $$ = pstrdup($1); }
   16978 CBC        1318 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   16979 ECB             :         ;
   16980                 : 
   16981                 : /* Column label --- allowed labels in "AS" clauses.
   16982                 :  * This presently includes *all* Postgres keywords.
   16983                 :  */
   16984 GIC     1504091 : ColLabel:   IDENT                                   { $$ = $1; }
   16985           48765 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   16986             112 :             | col_name_keyword                      { $$ = pstrdup($1); }
   16987             855 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   16988            3246 :             | reserved_keyword                      { $$ = pstrdup($1); }
   16989                 :         ;
   16990                 : 
   16991                 : /* Bare column label --- names that can be column labels without writing "AS".
   16992                 :  * This classification is orthogonal to the other keyword categories.
   16993                 :  */
   16994 CBC        1687 : BareColLabel:   IDENT                               { $$ = $1; }
   16995               3 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   16996                 :         ;
   16997                 : 
   16998                 : 
   16999                 : /*
   17000                 :  * Keyword category lists.  Generally, every keyword present in
   17001                 :  * the Postgres grammar should appear in exactly one of these lists.
   17002                 :  *
   17003                 :  * Put a new keyword into the first list that it can go into without causing
   17004                 :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   17005                 :  * categories of keywords.
   17006                 :  *
   17007                 :  * Make sure that each keyword's category in kwlist.h matches where
   17008 ECB             :  * it is listed here.  (Someday we may be able to generate these lists and
   17009                 :  * kwlist.h's table from one source of truth.)
   17010                 :  */
   17011                 : 
   17012                 : /* "Unreserved" keywords --- available for use as any kind of name.
   17013                 :  */
   17014                 : unreserved_keyword:
   17015                 :               ABORT_P
   17016                 :             | ABSENT
   17017                 :             | ABSOLUTE_P
   17018                 :             | ACCESS
   17019                 :             | ACTION
   17020                 :             | ADD_P
   17021                 :             | ADMIN
   17022                 :             | AFTER
   17023                 :             | AGGREGATE
   17024                 :             | ALSO
   17025                 :             | ALTER
   17026                 :             | ALWAYS
   17027                 :             | ASENSITIVE
   17028                 :             | ASSERTION
   17029                 :             | ASSIGNMENT
   17030                 :             | AT
   17031                 :             | ATOMIC
   17032                 :             | ATTACH
   17033                 :             | ATTRIBUTE
   17034                 :             | BACKWARD
   17035                 :             | BEFORE
   17036                 :             | BEGIN_P
   17037                 :             | BREADTH
   17038                 :             | BY
   17039                 :             | CACHE
   17040                 :             | CALL
   17041                 :             | CALLED
   17042                 :             | CASCADE
   17043                 :             | CASCADED
   17044                 :             | CATALOG_P
   17045                 :             | CHAIN
   17046                 :             | CHARACTERISTICS
   17047                 :             | CHECKPOINT
   17048                 :             | CLASS
   17049                 :             | CLOSE
   17050                 :             | CLUSTER
   17051                 :             | COLUMNS
   17052                 :             | COMMENT
   17053                 :             | COMMENTS
   17054                 :             | COMMIT
   17055                 :             | COMMITTED
   17056                 :             | COMPRESSION
   17057                 :             | CONFIGURATION
   17058                 :             | CONFLICT
   17059                 :             | CONNECTION
   17060                 :             | CONSTRAINTS
   17061                 :             | CONTENT_P
   17062                 :             | CONTINUE_P
   17063                 :             | CONVERSION_P
   17064                 :             | COPY
   17065                 :             | COST
   17066                 :             | CSV
   17067                 :             | CUBE
   17068                 :             | CURRENT_P
   17069                 :             | CURSOR
   17070                 :             | CYCLE
   17071                 :             | DATA_P
   17072                 :             | DATABASE
   17073                 :             | DAY_P
   17074                 :             | DEALLOCATE
   17075                 :             | DECLARE
   17076                 :             | DEFAULTS
   17077                 :             | DEFERRED
   17078                 :             | DEFINER
   17079                 :             | DELETE_P
   17080                 :             | DELIMITER
   17081                 :             | DELIMITERS
   17082                 :             | DEPENDS
   17083                 :             | DEPTH
   17084                 :             | DETACH
   17085                 :             | DICTIONARY
   17086                 :             | DISABLE_P
   17087 EUB             :             | DISCARD
   17088                 :             | DOCUMENT_P
   17089                 :             | DOMAIN_P
   17090                 :             | DOUBLE_P
   17091                 :             | DROP
   17092                 :             | EACH
   17093                 :             | ENABLE_P
   17094                 :             | ENCODING
   17095                 :             | ENCRYPTED
   17096                 :             | ENUM_P
   17097                 :             | ESCAPE
   17098                 :             | EVENT
   17099                 :             | EXCLUDE
   17100                 :             | EXCLUDING
   17101                 :             | EXCLUSIVE
   17102                 :             | EXECUTE
   17103                 :             | EXPLAIN
   17104                 :             | EXPRESSION
   17105                 :             | EXTENSION
   17106                 :             | EXTERNAL
   17107                 :             | FAMILY
   17108                 :             | FILTER
   17109                 :             | FINALIZE
   17110                 :             | FIRST_P
   17111                 :             | FOLLOWING
   17112                 :             | FORCE
   17113                 :             | FORMAT
   17114                 :             | FORWARD
   17115                 :             | FUNCTION
   17116                 :             | FUNCTIONS
   17117                 :             | GENERATED
   17118                 :             | GLOBAL
   17119 ECB             :             | GRANTED
   17120                 :             | GROUPS
   17121                 :             | HANDLER
   17122                 :             | HEADER_P
   17123                 :             | HOLD
   17124                 :             | HOUR_P
   17125                 :             | IDENTITY_P
   17126                 :             | IF_P
   17127                 :             | IMMEDIATE
   17128                 :             | IMMUTABLE
   17129                 :             | IMPLICIT_P
   17130                 :             | IMPORT_P
   17131                 :             | INCLUDE
   17132                 :             | INCLUDING
   17133                 :             | INCREMENT
   17134                 :             | INDENT
   17135                 :             | INDEX
   17136                 :             | INDEXES
   17137                 :             | INHERIT
   17138                 :             | INHERITS
   17139                 :             | INLINE_P
   17140                 :             | INPUT_P
   17141                 :             | INSENSITIVE
   17142                 :             | INSERT
   17143                 :             | INSTEAD
   17144                 :             | INVOKER
   17145                 :             | ISOLATION
   17146                 :             | JSON
   17147                 :             | KEY
   17148                 :             | KEYS
   17149                 :             | LABEL
   17150                 :             | LANGUAGE
   17151                 :             | LARGE_P
   17152                 :             | LAST_P
   17153                 :             | LEAKPROOF
   17154                 :             | LEVEL
   17155                 :             | LISTEN
   17156                 :             | LOAD
   17157 EUB             :             | LOCAL
   17158 ECB             :             | LOCATION
   17159                 :             | LOCK_P
   17160                 :             | LOCKED
   17161                 :             | LOGGED
   17162                 :             | MAPPING
   17163                 :             | MATCH
   17164                 :             | MATCHED
   17165                 :             | MATERIALIZED
   17166                 :             | MAXVALUE
   17167                 :             | MERGE
   17168                 :             | METHOD
   17169                 :             | MINUTE_P
   17170                 :             | MINVALUE
   17171                 :             | MODE
   17172                 :             | MONTH_P
   17173                 :             | MOVE
   17174                 :             | NAME_P
   17175                 :             | NAMES
   17176                 :             | NEW
   17177                 :             | NEXT
   17178                 :             | NFC
   17179                 :             | NFD
   17180                 :             | NFKC
   17181                 :             | NFKD
   17182                 :             | NO
   17183                 :             | NORMALIZED
   17184                 :             | NOTHING
   17185                 :             | NOTIFY
   17186                 :             | NOWAIT
   17187                 :             | NULLS_P
   17188                 :             | OBJECT_P
   17189                 :             | OF
   17190                 :             | OFF
   17191                 :             | OIDS
   17192                 :             | OLD
   17193                 :             | OPERATOR
   17194                 :             | OPTION
   17195                 :             | OPTIONS
   17196                 :             | ORDINALITY
   17197                 :             | OTHERS
   17198                 :             | OVER
   17199                 :             | OVERRIDING
   17200                 :             | OWNED
   17201                 :             | OWNER
   17202                 :             | PARALLEL
   17203                 :             | PARAMETER
   17204                 :             | PARSER
   17205                 :             | PARTIAL
   17206                 :             | PARTITION
   17207                 :             | PASSING
   17208                 :             | PASSWORD
   17209                 :             | PLANS
   17210                 :             | POLICY
   17211                 :             | PRECEDING
   17212                 :             | PREPARE
   17213                 :             | PREPARED
   17214                 :             | PRESERVE
   17215                 :             | PRIOR
   17216                 :             | PRIVILEGES
   17217                 :             | PROCEDURAL
   17218                 :             | PROCEDURE
   17219                 :             | PROCEDURES
   17220                 :             | PROGRAM
   17221                 :             | PUBLICATION
   17222                 :             | QUOTE
   17223                 :             | RANGE
   17224                 :             | READ
   17225                 :             | REASSIGN
   17226                 :             | RECHECK
   17227                 :             | RECURSIVE
   17228                 :             | REF_P
   17229                 :             | REFERENCING
   17230                 :             | REFRESH
   17231                 :             | REINDEX
   17232                 :             | RELATIVE_P
   17233                 :             | RELEASE
   17234                 :             | RENAME
   17235                 :             | REPEATABLE
   17236                 :             | REPLACE
   17237                 :             | REPLICA
   17238                 :             | RESET
   17239                 :             | RESTART
   17240                 :             | RESTRICT
   17241                 :             | RETURN
   17242                 :             | RETURNS
   17243                 :             | REVOKE
   17244                 :             | ROLE
   17245                 :             | ROLLBACK
   17246                 :             | ROLLUP
   17247                 :             | ROUTINE
   17248                 :             | ROUTINES
   17249                 :             | ROWS
   17250                 :             | RULE
   17251                 :             | SAVEPOINT
   17252                 :             | SCALAR
   17253                 :             | SCHEMA
   17254                 :             | SCHEMAS
   17255                 :             | SCROLL
   17256                 :             | SEARCH
   17257                 :             | SECOND_P
   17258                 :             | SECURITY
   17259                 :             | SEQUENCE
   17260                 :             | SEQUENCES
   17261                 :             | SERIALIZABLE
   17262                 :             | SERVER
   17263                 :             | SESSION
   17264                 :             | SET
   17265                 :             | SETS
   17266                 :             | SHARE
   17267                 :             | SHOW
   17268                 :             | SIMPLE
   17269                 :             | SKIP
   17270                 :             | SNAPSHOT
   17271                 :             | SQL_P
   17272                 :             | STABLE
   17273                 :             | STANDALONE_P
   17274                 :             | START
   17275                 :             | STATEMENT
   17276                 :             | STATISTICS
   17277                 :             | STDIN
   17278                 :             | STDOUT
   17279                 :             | STORAGE
   17280                 :             | STORED
   17281                 :             | STRICT_P
   17282                 :             | STRIP_P
   17283                 :             | SUBSCRIPTION
   17284 EUB             :             | SUPPORT
   17285                 :             | SYSID
   17286                 :             | SYSTEM_P
   17287 ECB             :             | TABLES
   17288                 :             | TABLESPACE
   17289                 :             | TEMP
   17290                 :             | TEMPLATE
   17291                 :             | TEMPORARY
   17292                 :             | TEXT_P
   17293                 :             | TIES
   17294                 :             | TRANSACTION
   17295                 :             | TRANSFORM
   17296                 :             | TRIGGER
   17297                 :             | TRUNCATE
   17298                 :             | TRUSTED
   17299                 :             | TYPE_P
   17300                 :             | TYPES_P
   17301                 :             | UESCAPE
   17302                 :             | UNBOUNDED
   17303                 :             | UNCOMMITTED
   17304                 :             | UNENCRYPTED
   17305                 :             | UNKNOWN
   17306                 :             | UNLISTEN
   17307                 :             | UNLOGGED
   17308                 :             | UNTIL
   17309                 :             | UPDATE
   17310                 :             | VACUUM
   17311                 :             | VALID
   17312                 :             | VALIDATE
   17313                 :             | VALIDATOR
   17314                 :             | VALUE_P
   17315                 :             | VARYING
   17316                 :             | VERSION_P
   17317                 :             | VIEW
   17318                 :             | VIEWS
   17319                 :             | VOLATILE
   17320                 :             | WHITESPACE_P
   17321                 :             | WITHIN
   17322                 :             | WITHOUT
   17323                 :             | WORK
   17324                 :             | WRAPPER
   17325                 :             | WRITE
   17326                 :             | XML_P
   17327                 :             | YEAR_P
   17328                 :             | YES_P
   17329                 :             | ZONE
   17330                 :         ;
   17331                 : 
   17332                 : /* Column identifier --- keywords that can be column, table, etc names.
   17333                 :  *
   17334                 :  * Many of these keywords will in fact be recognized as type or function
   17335                 :  * names too; but they have special productions for the purpose, and so
   17336                 :  * can't be treated as "generic" type or function names.
   17337                 :  *
   17338                 :  * The type names appearing here are not usable as function names
   17339                 :  * because they can be followed by '(' in typename productions, which
   17340                 :  * looks too much like a function call for an LR(1) parser.
   17341                 :  */
   17342                 : col_name_keyword:
   17343                 :               BETWEEN
   17344                 :             | BIGINT
   17345                 :             | BIT
   17346                 :             | BOOLEAN_P
   17347                 :             | CHAR_P
   17348                 :             | CHARACTER
   17349                 :             | COALESCE
   17350                 :             | DEC
   17351                 :             | DECIMAL_P
   17352                 :             | EXISTS
   17353                 :             | EXTRACT
   17354                 :             | FLOAT_P
   17355                 :             | GREATEST
   17356                 :             | GROUPING
   17357                 :             | INOUT
   17358                 :             | INT_P
   17359                 :             | INTEGER
   17360                 :             | INTERVAL
   17361                 :             | JSON_ARRAY
   17362                 :             | JSON_ARRAYAGG
   17363                 :             | JSON_OBJECT
   17364                 :             | JSON_OBJECTAGG
   17365                 :             | LEAST
   17366                 :             | NATIONAL
   17367                 :             | NCHAR
   17368                 :             | NONE
   17369                 :             | NORMALIZE
   17370                 :             | NULLIF
   17371                 :             | NUMERIC
   17372                 :             | OUT_P
   17373                 :             | OVERLAY
   17374                 :             | POSITION
   17375                 :             | PRECISION
   17376                 :             | REAL
   17377                 :             | ROW
   17378                 :             | SETOF
   17379                 :             | SMALLINT
   17380                 :             | SUBSTRING
   17381                 :             | TIME
   17382                 :             | TIMESTAMP
   17383                 :             | TREAT
   17384                 :             | TRIM
   17385                 :             | VALUES
   17386                 :             | VARCHAR
   17387                 :             | XMLATTRIBUTES
   17388                 :             | XMLCONCAT
   17389                 :             | XMLELEMENT
   17390                 :             | XMLEXISTS
   17391                 :             | XMLFOREST
   17392                 :             | XMLNAMESPACES
   17393                 :             | XMLPARSE
   17394                 :             | XMLPI
   17395                 :             | XMLROOT
   17396                 :             | XMLSERIALIZE
   17397                 :             | XMLTABLE
   17398                 :         ;
   17399                 : 
   17400                 : /* Type/function identifier --- keywords that can be type or function names.
   17401                 :  *
   17402                 :  * Most of these are keywords that are used as operators in expressions;
   17403                 :  * in general such keywords can't be column names because they would be
   17404                 :  * ambiguous with variables, but they are unambiguous as function identifiers.
   17405                 :  *
   17406                 :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   17407                 :  * productions in a_expr to support the goofy SQL9x argument syntax.
   17408                 :  * - thomas 2000-11-28
   17409                 :  */
   17410                 : type_func_name_keyword:
   17411                 :               AUTHORIZATION
   17412                 :             | BINARY
   17413                 :             | COLLATION
   17414                 :             | CONCURRENTLY
   17415                 :             | CROSS
   17416                 :             | CURRENT_SCHEMA
   17417                 :             | FREEZE
   17418                 :             | FULL
   17419                 :             | ILIKE
   17420                 :             | INNER_P
   17421                 :             | IS
   17422                 :             | ISNULL
   17423                 :             | JOIN
   17424                 :             | LEFT
   17425                 :             | LIKE
   17426                 :             | NATURAL
   17427                 :             | NOTNULL
   17428                 :             | OUTER_P
   17429                 :             | OVERLAPS
   17430                 :             | RIGHT
   17431                 :             | SIMILAR
   17432                 :             | TABLESAMPLE
   17433                 :             | VERBOSE
   17434                 :         ;
   17435                 : 
   17436                 : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   17437                 :  *
   17438                 :  * Keywords appear here if they could not be distinguished from variable,
   17439                 :  * type, or function names in some contexts.  Don't put things here unless
   17440                 :  * forced to.
   17441                 :  */
   17442                 : reserved_keyword:
   17443                 :               ALL
   17444                 :             | ANALYSE
   17445                 :             | ANALYZE
   17446                 :             | AND
   17447                 :             | ANY
   17448                 :             | ARRAY
   17449                 :             | AS
   17450                 :             | ASC
   17451                 :             | ASYMMETRIC
   17452                 :             | BOTH
   17453                 :             | CASE
   17454                 :             | CAST
   17455                 :             | CHECK
   17456                 :             | COLLATE
   17457                 :             | COLUMN
   17458                 :             | CONSTRAINT
   17459                 :             | CREATE
   17460                 :             | CURRENT_CATALOG
   17461                 :             | CURRENT_DATE
   17462                 :             | CURRENT_ROLE
   17463                 :             | CURRENT_TIME
   17464                 :             | CURRENT_TIMESTAMP
   17465                 :             | CURRENT_USER
   17466                 :             | DEFAULT
   17467                 :             | DEFERRABLE
   17468                 :             | DESC
   17469                 :             | DISTINCT
   17470                 :             | DO
   17471                 :             | ELSE
   17472                 :             | END_P
   17473                 :             | EXCEPT
   17474                 :             | FALSE_P
   17475                 :             | FETCH
   17476                 :             | FOR
   17477                 :             | FOREIGN
   17478                 :             | FROM
   17479                 :             | GRANT
   17480                 :             | GROUP_P
   17481                 :             | HAVING
   17482                 :             | IN_P
   17483                 :             | INITIALLY
   17484                 :             | INTERSECT
   17485                 :             | INTO
   17486                 :             | LATERAL_P
   17487                 :             | LEADING
   17488                 :             | LIMIT
   17489                 :             | LOCALTIME
   17490                 :             | LOCALTIMESTAMP
   17491                 :             | NOT
   17492                 :             | NULL_P
   17493                 :             | OFFSET
   17494                 :             | ON
   17495                 :             | ONLY
   17496                 :             | OR
   17497                 :             | ORDER
   17498                 :             | PLACING
   17499                 :             | PRIMARY
   17500                 :             | REFERENCES
   17501                 :             | RETURNING
   17502                 :             | SELECT
   17503                 :             | SESSION_USER
   17504                 :             | SOME
   17505                 :             | SYMMETRIC
   17506                 :             | SYSTEM_USER
   17507                 :             | TABLE
   17508                 :             | THEN
   17509                 :             | TO
   17510                 :             | TRAILING
   17511                 :             | TRUE_P
   17512                 :             | UNION
   17513                 :             | UNIQUE
   17514                 :             | USER
   17515                 :             | USING
   17516                 :             | VARIADIC
   17517                 :             | WHEN
   17518                 :             | WHERE
   17519                 :             | WINDOW
   17520                 :             | WITH
   17521                 :         ;
   17522                 : 
   17523                 : /*
   17524                 :  * While all keywords can be used as column labels when preceded by AS,
   17525                 :  * not all of them can be used as a "bare" column label without AS.
   17526                 :  * Those that can be used as a bare label must be listed here,
   17527                 :  * in addition to appearing in one of the category lists above.
   17528                 :  *
   17529                 :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   17530                 :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   17531                 :  */
   17532                 : bare_label_keyword:
   17533                 :               ABORT_P
   17534                 :             | ABSENT
   17535                 :             | ABSOLUTE_P
   17536                 :             | ACCESS
   17537                 :             | ACTION
   17538                 :             | ADD_P
   17539                 :             | ADMIN
   17540                 :             | AFTER
   17541                 :             | AGGREGATE
   17542                 :             | ALL
   17543                 :             | ALSO
   17544                 :             | ALTER
   17545                 :             | ALWAYS
   17546                 :             | ANALYSE
   17547                 :             | ANALYZE
   17548                 :             | AND
   17549                 :             | ANY
   17550                 :             | ASC
   17551                 :             | ASENSITIVE
   17552                 :             | ASSERTION
   17553                 :             | ASSIGNMENT
   17554                 :             | ASYMMETRIC
   17555                 :             | AT
   17556                 :             | ATOMIC
   17557                 :             | ATTACH
   17558                 :             | ATTRIBUTE
   17559                 :             | AUTHORIZATION
   17560                 :             | BACKWARD
   17561                 :             | BEFORE
   17562                 :             | BEGIN_P
   17563                 :             | BETWEEN
   17564                 :             | BIGINT
   17565                 :             | BINARY
   17566                 :             | BIT
   17567                 :             | BOOLEAN_P
   17568                 :             | BOTH
   17569                 :             | BREADTH
   17570                 :             | BY
   17571                 :             | CACHE
   17572                 :             | CALL
   17573                 :             | CALLED
   17574                 :             | CASCADE
   17575                 :             | CASCADED
   17576                 :             | CASE
   17577                 :             | CAST
   17578                 :             | CATALOG_P
   17579                 :             | CHAIN
   17580                 :             | CHARACTERISTICS
   17581                 :             | CHECK
   17582                 :             | CHECKPOINT
   17583                 :             | CLASS
   17584                 :             | CLOSE
   17585                 :             | CLUSTER
   17586                 :             | COALESCE
   17587                 :             | COLLATE
   17588                 :             | COLLATION
   17589                 :             | COLUMN
   17590                 :             | COLUMNS
   17591                 :             | COMMENT
   17592                 :             | COMMENTS
   17593                 :             | COMMIT
   17594                 :             | COMMITTED
   17595                 :             | COMPRESSION
   17596                 :             | CONCURRENTLY
   17597                 :             | CONFIGURATION
   17598                 :             | CONFLICT
   17599                 :             | CONNECTION
   17600                 :             | CONSTRAINT
   17601                 :             | CONSTRAINTS
   17602                 :             | CONTENT_P
   17603                 :             | CONTINUE_P
   17604                 :             | CONVERSION_P
   17605                 :             | COPY
   17606                 :             | COST
   17607                 :             | CROSS
   17608                 :             | CSV
   17609                 :             | CUBE
   17610                 :             | CURRENT_P
   17611                 :             | CURRENT_CATALOG
   17612                 :             | CURRENT_DATE
   17613                 :             | CURRENT_ROLE
   17614                 :             | CURRENT_SCHEMA
   17615                 :             | CURRENT_TIME
   17616                 :             | CURRENT_TIMESTAMP
   17617                 :             | CURRENT_USER
   17618                 :             | CURSOR
   17619                 :             | CYCLE
   17620                 :             | DATA_P
   17621                 :             | DATABASE
   17622                 :             | DEALLOCATE
   17623                 :             | DEC
   17624                 :             | DECIMAL_P
   17625                 :             | DECLARE
   17626                 :             | DEFAULT
   17627                 :             | DEFAULTS
   17628                 :             | DEFERRABLE
   17629                 :             | DEFERRED
   17630                 :             | DEFINER
   17631                 :             | DELETE_P
   17632                 :             | DELIMITER
   17633                 :             | DELIMITERS
   17634                 :             | DEPENDS
   17635                 :             | DEPTH
   17636                 :             | DESC
   17637                 :             | DETACH
   17638                 :             | DICTIONARY
   17639                 :             | DISABLE_P
   17640                 :             | DISCARD
   17641                 :             | DISTINCT
   17642                 :             | DO
   17643                 :             | DOCUMENT_P
   17644                 :             | DOMAIN_P
   17645                 :             | DOUBLE_P
   17646                 :             | DROP
   17647                 :             | EACH
   17648                 :             | ELSE
   17649                 :             | ENABLE_P
   17650                 :             | ENCODING
   17651                 :             | ENCRYPTED
   17652                 :             | END_P
   17653                 :             | ENUM_P
   17654                 :             | ESCAPE
   17655                 :             | EVENT
   17656                 :             | EXCLUDE
   17657                 :             | EXCLUDING
   17658                 :             | EXCLUSIVE
   17659                 :             | EXECUTE
   17660                 :             | EXISTS
   17661                 :             | EXPLAIN
   17662                 :             | EXPRESSION
   17663                 :             | EXTENSION
   17664                 :             | EXTERNAL
   17665                 :             | EXTRACT
   17666                 :             | FALSE_P
   17667                 :             | FAMILY
   17668                 :             | FINALIZE
   17669                 :             | FIRST_P
   17670                 :             | FLOAT_P
   17671                 :             | FOLLOWING
   17672                 :             | FORCE
   17673                 :             | FOREIGN
   17674                 :             | FORMAT
   17675                 :             | FORWARD
   17676                 :             | FREEZE
   17677                 :             | FULL
   17678                 :             | FUNCTION
   17679                 :             | FUNCTIONS
   17680                 :             | GENERATED
   17681                 :             | GLOBAL
   17682                 :             | GRANTED
   17683                 :             | GREATEST
   17684                 :             | GROUPING
   17685                 :             | GROUPS
   17686                 :             | HANDLER
   17687                 :             | HEADER_P
   17688                 :             | HOLD
   17689                 :             | IDENTITY_P
   17690                 :             | IF_P
   17691                 :             | ILIKE
   17692                 :             | IMMEDIATE
   17693                 :             | IMMUTABLE
   17694                 :             | IMPLICIT_P
   17695                 :             | IMPORT_P
   17696                 :             | IN_P
   17697                 :             | INCLUDE
   17698                 :             | INCLUDING
   17699                 :             | INCREMENT
   17700                 :             | INDENT
   17701                 :             | INDEX
   17702                 :             | INDEXES
   17703                 :             | INHERIT
   17704                 :             | INHERITS
   17705                 :             | INITIALLY
   17706                 :             | INLINE_P
   17707                 :             | INNER_P
   17708                 :             | INOUT
   17709                 :             | INPUT_P
   17710                 :             | INSENSITIVE
   17711                 :             | INSERT
   17712                 :             | INSTEAD
   17713                 :             | INT_P
   17714                 :             | INTEGER
   17715                 :             | INTERVAL
   17716                 :             | INVOKER
   17717                 :             | IS
   17718                 :             | ISOLATION
   17719                 :             | JOIN
   17720                 :             | JSON
   17721                 :             | JSON_ARRAY
   17722                 :             | JSON_ARRAYAGG
   17723                 :             | JSON_OBJECT
   17724                 :             | JSON_OBJECTAGG
   17725                 :             | KEY
   17726                 :             | KEYS
   17727                 :             | LABEL
   17728                 :             | LANGUAGE
   17729                 :             | LARGE_P
   17730                 :             | LAST_P
   17731                 :             | LATERAL_P
   17732                 :             | LEADING
   17733                 :             | LEAKPROOF
   17734                 :             | LEAST
   17735                 :             | LEFT
   17736                 :             | LEVEL
   17737                 :             | LIKE
   17738                 :             | LISTEN
   17739                 :             | LOAD
   17740                 :             | LOCAL
   17741                 :             | LOCALTIME
   17742                 :             | LOCALTIMESTAMP
   17743                 :             | LOCATION
   17744                 :             | LOCK_P
   17745                 :             | LOCKED
   17746                 :             | LOGGED
   17747                 :             | MAPPING
   17748                 :             | MATCH
   17749                 :             | MATCHED
   17750                 :             | MATERIALIZED
   17751                 :             | MAXVALUE
   17752                 :             | MERGE
   17753                 :             | METHOD
   17754                 :             | MINVALUE
   17755                 :             | MODE
   17756                 :             | MOVE
   17757                 :             | NAME_P
   17758                 :             | NAMES
   17759                 :             | NATIONAL
   17760                 :             | NATURAL
   17761                 :             | NCHAR
   17762                 :             | NEW
   17763                 :             | NEXT
   17764                 :             | NFC
   17765                 :             | NFD
   17766                 :             | NFKC
   17767                 :             | NFKD
   17768                 :             | NO
   17769                 :             | NONE
   17770                 :             | NORMALIZE
   17771                 :             | NORMALIZED
   17772                 :             | NOT
   17773                 :             | NOTHING
   17774                 :             | NOTIFY
   17775                 :             | NOWAIT
   17776                 :             | NULL_P
   17777                 :             | NULLIF
   17778                 :             | NULLS_P
   17779                 :             | NUMERIC
   17780                 :             | OBJECT_P
   17781                 :             | OF
   17782                 :             | OFF
   17783                 :             | OIDS
   17784                 :             | OLD
   17785                 :             | ONLY
   17786                 :             | OPERATOR
   17787                 :             | OPTION
   17788                 :             | OPTIONS
   17789                 :             | OR
   17790                 :             | ORDINALITY
   17791                 :             | OTHERS
   17792                 :             | OUT_P
   17793                 :             | OUTER_P
   17794                 :             | OVERLAY
   17795                 :             | OVERRIDING
   17796                 :             | OWNED
   17797                 :             | OWNER
   17798                 :             | PARALLEL
   17799                 :             | PARAMETER
   17800                 :             | PARSER
   17801                 :             | PARTIAL
   17802                 :             | PARTITION
   17803                 :             | PASSING
   17804                 :             | PASSWORD
   17805                 :             | PLACING
   17806                 :             | PLANS
   17807                 :             | POLICY
   17808                 :             | POSITION
   17809                 :             | PRECEDING
   17810                 :             | PREPARE
   17811                 :             | PREPARED
   17812                 :             | PRESERVE
   17813                 :             | PRIMARY
   17814                 :             | PRIOR
   17815                 :             | PRIVILEGES
   17816                 :             | PROCEDURAL
   17817                 :             | PROCEDURE
   17818                 :             | PROCEDURES
   17819                 :             | PROGRAM
   17820                 :             | PUBLICATION
   17821                 :             | QUOTE
   17822                 :             | RANGE
   17823                 :             | READ
   17824                 :             | REAL
   17825                 :             | REASSIGN
   17826                 :             | RECHECK
   17827                 :             | RECURSIVE
   17828                 :             | REF_P
   17829                 :             | REFERENCES
   17830                 :             | REFERENCING
   17831                 :             | REFRESH
   17832                 :             | REINDEX
   17833                 :             | RELATIVE_P
   17834                 :             | RELEASE
   17835                 :             | RENAME
   17836                 :             | REPEATABLE
   17837                 :             | REPLACE
   17838                 :             | REPLICA
   17839                 :             | RESET
   17840                 :             | RESTART
   17841                 :             | RESTRICT
   17842                 :             | RETURN
   17843                 :             | RETURNS
   17844                 :             | REVOKE
   17845                 :             | RIGHT
   17846                 :             | ROLE
   17847                 :             | ROLLBACK
   17848                 :             | ROLLUP
   17849                 :             | ROUTINE
   17850                 :             | ROUTINES
   17851                 :             | ROW
   17852                 :             | ROWS
   17853                 :             | RULE
   17854                 :             | SAVEPOINT
   17855                 :             | SCALAR
   17856                 :             | SCHEMA
   17857                 :             | SCHEMAS
   17858                 :             | SCROLL
   17859                 :             | SEARCH
   17860                 :             | SECURITY
   17861                 :             | SELECT
   17862                 :             | SEQUENCE
   17863                 :             | SEQUENCES
   17864                 :             | SERIALIZABLE
   17865                 :             | SERVER
   17866                 :             | SESSION
   17867                 :             | SESSION_USER
   17868                 :             | SET
   17869                 :             | SETOF
   17870                 :             | SETS
   17871                 :             | SHARE
   17872                 :             | SHOW
   17873                 :             | SIMILAR
   17874                 :             | SIMPLE
   17875                 :             | SKIP
   17876                 :             | SMALLINT
   17877                 :             | SNAPSHOT
   17878                 :             | SOME
   17879                 :             | SQL_P
   17880                 :             | STABLE
   17881                 :             | STANDALONE_P
   17882                 :             | START
   17883                 :             | STATEMENT
   17884                 :             | STATISTICS
   17885                 :             | STDIN
   17886                 :             | STDOUT
   17887                 :             | STORAGE
   17888                 :             | STORED
   17889                 :             | STRICT_P
   17890                 :             | STRIP_P
   17891                 :             | SUBSCRIPTION
   17892                 :             | SUBSTRING
   17893                 :             | SUPPORT
   17894                 :             | SYMMETRIC
   17895                 :             | SYSID
   17896                 :             | SYSTEM_P
   17897                 :             | SYSTEM_USER
   17898                 :             | TABLE
   17899                 :             | TABLES
   17900                 :             | TABLESAMPLE
   17901                 :             | TABLESPACE
   17902                 :             | TEMP
   17903                 :             | TEMPLATE
   17904                 :             | TEMPORARY
   17905                 :             | TEXT_P
   17906                 :             | THEN
   17907                 :             | TIES
   17908                 :             | TIME
   17909                 :             | TIMESTAMP
   17910                 :             | TRAILING
   17911                 :             | TRANSACTION
   17912                 :             | TRANSFORM
   17913                 :             | TREAT
   17914                 :             | TRIGGER
   17915                 :             | TRIM
   17916                 :             | TRUE_P
   17917                 :             | TRUNCATE
   17918                 :             | TRUSTED
   17919                 :             | TYPE_P
   17920                 :             | TYPES_P
   17921                 :             | UESCAPE
   17922                 :             | UNBOUNDED
   17923                 :             | UNCOMMITTED
   17924                 :             | UNENCRYPTED
   17925                 :             | UNIQUE
   17926                 :             | UNKNOWN
   17927                 :             | UNLISTEN
   17928                 :             | UNLOGGED
   17929                 :             | UNTIL
   17930                 :             | UPDATE
   17931                 :             | USER
   17932                 :             | USING
   17933                 :             | VACUUM
   17934                 :             | VALID
   17935                 :             | VALIDATE
   17936                 :             | VALIDATOR
   17937                 :             | VALUE_P
   17938                 :             | VALUES
   17939                 :             | VARCHAR
   17940                 :             | VARIADIC
   17941                 :             | VERBOSE
   17942                 :             | VERSION_P
   17943                 :             | VIEW
   17944                 :             | VIEWS
   17945                 :             | VOLATILE
   17946                 :             | WHEN
   17947                 :             | WHITESPACE_P
   17948                 :             | WORK
   17949                 :             | WRAPPER
   17950                 :             | WRITE
   17951                 :             | XML_P
   17952                 :             | XMLATTRIBUTES
   17953                 :             | XMLCONCAT
   17954                 :             | XMLELEMENT
   17955                 :             | XMLEXISTS
   17956                 :             | XMLFOREST
   17957                 :             | XMLNAMESPACES
   17958                 :             | XMLPARSE
   17959                 :             | XMLPI
   17960                 :             | XMLROOT
   17961                 :             | XMLSERIALIZE
   17962                 :             | XMLTABLE
   17963                 :             | YES_P
   17964                 :             | ZONE
   17965                 :         ;
   17966                 : 
   17967                 : %%
   17968                 : 
   17969                 : /*
   17970                 :  * The signature of this function is required by bison.  However, we
   17971                 :  * ignore the passed yylloc and instead use the last token position
   17972                 :  * available from the scanner.
   17973                 :  */
   17974                 : static void
   17975 GIC         322 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   17976                 : {
   17977             322 :     parser_yyerror(msg);
   17978                 : }
   17979                 : 
   17980                 : static RawStmt *
   17981          540777 : makeRawStmt(Node *stmt, int stmt_location)
   17982                 : {
   17983          540777 :     RawStmt    *rs = makeNode(RawStmt);
   17984                 : 
   17985          540777 :     rs->stmt = stmt;
   17986          540777 :     rs->stmt_location = stmt_location;
   17987          540777 :     rs->stmt_len = 0;            /* might get changed later */
   17988          540777 :     return rs;
   17989                 : }
   17990                 : 
   17991                 : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   17992                 : static void
   17993          454229 : updateRawStmtEnd(RawStmt *rs, int end_location)
   17994                 : {
   17995                 :     /*
   17996                 :      * If we already set the length, don't change it.  This is for situations
   17997                 :      * like "select foo ;; select bar" where the same statement will be last
   17998                 :      * in the string for more than one semicolon.
   17999                 :      */
   18000          454229 :     if (rs->stmt_len > 0)
   18001               5 :         return;
   18002                 : 
   18003                 :     /* OK, update length of RawStmt */
   18004          454224 :     rs->stmt_len = end_location - rs->stmt_location;
   18005                 : }
   18006                 : 
   18007                 : static Node *
   18008         1358108 : makeColumnRef(char *colname, List *indirection,
   18009                 :               int location, core_yyscan_t yyscanner)
   18010                 : {
   18011                 :     /*
   18012                 :      * Generate a ColumnRef node, with an A_Indirection node added if there
   18013                 :      * is any subscripting in the specified indirection list.  However,
   18014                 :      * any field selection at the start of the indirection list must be
   18015                 :      * transposed into the "fields" part of the ColumnRef node.
   18016                 :      */
   18017         1358108 :     ColumnRef  *c = makeNode(ColumnRef);
   18018         1358108 :     int         nfields = 0;
   18019                 :     ListCell   *l;
   18020                 : 
   18021         1358108 :     c->location = location;
   18022         2307350 :     foreach(l, indirection)
   18023                 :     {
   18024          955685 :         if (IsA(lfirst(l), A_Indices))
   18025                 :         {
   18026            6443 :             A_Indirection *i = makeNode(A_Indirection);
   18027                 : 
   18028            6443 :             if (nfields == 0)
   18029                 :             {
   18030                 :                 /* easy case - all indirection goes to A_Indirection */
   18031            5607 :                 c->fields = list_make1(makeString(colname));
   18032            5607 :                 i->indirection = check_indirection(indirection, yyscanner);
   18033                 :             }
   18034                 :             else
   18035                 :             {
   18036                 :                 /* got to split the list in two */
   18037             836 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   18038                 :                                                                   nfields),
   18039                 :                                                    yyscanner);
   18040             836 :                 indirection = list_truncate(indirection, nfields);
   18041             836 :                 c->fields = lcons(makeString(colname), indirection);
   18042                 :             }
   18043            6443 :             i->arg = (Node *) c;
   18044            6443 :             return (Node *) i;
   18045                 :         }
   18046          949242 :         else if (IsA(lfirst(l), A_Star))
   18047                 :         {
   18048                 :             /* We only allow '*' at the end of a ColumnRef */
   18049            2099 :             if (lnext(indirection, l) != NULL)
   18050 UIC           0 :                 parser_yyerror("improper use of \"*\"");
   18051                 :         }
   18052 GIC      949242 :         nfields++;
   18053                 :     }
   18054                 :     /* No subscripting, so all indirection gets added to field list */
   18055         1351665 :     c->fields = lcons(makeString(colname), indirection);
   18056         1351665 :     return (Node *) c;
   18057                 : }
   18058                 : 
   18059                 : static Node *
   18060          311956 : makeTypeCast(Node *arg, TypeName *typename, int location)
   18061                 : {
   18062          311956 :     TypeCast   *n = makeNode(TypeCast);
   18063                 : 
   18064          311956 :     n->arg = arg;
   18065          311956 :     n->typeName = typename;
   18066          311956 :     n->location = location;
   18067          311956 :     return (Node *) n;
   18068                 : }
   18069                 : 
   18070                 : static Node *
   18071          498738 : makeStringConst(char *str, int location)
   18072                 : {
   18073          498738 :     A_Const    *n = makeNode(A_Const);
   18074                 : 
   18075          498738 :     n->val.sval.type = T_String;
   18076          498738 :     n->val.sval.sval = str;
   18077          498738 :     n->location = location;
   18078                 : 
   18079          498738 :    return (Node *) n;
   18080                 : }
   18081                 : 
   18082                 : static Node *
   18083            6165 : makeStringConstCast(char *str, int location, TypeName *typename)
   18084                 : {
   18085            6165 :     Node       *s = makeStringConst(str, location);
   18086                 : 
   18087            6165 :     return makeTypeCast(s, typename, -1);
   18088                 : }
   18089                 : 
   18090                 : static Node *
   18091          267775 : makeIntConst(int val, int location)
   18092                 : {
   18093          267775 :     A_Const    *n = makeNode(A_Const);
   18094                 : 
   18095          267775 :     n->val.ival.type = T_Integer;
   18096          267775 :     n->val.ival.ival = val;
   18097          267775 :     n->location = location;
   18098                 : 
   18099          267775 :    return (Node *) n;
   18100                 : }
   18101                 : 
   18102                 : static Node *
   18103            5385 : makeFloatConst(char *str, int location)
   18104                 : {
   18105            5385 :     A_Const    *n = makeNode(A_Const);
   18106                 : 
   18107            5385 :     n->val.fval.type = T_Float;
   18108            5385 :     n->val.fval.fval = str;
   18109            5385 :     n->location = location;
   18110                 : 
   18111            5385 :    return (Node *) n;
   18112                 : }
   18113                 : 
   18114                 : static Node *
   18115           29657 : makeBoolAConst(bool state, int location)
   18116                 : {
   18117           29657 :     A_Const    *n = makeNode(A_Const);
   18118                 : 
   18119           29657 :     n->val.boolval.type = T_Boolean;
   18120           29657 :     n->val.boolval.boolval = state;
   18121           29657 :     n->location = location;
   18122                 : 
   18123           29657 :    return (Node *) n;
   18124                 : }
   18125                 : 
   18126                 : static Node *
   18127            2023 : makeBitStringConst(char *str, int location)
   18128                 : {
   18129            2023 :     A_Const    *n = makeNode(A_Const);
   18130                 : 
   18131            2023 :     n->val.bsval.type = T_BitString;
   18132            2023 :     n->val.bsval.bsval = str;
   18133            2023 :     n->location = location;
   18134                 : 
   18135            2023 :    return (Node *) n;
   18136                 : }
   18137                 : 
   18138                 : static Node *
   18139           96532 : makeNullAConst(int location)
   18140                 : {
   18141           96532 :     A_Const    *n = makeNode(A_Const);
   18142                 : 
   18143           96532 :     n->isnull = true;
   18144           96532 :     n->location = location;
   18145                 : 
   18146           96532 :     return (Node *) n;
   18147                 : }
   18148                 : 
   18149                 : static Node *
   18150            1670 : makeAConst(Node *v, int location)
   18151                 : {
   18152                 :     Node       *n;
   18153                 : 
   18154            1670 :     switch (v->type)
   18155                 :     {
   18156             109 :         case T_Float:
   18157             109 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   18158             109 :             break;
   18159                 : 
   18160            1561 :         case T_Integer:
   18161            1561 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   18162            1561 :             break;
   18163                 : 
   18164 UIC           0 :         default:
   18165                 :             /* currently not used */
   18166               0 :             Assert(false);
   18167                 :             n = NULL;
   18168                 :     }
   18169                 : 
   18170 GIC        1670 :     return n;
   18171                 : }
   18172                 : 
   18173                 : /* makeRoleSpec
   18174                 :  * Create a RoleSpec with the given type
   18175                 :  */
   18176                 : static RoleSpec *
   18177           54858 : makeRoleSpec(RoleSpecType type, int location)
   18178                 : {
   18179           54858 :     RoleSpec   *spec = makeNode(RoleSpec);
   18180                 : 
   18181           54858 :     spec->roletype = type;
   18182           54858 :     spec->location = location;
   18183                 : 
   18184           54858 :     return spec;
   18185                 : }
   18186                 : 
   18187                 : /* check_qualified_name --- check the result of qualified_name production
   18188                 :  *
   18189                 :  * It's easiest to let the grammar production for qualified_name allow
   18190                 :  * subscripts and '*', which we then must reject here.
   18191                 :  */
   18192                 : static void
   18193           90692 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   18194                 : {
   18195                 :     ListCell   *i;
   18196                 : 
   18197          181384 :     foreach(i, names)
   18198                 :     {
   18199           90692 :         if (!IsA(lfirst(i), String))
   18200 UIC           0 :             parser_yyerror("syntax error");
   18201                 :     }
   18202 GIC       90692 : }
   18203                 : 
   18204                 : /* check_func_name --- check the result of func_name production
   18205                 :  *
   18206                 :  * It's easiest to let the grammar production for func_name allow subscripts
   18207                 :  * and '*', which we then must reject here.
   18208                 :  */
   18209                 : static List *
   18210           46693 : check_func_name(List *names, core_yyscan_t yyscanner)
   18211                 : {
   18212                 :     ListCell   *i;
   18213                 : 
   18214          140079 :     foreach(i, names)
   18215                 :     {
   18216           93386 :         if (!IsA(lfirst(i), String))
   18217 UIC           0 :             parser_yyerror("syntax error");
   18218                 :     }
   18219 GIC       46693 :     return names;
   18220                 : }
   18221                 : 
   18222                 : /* check_indirection --- check the result of indirection production
   18223                 :  *
   18224                 :  * We only allow '*' at the end of the list, but it's hard to enforce that
   18225                 :  * in the grammar, so do it here.
   18226                 :  */
   18227                 : static List *
   18228           80312 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   18229                 : {
   18230                 :     ListCell *l;
   18231                 : 
   18232          126393 :     foreach(l, indirection)
   18233                 :     {
   18234           46081 :         if (IsA(lfirst(l), A_Star))
   18235                 :         {
   18236            2983 :             if (lnext(indirection, l) != NULL)
   18237 UIC           0 :                 parser_yyerror("improper use of \"*\"");
   18238                 :         }
   18239                 :     }
   18240 GIC       80312 :     return indirection;
   18241                 : }
   18242                 : 
   18243                 : /* extractArgTypes()
   18244                 :  * Given a list of FunctionParameter nodes, extract a list of just the
   18245                 :  * argument types (TypeNames) for input parameters only.  This is what
   18246                 :  * is needed to look up an existing function, which is what is wanted by
   18247                 :  * the productions that use this call.
   18248                 :  */
   18249                 : static List *
   18250           25527 : extractArgTypes(List *parameters)
   18251                 : {
   18252           25527 :     List       *result = NIL;
   18253                 :     ListCell   *i;
   18254                 : 
   18255           50381 :     foreach(i, parameters)
   18256                 :     {
   18257           24854 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   18258                 : 
   18259           24854 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   18260           24779 :             result = lappend(result, p->argType);
   18261                 :     }
   18262           25527 :     return result;
   18263                 : }
   18264                 : 
   18265                 : /* extractAggrArgTypes()
   18266                 :  * As above, but work from the output of the aggr_args production.
   18267                 :  */
   18268                 : static List *
   18269             181 : extractAggrArgTypes(List *aggrargs)
   18270                 : {
   18271             181 :     Assert(list_length(aggrargs) == 2);
   18272             181 :     return extractArgTypes((List *) linitial(aggrargs));
   18273                 : }
   18274                 : 
   18275                 : /* makeOrderedSetArgs()
   18276                 :  * Build the result of the aggr_args production (which see the comments for).
   18277                 :  * This handles only the case where both given lists are nonempty, so that
   18278                 :  * we have to deal with multiple VARIADIC arguments.
   18279                 :  */
   18280                 : static List *
   18281              16 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   18282                 :                    core_yyscan_t yyscanner)
   18283                 : {
   18284              16 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   18285                 :     Integer    *ndirectargs;
   18286                 : 
   18287                 :     /* No restriction unless last direct arg is VARIADIC */
   18288              16 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   18289                 :     {
   18290               8 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   18291                 : 
   18292                 :         /*
   18293                 :          * We ignore the names, though the aggr_arg production allows them;
   18294                 :          * it doesn't allow default values, so those need not be checked.
   18295                 :          */
   18296               8 :         if (list_length(orderedargs) != 1 ||
   18297               8 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   18298               8 :             !equal(lastd->argType, firsto->argType))
   18299 UIC           0 :             ereport(ERROR,
   18300                 :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   18301                 :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   18302                 :                      parser_errposition(exprLocation((Node *) firsto))));
   18303                 : 
   18304                 :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   18305 GIC           8 :         orderedargs = NIL;
   18306                 :     }
   18307                 : 
   18308                 :     /* don't merge into the next line, as list_concat changes directargs */
   18309              16 :     ndirectargs = makeInteger(list_length(directargs));
   18310                 : 
   18311              16 :     return list_make2(list_concat(directargs, orderedargs),
   18312                 :                       ndirectargs);
   18313                 : }
   18314                 : 
   18315                 : /* insertSelectOptions()
   18316                 :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   18317                 :  *
   18318                 :  * This routine is just to avoid duplicating code in SelectStmt productions.
   18319                 :  */
   18320                 : static void
   18321           30248 : insertSelectOptions(SelectStmt *stmt,
   18322                 :                     List *sortClause, List *lockingClause,
   18323                 :                     SelectLimit *limitClause,
   18324                 :                     WithClause *withClause,
   18325                 :                     core_yyscan_t yyscanner)
   18326                 : {
   18327           30248 :     Assert(IsA(stmt, SelectStmt));
   18328                 : 
   18329                 :     /*
   18330                 :      * Tests here are to reject constructs like
   18331                 :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   18332                 :      */
   18333           30248 :     if (sortClause)
   18334                 :     {
   18335           26190 :         if (stmt->sortClause)
   18336 UIC           0 :             ereport(ERROR,
   18337                 :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18338                 :                      errmsg("multiple ORDER BY clauses not allowed"),
   18339                 :                      parser_errposition(exprLocation((Node *) sortClause))));
   18340 GIC       26190 :         stmt->sortClause = sortClause;
   18341                 :     }
   18342                 :     /* We can handle multiple locking clauses, though */
   18343           30248 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   18344           30248 :     if (limitClause && limitClause->limitOffset)
   18345                 :     {
   18346             359 :         if (stmt->limitOffset)
   18347 UIC           0 :             ereport(ERROR,
   18348                 :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18349                 :                      errmsg("multiple OFFSET clauses not allowed"),
   18350                 :                      parser_errposition(exprLocation(limitClause->limitOffset))));
   18351 GIC         359 :         stmt->limitOffset = limitClause->limitOffset;
   18352                 :     }
   18353           30248 :     if (limitClause && limitClause->limitCount)
   18354                 :     {
   18355            2937 :         if (stmt->limitCount)
   18356 UIC           0 :             ereport(ERROR,
   18357                 :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18358                 :                      errmsg("multiple LIMIT clauses not allowed"),
   18359                 :                      parser_errposition(exprLocation(limitClause->limitCount))));
   18360 GIC        2937 :         stmt->limitCount = limitClause->limitCount;
   18361                 :     }
   18362           30248 :     if (limitClause && limitClause->limitOption != LIMIT_OPTION_DEFAULT)
   18363 ECB             :     {
   18364 GIC        3109 :         if (stmt->limitOption)
   18365 LBC           0 :             ereport(ERROR,
   18366                 :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18367                 :                      errmsg("multiple limit options not allowed")));
   18368 GIC        3109 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   18369 CBC           3 :             ereport(ERROR,
   18370                 :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18371 ECB             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause")));
   18372 GIC        3106 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   18373 ECB             :         {
   18374                 :             ListCell   *lc;
   18375                 : 
   18376 CBC           3 :             foreach(lc, stmt->lockingClause)
   18377                 :             {
   18378 GIC           3 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   18379                 : 
   18380               3 :                 if (lock->waitPolicy == LockWaitSkip)
   18381 CBC           3 :                     ereport(ERROR,
   18382                 :                             (errcode(ERRCODE_SYNTAX_ERROR),
   18383                 :                              errmsg("%s and %s options cannot be used together",
   18384                 :                                     "SKIP LOCKED", "WITH TIES")));
   18385                 :             }
   18386                 :         }
   18387 GIC        3103 :         stmt->limitOption = limitClause->limitOption;
   18388 ECB             :     }
   18389 CBC       30242 :     if (withClause)
   18390                 :     {
   18391 GIC        1038 :         if (stmt->withClause)
   18392 LBC           0 :             ereport(ERROR,
   18393                 :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18394                 :                      errmsg("multiple WITH clauses not allowed"),
   18395                 :                      parser_errposition(exprLocation((Node *) withClause))));
   18396 CBC        1038 :         stmt->withClause = withClause;
   18397                 :     }
   18398 GIC       30242 : }
   18399                 : 
   18400                 : static Node *
   18401           16666 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
   18402                 : {
   18403           16666 :     SelectStmt *n = makeNode(SelectStmt);
   18404                 : 
   18405 CBC       16666 :     n->op = op;
   18406           16666 :     n->all = all;
   18407 GIC       16666 :     n->larg = (SelectStmt *) larg;
   18408           16666 :     n->rarg = (SelectStmt *) rarg;
   18409 CBC       16666 :     return (Node *) n;
   18410 ECB             : }
   18411                 : 
   18412                 : /* SystemFuncName()
   18413                 :  * Build a properly-qualified reference to a built-in function.
   18414                 :  */
   18415                 : List *
   18416 CBC       15783 : SystemFuncName(char *name)
   18417                 : {
   18418 GIC       15783 :     return list_make2(makeString("pg_catalog"), makeString(name));
   18419 ECB             : }
   18420                 : 
   18421                 : /* SystemTypeName()
   18422                 :  * Build a properly-qualified reference to a built-in type.
   18423                 :  *
   18424                 :  * typmod is defaulted, but may be changed afterwards by caller.
   18425                 :  * Likewise for the location.
   18426                 :  */
   18427                 : TypeName *
   18428 CBC       83714 : SystemTypeName(char *name)
   18429 ECB             : {
   18430 GIC       83714 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   18431 ECB             :                                                makeString(name)));
   18432                 : }
   18433                 : 
   18434                 : /* doNegate()
   18435                 :  * Handle negation of a numeric constant.
   18436                 :  *
   18437                 :  * Formerly, we did this here because the optimizer couldn't cope with
   18438 EUB             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   18439                 :  * and a unary minus operator applied to a constant didn't qualify.
   18440 ECB             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   18441                 :  * is a constant-subexpression simplifier in the optimizer.  However,
   18442                 :  * there's still a good reason for doing this here, which is that we can
   18443                 :  * postpone committing to a particular internal representation for simple
   18444                 :  * negative constants.  It's better to leave "-123.456" in string form
   18445                 :  * until we know what the desired type is.
   18446                 :  */
   18447                 : static Node *
   18448 CBC        8915 : doNegate(Node *n, int location)
   18449                 : {
   18450            8915 :     if (IsA(n, A_Const))
   18451                 :     {
   18452            8493 :         A_Const    *con = (A_Const *) n;
   18453 ECB             : 
   18454                 :         /* report the constant's location as that of the '-' sign */
   18455 CBC        8493 :         con->location = location;
   18456                 : 
   18457 GIC        8493 :         if (IsA(&con->val, Integer))
   18458                 :         {
   18459 CBC        8104 :             con->val.ival.ival = -con->val.ival.ival;
   18460 GIC        8104 :             return n;
   18461 ECB             :         }
   18462 GIC         389 :         if (IsA(&con->val, Float))
   18463 ECB             :         {
   18464 CBC         389 :             doNegateFloat(&con->val.fval);
   18465             389 :             return n;
   18466                 :         }
   18467 ECB             :     }
   18468                 : 
   18469 GIC         422 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   18470                 : }
   18471 ECB             : 
   18472                 : static void
   18473 CBC         399 : doNegateFloat(Float *v)
   18474                 : {
   18475             399 :     char       *oldval = v->fval;
   18476                 : 
   18477 GIC         399 :     if (*oldval == '+')
   18478 UIC           0 :         oldval++;
   18479 CBC         399 :     if (*oldval == '-')
   18480 UIC           0 :         v->fval = oldval+1;  /* just strip the '-' */
   18481 ECB             :     else
   18482 GIC         399 :         v->fval = psprintf("-%s", oldval);
   18483 CBC         399 : }
   18484 ECB             : 
   18485                 : static Node *
   18486 GIC      174289 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   18487 ECB             : {
   18488                 :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   18489 GIC      174289 :     if (IsA(lexpr, BoolExpr))
   18490                 :     {
   18491 CBC       96665 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   18492                 : 
   18493           96665 :         if (blexpr->boolop == AND_EXPR)
   18494                 :         {
   18495           94261 :             blexpr->args = lappend(blexpr->args, rexpr);
   18496           94261 :             return (Node *) blexpr;
   18497 ECB             :         }
   18498                 :     }
   18499 CBC       80028 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   18500                 : }
   18501                 : 
   18502                 : static Node *
   18503           26248 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   18504                 : {
   18505 ECB             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   18506 GIC       26248 :     if (IsA(lexpr, BoolExpr))
   18507 ECB             :     {
   18508 CBC        7442 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   18509 ECB             : 
   18510 GIC        7442 :         if (blexpr->boolop == OR_EXPR)
   18511 ECB             :         {
   18512 GIC        6128 :             blexpr->args = lappend(blexpr->args, rexpr);
   18513            6128 :             return (Node *) blexpr;
   18514                 :         }
   18515 ECB             :     }
   18516 GIC       20120 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   18517 ECB             : }
   18518                 : 
   18519                 : static Node *
   18520 CBC       15206 : makeNotExpr(Node *expr, int location)
   18521 ECB             : {
   18522 GIC       15206 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   18523 ECB             : }
   18524                 : 
   18525                 : static Node *
   18526 GIC        3780 : makeAArrayExpr(List *elements, int location)
   18527 ECB             : {
   18528 GIC        3780 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   18529 ECB             : 
   18530 GIC        3780 :     n->elements = elements;
   18531 CBC        3780 :     n->location = location;
   18532            3780 :     return (Node *) n;
   18533                 : }
   18534 ECB             : 
   18535                 : static Node *
   18536 CBC         298 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   18537 ECB             :             int location)
   18538                 : {
   18539 GIC         298 :     XmlExpr     *x = makeNode(XmlExpr);
   18540 EUB             : 
   18541 GIC         298 :     x->op = op;
   18542 GBC         298 :     x->name = name;
   18543                 :     /*
   18544                 :      * named_args is a list of ResTarget; it'll be split apart into separate
   18545                 :      * expression and name lists in transformXmlExpr().
   18546 ECB             :      */
   18547 GIC         298 :     x->named_args = named_args;
   18548             298 :     x->arg_names = NIL;
   18549             298 :     x->args = args;
   18550                 :     /* xmloption, if relevant, must be filled in by caller */
   18551                 :     /* type and typmod will be filled in during parse analysis */
   18552             298 :     x->type = InvalidOid;            /* marks the node as not analyzed */
   18553 CBC         298 :     x->location = location;
   18554 GIC         298 :     return (Node *) x;
   18555 ECB             : }
   18556                 : 
   18557                 : /*
   18558                 :  * Merge the input and output parameters of a table function.
   18559                 :  */
   18560                 : static List *
   18561 GIC          88 : mergeTableFuncParameters(List *func_args, List *columns)
   18562                 : {
   18563                 :     ListCell   *lc;
   18564                 : 
   18565                 :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   18566             185 :     foreach(lc, func_args)
   18567                 :     {
   18568              97 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   18569 ECB             : 
   18570 GIC          97 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   18571 UIC           0 :             p->mode != FUNC_PARAM_IN &&
   18572               0 :             p->mode != FUNC_PARAM_VARIADIC)
   18573 LBC           0 :             ereport(ERROR,
   18574                 :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18575 ECB             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions")));
   18576 EUB             :     }
   18577                 : 
   18578 CBC          88 :     return list_concat(func_args, columns);
   18579                 : }
   18580                 : 
   18581                 : /*
   18582                 :  * Determine return type of a TABLE function.  A single result column
   18583                 :  * returns setof that column's type; otherwise return setof record.
   18584                 :  */
   18585                 : static TypeName *
   18586              88 : TableFuncTypeName(List *columns)
   18587                 : {
   18588                 :     TypeName   *result;
   18589                 : 
   18590              88 :     if (list_length(columns) == 1)
   18591                 :     {
   18592              31 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   18593 EUB             : 
   18594 GIC          31 :         result = copyObject(p->argType);
   18595 ECB             :     }
   18596                 :     else
   18597 GIC          57 :         result = SystemTypeName("record");
   18598                 : 
   18599              88 :     result->setof = true;
   18600                 : 
   18601              88 :     return result;
   18602                 : }
   18603                 : 
   18604 ECB             : /*
   18605                 :  * Convert a list of (dotted) names to a RangeVar (like
   18606                 :  * makeRangeVarFromNameList, but with position support).  The
   18607                 :  * "AnyName" refers to the any_name production in the grammar.
   18608                 :  */
   18609                 : static RangeVar *
   18610 CBC         431 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   18611                 : {
   18612             431 :     RangeVar   *r = makeNode(RangeVar);
   18613 EUB             : 
   18614 GIC         431 :     switch (list_length(names))
   18615                 :     {
   18616 CBC         392 :         case 1:
   18617 GIC         392 :             r->catalogname = NULL;
   18618             392 :             r->schemaname = NULL;
   18619             392 :             r->relname = strVal(linitial(names));
   18620             392 :             break;
   18621              39 :         case 2:
   18622              39 :             r->catalogname = NULL;
   18623              39 :             r->schemaname = strVal(linitial(names));
   18624              39 :             r->relname = strVal(lsecond(names));
   18625              39 :             break;
   18626 LBC           0 :         case 3:
   18627 UIC           0 :             r->catalogname = strVal(linitial(names));
   18628 LBC           0 :             r->schemaname = strVal(lsecond(names));
   18629 UIC           0 :             r->relname = strVal(lthird(names));
   18630               0 :             break;
   18631 LBC           0 :         default:
   18632 UIC           0 :             ereport(ERROR,
   18633 ECB             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   18634                 :                      errmsg("improper qualified name (too many dotted names): %s",
   18635                 :                             NameListToString(names)),
   18636                 :                      parser_errposition(position)));
   18637                 :             break;
   18638                 :     }
   18639                 : 
   18640 GIC         431 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   18641             431 :     r->location = position;
   18642                 : 
   18643             431 :     return r;
   18644                 : }
   18645 ECB             : 
   18646                 : /*
   18647                 :  * Convert a relation_name with name and namelist to a RangeVar using
   18648                 :  * makeRangeVar.
   18649                 :  */
   18650                 : static RangeVar *
   18651 GIC       90692 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   18652                 :                               core_yyscan_t yyscanner)
   18653                 : {
   18654                 :     RangeVar   *r;
   18655                 : 
   18656           90692 :     check_qualified_name(namelist, yyscanner);
   18657 CBC       90692 :     r = makeRangeVar(NULL, NULL, location);
   18658                 : 
   18659 GIC       90692 :     switch (list_length(namelist))
   18660 ECB             :     {
   18661 GIC       90692 :         case 1:
   18662           90692 :             r->catalogname = NULL;
   18663           90692 :             r->schemaname = name;
   18664 CBC       90692 :             r->relname = strVal(linitial(namelist));
   18665 GIC       90692 :             break;
   18666 LBC           0 :         case 2:
   18667 UIC           0 :             r->catalogname = name;
   18668               0 :             r->schemaname = strVal(linitial(namelist));
   18669               0 :             r->relname = strVal(lsecond(namelist));
   18670               0 :             break;
   18671               0 :         default:
   18672 LBC           0 :             ereport(ERROR,
   18673 ECB             :                     errcode(ERRCODE_SYNTAX_ERROR),
   18674                 :                     errmsg("improper qualified name (too many dotted names): %s",
   18675 EUB             :                            NameListToString(lcons(makeString(name), namelist))),
   18676                 :                            parser_errposition(location));
   18677                 :             break;
   18678                 :     }
   18679                 : 
   18680 GIC       90692 :     return r;
   18681 ECB             : }
   18682                 : 
   18683                 : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   18684                 : static void
   18685 CBC       36794 : SplitColQualList(List *qualList,
   18686                 :                  List **constraintList, CollateClause **collClause,
   18687 ECB             :                  core_yyscan_t yyscanner)
   18688                 : {
   18689                 :     ListCell   *cell;
   18690                 : 
   18691 GIC       36794 :     *collClause = NULL;
   18692           46122 :     foreach(cell, qualList)
   18693                 :     {
   18694            9328 :         Node       *n = (Node *) lfirst(cell);
   18695                 : 
   18696            9328 :         if (IsA(n, Constraint))
   18697 ECB             :         {
   18698                 :             /* keep it in list */
   18699 GIC        8455 :             continue;
   18700                 :         }
   18701             873 :         if (IsA(n, CollateClause))
   18702                 :         {
   18703 CBC         873 :             CollateClause *c = (CollateClause *) n;
   18704                 : 
   18705 GIC         873 :             if (*collClause)
   18706 UIC           0 :                 ereport(ERROR,
   18707                 :                         (errcode(ERRCODE_SYNTAX_ERROR),
   18708                 :                          errmsg("multiple COLLATE clauses not allowed"),
   18709 ECB             :                          parser_errposition(c->location)));
   18710 GIC         873 :             *collClause = c;
   18711 ECB             :         }
   18712 EUB             :         else
   18713 UIC           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   18714                 :         /* remove non-Constraint nodes from qualList */
   18715 GIC         873 :         qualList = foreach_delete_current(qualList, cell);
   18716 ECB             :     }
   18717 GIC       36794 :     *constraintList = qualList;
   18718           36794 : }
   18719 ECB             : 
   18720                 : /*
   18721                 :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   18722                 :  * in the output command node.  Pass NULL for any flags the particular
   18723 EUB             :  * command doesn't support.
   18724                 :  */
   18725                 : static void
   18726 GIC       35769 : processCASbits(int cas_bits, int location, const char *constrType,
   18727 ECB             :                bool *deferrable, bool *initdeferred, bool *not_valid,
   18728                 :                bool *no_inherit, core_yyscan_t yyscanner)
   18729                 : {
   18730                 :     /* defaults */
   18731 CBC       35769 :     if (deferrable)
   18732 GBC       35150 :         *deferrable = false;
   18733 GIC       35769 :     if (initdeferred)
   18734           35150 :         *initdeferred = false;
   18735           35769 :     if (not_valid)
   18736 CBC        1257 :         *not_valid = false;
   18737                 : 
   18738           35769 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   18739                 :     {
   18740              79 :         if (deferrable)
   18741 GBC          79 :             *deferrable = true;
   18742                 :         else
   18743 UIC           0 :             ereport(ERROR,
   18744 ECB             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   18745                 :                      /* translator: %s is CHECK, UNIQUE, or similar */
   18746                 :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   18747                 :                             constrType),
   18748                 :                      parser_errposition(location)));
   18749                 :     }
   18750                 : 
   18751 GIC       35769 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   18752 ECB             :     {
   18753 GIC          45 :         if (initdeferred)
   18754 CBC          45 :             *initdeferred = true;
   18755                 :         else
   18756 LBC           0 :             ereport(ERROR,
   18757 ECB             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   18758                 :                      /* translator: %s is CHECK, UNIQUE, or similar */
   18759                 :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   18760                 :                             constrType),
   18761                 :                      parser_errposition(location)));
   18762                 :     }
   18763                 : 
   18764 GIC       35769 :     if (cas_bits & CAS_NOT_VALID)
   18765 ECB             :     {
   18766 GIC         258 :         if (not_valid)
   18767 CBC         258 :             *not_valid = true;
   18768 EUB             :         else
   18769 UIC           0 :             ereport(ERROR,
   18770                 :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   18771                 :                      /* translator: %s is CHECK, UNIQUE, or similar */
   18772 ECB             :                      errmsg("%s constraints cannot be marked NOT VALID",
   18773                 :                             constrType),
   18774                 :                      parser_errposition(location)));
   18775                 :     }
   18776                 : 
   18777 CBC       35769 :     if (cas_bits & CAS_NO_INHERIT)
   18778                 :     {
   18779              53 :         if (no_inherit)
   18780 GIC          53 :             *no_inherit = true;
   18781 ECB             :         else
   18782 LBC           0 :             ereport(ERROR,
   18783 ECB             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   18784                 :                      /* translator: %s is CHECK, UNIQUE, or similar */
   18785                 :                      errmsg("%s constraints cannot be marked NO INHERIT",
   18786                 :                             constrType),
   18787                 :                      parser_errposition(location)));
   18788                 :     }
   18789 GIC       35769 : }
   18790                 : 
   18791                 : /*
   18792                 :  * Parse a user-supplied partition strategy string into parse node
   18793                 :  * PartitionStrategy representation, or die trying.
   18794                 :  */
   18795                 : static PartitionStrategy
   18796 GNC        2190 : parsePartitionStrategy(char *strategy)
   18797                 : {
   18798            2190 :     if (pg_strcasecmp(strategy, "list") == 0)
   18799            1116 :         return PARTITION_STRATEGY_LIST;
   18800            1074 :     else if (pg_strcasecmp(strategy, "range") == 0)
   18801             964 :         return PARTITION_STRATEGY_RANGE;
   18802             110 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   18803             107 :         return PARTITION_STRATEGY_HASH;
   18804                 : 
   18805               3 :     ereport(ERROR,
   18806                 :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   18807                 :              errmsg("unrecognized partitioning strategy \"%s\"",
   18808                 :                     strategy)));
   18809                 :     return PARTITION_STRATEGY_LIST;     /* keep compiler quiet */
   18810                 : 
   18811                 : }
   18812                 : 
   18813                 : /*
   18814 ECB             :  * Process pubobjspec_list to check for errors in any of the objects and
   18815                 :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   18816                 :  */
   18817                 : static void
   18818 GIC         719 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   18819                 : {
   18820                 :     ListCell   *cell;
   18821                 :     PublicationObjSpec *pubobj;
   18822             719 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   18823                 : 
   18824             719 :     if (!pubobjspec_list)
   18825 UIC           0 :         return;
   18826 ECB             : 
   18827 GIC         719 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   18828 CBC         719 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   18829 GIC           6 :         ereport(ERROR,
   18830                 :                 errcode(ERRCODE_SYNTAX_ERROR),
   18831                 :                 errmsg("invalid publication object list"),
   18832                 :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   18833                 :                 parser_errposition(pubobj->location));
   18834                 : 
   18835            1525 :     foreach(cell, pubobjspec_list)
   18836                 :     {
   18837             818 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   18838                 : 
   18839             818 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   18840              80 :             pubobj->pubobjtype = prevobjtype;
   18841                 : 
   18842             818 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   18843                 :         {
   18844                 :             /* relation name or pubtable must be set for this type of object */
   18845             622 :             if (!pubobj->name && !pubobj->pubtable)
   18846 LBC           0 :                 ereport(ERROR,
   18847                 :                         errcode(ERRCODE_SYNTAX_ERROR),
   18848 ECB             :                         errmsg("invalid table name at or near"),
   18849                 :                         parser_errposition(pubobj->location));
   18850                 : 
   18851 GIC         622 :             if (pubobj->name)
   18852                 :             {
   18853 ECB             :                 /* convert it to PublicationTable */
   18854 GIC          28 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   18855 ECB             : 
   18856 GIC          28 :                 pubtable->relation =
   18857 CBC          28 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   18858              28 :                 pubobj->pubtable = pubtable;
   18859 GIC          28 :                 pubobj->name = NULL;
   18860 ECB             :             }
   18861                 :         }
   18862 CBC         196 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   18863              12 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   18864                 :         {
   18865                 :             /* WHERE clause is not allowed on a schema object */
   18866 GIC         196 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   18867 CBC           3 :                 ereport(ERROR,
   18868                 :                         errcode(ERRCODE_SYNTAX_ERROR),
   18869                 :                         errmsg("WHERE clause not allowed for schema"),
   18870                 :                         parser_errposition(pubobj->location));
   18871 ECB             : 
   18872                 :             /* Column list is not allowed on a schema object */
   18873 CBC         193 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   18874 GIC           3 :                 ereport(ERROR,
   18875 ECB             :                         errcode(ERRCODE_SYNTAX_ERROR),
   18876 EUB             :                         errmsg("column specification not allowed for schema"),
   18877 ECB             :                         parser_errposition(pubobj->location));
   18878 EUB             : 
   18879                 :             /*
   18880 ECB             :              * We can distinguish between the different type of schema
   18881                 :              * objects based on whether name and pubtable is set.
   18882                 :              */
   18883 GIC         190 :             if (pubobj->name)
   18884 CBC         178 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   18885 GIC          12 :             else if (!pubobj->name && !pubobj->pubtable)
   18886              12 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   18887 ECB             :             else
   18888 UIC           0 :                 ereport(ERROR,
   18889 ECB             :                         errcode(ERRCODE_SYNTAX_ERROR),
   18890                 :                         errmsg("invalid schema name at or near"),
   18891                 :                         parser_errposition(pubobj->location));
   18892                 :         }
   18893                 : 
   18894 CBC         812 :         prevobjtype = pubobj->pubobjtype;
   18895                 :     }
   18896                 : }
   18897 ECB             : 
   18898                 : /*----------
   18899                 :  * Recursive view transformation
   18900                 :  *
   18901                 :  * Convert
   18902                 :  *
   18903                 :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   18904                 :  *
   18905                 :  * to
   18906                 :  *
   18907                 :  *     CREATE VIEW relname (aliases) AS
   18908                 :  *         WITH RECURSIVE relname (aliases) AS (query)
   18909                 :  *         SELECT aliases FROM relname
   18910                 :  *
   18911                 :  * Actually, just the WITH ... part, which is then inserted into the original
   18912                 :  * view definition as the query.
   18913                 :  * ----------
   18914                 :  */
   18915                 : static Node *
   18916 GIC           7 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   18917                 : {
   18918 CBC           7 :     SelectStmt *s = makeNode(SelectStmt);
   18919 GIC           7 :     WithClause *w = makeNode(WithClause);
   18920 CBC           7 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   18921 GIC           7 :     List       *tl = NIL;
   18922                 :     ListCell   *lc;
   18923                 : 
   18924 ECB             :     /* create common table expression */
   18925 GIC           7 :     cte->ctename = relname;
   18926 CBC           7 :     cte->aliascolnames = aliases;
   18927 GIC           7 :     cte->ctematerialized = CTEMaterializeDefault;
   18928 CBC           7 :     cte->ctequery = query;
   18929               7 :     cte->location = -1;
   18930 ECB             : 
   18931                 :     /* create WITH clause and attach CTE */
   18932 GIC           7 :     w->recursive = true;
   18933               7 :     w->ctes = list_make1(cte);
   18934 CBC           7 :     w->location = -1;
   18935                 : 
   18936                 :     /* create target list for the new SELECT from the alias list of the
   18937 ECB             :      * recursive view specification */
   18938 GIC          14 :     foreach (lc, aliases)
   18939 ECB             :     {
   18940 CBC           7 :         ResTarget *rt = makeNode(ResTarget);
   18941                 : 
   18942 GIC           7 :         rt->name = NULL;
   18943               7 :         rt->indirection = NIL;
   18944               7 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   18945 CBC           7 :         rt->location = -1;
   18946 ECB             : 
   18947 CBC           7 :         tl = lappend(tl, rt);
   18948                 :     }
   18949                 : 
   18950 ECB             :     /* create new SELECT combining WITH clause, target list, and fake FROM
   18951                 :      * clause */
   18952 CBC           7 :     s->withClause = w;
   18953 GIC           7 :     s->targetList = tl;
   18954               7 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   18955                 : 
   18956               7 :     return (Node *) s;
   18957                 : }
   18958                 : 
   18959 ECB             : /* parser_init()
   18960                 :  * Initialize to parse one query string
   18961                 :  */
   18962                 : void
   18963 GIC      498136 : parser_init(base_yy_extra_type *yyext)
   18964 ECB             : {
   18965 GIC      498136 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   18966 CBC      498136 : }
        

Generated by: LCOV version v1.16-55-g56c0a2a