LCOV - code coverage report
Current view: top level - src/backend/parser - gram.y (source / functions) Coverage Total Hit
Test: PostgreSQL 20devel Lines: 91.2 % 7646 6972
Test Date: 2026-09-26 00:15:52 Functions: 100.0 % 42 42
Legend: Lines:     hit not hit
Branches: + taken - not taken # not executed
Branches: 63.0 % 748 471

             Branch data     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-2026, PostgreSQL Global Development Group
      10                 :             :  * Portions Copyright (c) 1994, Regents of the University of California
      11                 :             :  *
      12                 :             :  *
      13                 :             :  * IDENTIFICATION
      14                 :             :  *    src/backend/parser/gram.y
      15                 :             :  *
      16                 :             :  * HISTORY
      17                 :             :  *    AUTHOR            DATE            MAJOR EVENT
      18                 :             :  *    Andrew Yu         Sept, 1994      POSTQUEL to SQL conversion
      19                 :             :  *    Andrew Yu         Oct, 1994       lispy code conversion
      20                 :             :  *
      21                 :             :  * NOTES
      22                 :             :  *    CAPITALS are used to represent terminal symbols.
      23                 :             :  *    non-capitals are used to represent non-terminals.
      24                 :             :  *
      25                 :             :  *    In general, nothing in this file should initiate database accesses
      26                 :             :  *    nor depend on changeable state (such as SET variables).  If you do
      27                 :             :  *    database accesses, your code will fail when we have aborted the
      28                 :             :  *    current transaction and are just parsing commands to find the next
      29                 :             :  *    ROLLBACK or COMMIT.  If you make use of SET variables, then you
      30                 :             :  *    will do the wrong thing in multi-query strings like this:
      31                 :             :  *          SET constraint_exclusion TO off; SELECT * FROM foo;
      32                 :             :  *    because the entire string is parsed by gram.y before the SET gets
      33                 :             :  *    executed.  Anything that depends on the database or changeable state
      34                 :             :  *    should be handled during parse analysis so that it happens at the
      35                 :             :  *    right time not the wrong time.
      36                 :             :  *
      37                 :             :  * WARNINGS
      38                 :             :  *    If you use a list, make sure the datum is a node so that the printing
      39                 :             :  *    routines work.
      40                 :             :  *
      41                 :             :  *    Sometimes we assign constants to makeStrings. Make sure we don't free
      42                 :             :  *    those.
      43                 :             :  *
      44                 :             :  *-------------------------------------------------------------------------
      45                 :             :  */
      46                 :             : #include "postgres.h"
      47                 :             : 
      48                 :             : #include <ctype.h>
      49                 :             : #include <limits.h>
      50                 :             : 
      51                 :             : #include "catalog/index.h"
      52                 :             : #include "catalog/namespace.h"
      53                 :             : #include "catalog/pg_am.h"
      54                 :             : #include "catalog/pg_trigger.h"
      55                 :             : #include "commands/defrem.h"
      56                 :             : #include "commands/trigger.h"
      57                 :             : #include "gramparse.h"
      58                 :             : #include "nodes/makefuncs.h"
      59                 :             : #include "nodes/nodeFuncs.h"
      60                 :             : #include "parser/parser.h"
      61                 :             : #include "utils/datetime.h"
      62                 :             : #include "utils/xml.h"
      63                 :             : 
      64                 :             : 
      65                 :             : /*
      66                 :             :  * Location tracking support.  Unlike bison's default, we only want
      67                 :             :  * to track the start position not the end position of each nonterminal.
      68                 :             :  * Nonterminals that reduce to empty receive position "-1".  Since a
      69                 :             :  * production's leading RHS nonterminal(s) may have reduced to empty,
      70                 :             :  * we have to scan to find the first one that's not -1.
      71                 :             :  */
      72                 :             : #define YYLLOC_DEFAULT(Current, Rhs, N) \
      73                 :             :     do { \
      74                 :             :         (Current) = (-1); \
      75                 :             :         for (int _i = 1; _i <= (N); _i++) \
      76                 :             :         { \
      77                 :             :             if ((Rhs)[_i] >= 0) \
      78                 :             :             { \
      79                 :             :                 (Current) = (Rhs)[_i]; \
      80                 :             :                 break; \
      81                 :             :             } \
      82                 :             :         } \
      83                 :             :     } while (0)
      84                 :             : 
      85                 :             : /*
      86                 :             :  * Bison doesn't allocate anything that needs to live across parser calls,
      87                 :             :  * so we can easily have it use palloc instead of malloc.  This prevents
      88                 :             :  * memory leaks if we error out during parsing.
      89                 :             :  */
      90                 :             : #define YYMALLOC palloc
      91                 :             : #define YYFREE   pfree
      92                 :             : 
      93                 :             : /* Private struct for the result of privilege_target production */
      94                 :             : typedef struct PrivTarget
      95                 :             : {
      96                 :             :     GrantTargetType targtype;
      97                 :             :     ObjectType  objtype;
      98                 :             :     List       *objs;
      99                 :             : } PrivTarget;
     100                 :             : 
     101                 :             : /* Private struct for the result of import_qualification production */
     102                 :             : typedef struct ImportQual
     103                 :             : {
     104                 :             :     ImportForeignSchemaType type;
     105                 :             :     List       *table_names;
     106                 :             : } ImportQual;
     107                 :             : 
     108                 :             : /* Private struct for the result of select_limit & limit_clause productions */
     109                 :             : typedef struct SelectLimit
     110                 :             : {
     111                 :             :     Node       *limitOffset;
     112                 :             :     Node       *limitCount;
     113                 :             :     LimitOption limitOption;    /* indicates presence of WITH TIES */
     114                 :             :     ParseLoc    offsetLoc;      /* location of OFFSET token, if present */
     115                 :             :     ParseLoc    countLoc;       /* location of LIMIT/FETCH token, if present */
     116                 :             :     ParseLoc    optionLoc;      /* location of WITH TIES, if present */
     117                 :             : } SelectLimit;
     118                 :             : 
     119                 :             : /* Private struct for the result of group_clause production */
     120                 :             : typedef struct GroupClause
     121                 :             : {
     122                 :             :     bool        distinct;
     123                 :             :     List       *list;
     124                 :             : } GroupClause;
     125                 :             : 
     126                 :             : /* Private structs for the result of key_actions and key_action productions */
     127                 :             : typedef struct KeyAction
     128                 :             : {
     129                 :             :     char        action;
     130                 :             :     List       *cols;
     131                 :             : } KeyAction;
     132                 :             : 
     133                 :             : typedef struct KeyActions
     134                 :             : {
     135                 :             :     KeyAction *updateAction;
     136                 :             :     KeyAction *deleteAction;
     137                 :             : } KeyActions;
     138                 :             : 
     139                 :             : /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
     140                 :             : #define CAS_NOT_DEFERRABLE          0x01
     141                 :             : #define CAS_DEFERRABLE              0x02
     142                 :             : #define CAS_INITIALLY_IMMEDIATE     0x04
     143                 :             : #define CAS_INITIALLY_DEFERRED      0x08
     144                 :             : #define CAS_NOT_VALID               0x10
     145                 :             : #define CAS_NO_INHERIT              0x20
     146                 :             : #define CAS_NOT_ENFORCED            0x40
     147                 :             : #define CAS_ENFORCED                0x80
     148                 :             : 
     149                 :             : 
     150                 :             : #define parser_yyerror(msg)  scanner_yyerror(msg, yyscanner)
     151                 :             : #define parser_errposition(pos)  scanner_errposition(pos, yyscanner)
     152                 :             : 
     153                 :             : static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
     154                 :             :                          const char *msg);
     155                 :             : static RawStmt *makeRawStmt(Node *stmt, int stmt_location);
     156                 :             : static void updateRawStmtEnd(RawStmt *rs, int end_location);
     157                 :             : static Node *makeColumnRef(char *colname, List *indirection,
     158                 :             :                            int location, core_yyscan_t yyscanner);
     159                 :             : static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
     160                 :             : static Node *makeStringConstCast(char *str, int location, TypeName *typename);
     161                 :             : static Node *makeIntConst(int val, int location);
     162                 :             : static Node *makeFloatConst(char *str, int location);
     163                 :             : static Node *makeBoolAConst(bool state, int location);
     164                 :             : static Node *makeBitStringConst(char *str, int location);
     165                 :             : static Node *makeNullAConst(int location);
     166                 :             : static Node *makeAConst(Node *v, int location);
     167                 :             : static RoleSpec *makeRoleSpec(RoleSpecType type, int location);
     168                 :             : static void check_qualified_name(List *names, core_yyscan_t yyscanner);
     169                 :             : static List *check_func_name(List *names, core_yyscan_t yyscanner);
     170                 :             : static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
     171                 :             : static List *extractArgTypes(List *parameters);
     172                 :             : static List *extractAggrArgTypes(List *aggrargs);
     173                 :             : static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
     174                 :             :                                 core_yyscan_t yyscanner);
     175                 :             : static void insertSelectOptions(SelectStmt *stmt,
     176                 :             :                                 List *sortClause, List *lockingClause,
     177                 :             :                                 SelectLimit *limitClause,
     178                 :             :                                 WithClause *withClause,
     179                 :             :                                 core_yyscan_t yyscanner);
     180                 :             : static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
     181                 :             : static Node *doNegate(Node *n, int location);
     182                 :             : static void doNegateFloat(Float *v);
     183                 :             : static Node *makeAndExpr(Node *lexpr, Node *rexpr, int location);
     184                 :             : static Node *makeOrExpr(Node *lexpr, Node *rexpr, int location);
     185                 :             : static Node *makeNotExpr(Node *expr, int location);
     186                 :             : static Node *makeAArrayExpr(List *elements, int location, int location_end);
     187                 :             : static Node *makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod,
     188                 :             :                                   int location);
     189                 :             : static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
     190                 :             :                          List *args, int location);
     191                 :             : static List *mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner);
     192                 :             : static TypeName *TableFuncTypeName(List *columns);
     193                 :             : static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
     194                 :             : static RangeVar *makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
     195                 :             :                                                core_yyscan_t yyscanner);
     196                 :             : static void SplitColQualList(List *qualList,
     197                 :             :                              List **constraintList, CollateClause **collClause,
     198                 :             :                              core_yyscan_t yyscanner);
     199                 :             : static void processCASbits(int cas_bits, int location, const char *constrType,
     200                 :             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
     201                 :             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner);
     202                 :             : static PartitionStrategy parsePartitionStrategy(char *strategy, int location,
     203                 :             :                                                 core_yyscan_t yyscanner);
     204                 :             : static void preprocess_pub_all_objtype_list(List *all_objects_list,
     205                 :             :                                             List **pubobjects,
     206                 :             :                                             bool *all_tables,
     207                 :             :                                             bool *all_sequences,
     208                 :             :                                             core_yyscan_t yyscanner);
     209                 :             : static void preprocess_pubobj_list(List *pubobjspec_list,
     210                 :             :                                    core_yyscan_t yyscanner);
     211                 :             : static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
     212                 :             : 
     213                 :             : %}
     214                 :             : 
     215                 :             : %pure-parser
     216                 :             : %expect 0
     217                 :             : %name-prefix="base_yy"
     218                 :             : %locations
     219                 :             : 
     220                 :             : %parse-param {core_yyscan_t yyscanner}
     221                 :             : %lex-param   {core_yyscan_t yyscanner}
     222                 :             : 
     223                 :             : %union
     224                 :             : {
     225                 :             :     core_YYSTYPE core_yystype;
     226                 :             :     /* these fields must match core_YYSTYPE: */
     227                 :             :     int         ival;
     228                 :             :     char       *str;
     229                 :             :     const char *keyword;
     230                 :             : 
     231                 :             :     char        chr;
     232                 :             :     bool        boolean;
     233                 :             :     JoinType    jtype;
     234                 :             :     DropBehavior dbehavior;
     235                 :             :     OnCommitAction oncommit;
     236                 :             :     List       *list;
     237                 :             :     Node       *node;
     238                 :             :     ObjectType  objtype;
     239                 :             :     TypeName   *typnam;
     240                 :             :     FunctionParameter *fun_param;
     241                 :             :     FunctionParameterMode fun_param_mode;
     242                 :             :     ObjectWithArgs *objwithargs;
     243                 :             :     DefElem    *defelt;
     244                 :             :     SortBy     *sortby;
     245                 :             :     WindowDef  *windef;
     246                 :             :     JoinExpr   *jexpr;
     247                 :             :     IndexElem  *ielem;
     248                 :             :     StatsElem  *selem;
     249                 :             :     Alias      *alias;
     250                 :             :     RangeVar   *range;
     251                 :             :     IntoClause *into;
     252                 :             :     WithClause *with;
     253                 :             :     InferClause *infer;
     254                 :             :     OnConflictClause *onconflict;
     255                 :             :     A_Indices  *aind;
     256                 :             :     ResTarget  *target;
     257                 :             :     struct PrivTarget *privtarget;
     258                 :             :     AccessPriv *accesspriv;
     259                 :             :     struct ImportQual *importqual;
     260                 :             :     InsertStmt *istmt;
     261                 :             :     VariableSetStmt *vsetstmt;
     262                 :             :     PartitionElem *partelem;
     263                 :             :     PartitionSpec *partspec;
     264                 :             :     PartitionBoundSpec *partboundspec;
     265                 :             :     RoleSpec   *rolespec;
     266                 :             :     PublicationObjSpec *publicationobjectspec;
     267                 :             :     PublicationAllObjSpec *publicationallobjectspec;
     268                 :             :     struct SelectLimit *selectlimit;
     269                 :             :     SetQuantifier setquantifier;
     270                 :             :     struct GroupClause *groupclause;
     271                 :             :     MergeMatchKind mergematch;
     272                 :             :     MergeWhenClause *mergewhen;
     273                 :             :     struct KeyActions *keyactions;
     274                 :             :     struct KeyAction *keyaction;
     275                 :             :     ReturningClause *retclause;
     276                 :             :     ReturningOptionKind retoptionkind;
     277                 :             : }
     278                 :             : 
     279                 :             : %type <node>  stmt toplevel_stmt schema_stmt routine_body_stmt
     280                 :             :         AlterEventTrigStmt AlterCollationStmt
     281                 :             :         AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
     282                 :             :         AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
     283                 :             :         AlterObjectDependsStmt AlterObjectSchemaStmt AlterOwnerStmt
     284                 :             :         AlterOperatorStmt AlterTypeStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
     285                 :             :         AlterTblSpcStmt AlterExtensionStmt AlterExtensionContentsStmt
     286                 :             :         AlterCompositeTypeStmt AlterUserMappingStmt
     287                 :             :         AlterRoleStmt AlterRoleSetStmt AlterPolicyStmt AlterStatsStmt
     288                 :             :         AlterDefaultPrivilegesStmt DefACLAction
     289                 :             :         AnalyzeStmt CallStmt ClosePortalStmt CommentStmt
     290                 :             :         ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
     291                 :             :         CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
     292                 :             :         CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
     293                 :             :         CreateSchemaStmt CreateSeqStmt CreateStmt CreateStatsStmt CreateTableSpaceStmt
     294                 :             :         CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
     295                 :             :         CreateAssertionStmt CreateTransformStmt CreateTrigStmt CreateEventTrigStmt
     296                 :             :         CreateUserStmt CreateUserMappingStmt CreateRoleStmt CreatePolicyStmt
     297                 :             :         CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
     298                 :             :         DropOpClassStmt DropOpFamilyStmt DropStmt
     299                 :             :         DropCastStmt DropRoleStmt
     300                 :             :         DropdbStmt DropTableSpaceStmt
     301                 :             :         DropTransformStmt
     302                 :             :         DropUserMappingStmt ExplainStmt FetchStmt
     303                 :             :         GrantStmt GrantRoleStmt ImportForeignSchemaStmt IndexStmt InsertStmt
     304                 :             :         ListenStmt LoadStmt LockStmt MergeStmt NotifyStmt ExplainableStmt PreparableStmt
     305                 :             :         CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
     306                 :             :         RemoveFuncStmt RemoveOperStmt RenameStmt RepackStmt ReturnStmt RevokeStmt RevokeRoleStmt
     307                 :             :         RuleActionStmt RuleActionStmtOrEmpty RuleStmt
     308                 :             :         SecLabelStmt SelectStmt TransactionStmt TransactionStmtLegacy TruncateStmt
     309                 :             :         UnlistenStmt UpdateStmt VacuumStmt
     310                 :             :         VariableResetStmt VariableSetStmt VariableShowStmt
     311                 :             :         ViewStmt WaitStmt CheckPointStmt CreateConversionStmt
     312                 :             :         DeallocateStmt PrepareStmt ExecuteStmt
     313                 :             :         DropOwnedStmt ReassignOwnedStmt
     314                 :             :         AlterTSConfigurationStmt AlterTSDictionaryStmt
     315                 :             :         CreateMatViewStmt RefreshMatViewStmt CreateAmStmt
     316                 :             :         CreatePublicationStmt AlterPublicationStmt
     317                 :             :         CreateSubscriptionStmt AlterSubscriptionStmt DropSubscriptionStmt
     318                 :             : 
     319                 :             : %type <node>  select_no_parens select_with_parens select_clause
     320                 :             :                 simple_select values_clause
     321                 :             :                 PLpgSQL_Expr PLAssignStmt
     322                 :             : 
     323                 :             : %type <str>           opt_single_name
     324                 :             : %type <list>      opt_qualified_name
     325                 :             : %type <boolean>       opt_concurrently opt_usingindex
     326                 :             : %type <dbehavior> opt_drop_behavior
     327                 :             : %type <list>      opt_utility_option_list
     328                 :             : %type <list>      opt_wait_with_clause
     329                 :             : %type <list>      utility_option_list
     330                 :             : %type <defelt>        utility_option_elem
     331                 :             : %type <str>           utility_option_name
     332                 :             : %type <node>      utility_option_arg
     333                 :             : 
     334                 :             : %type <node>  alter_column_default opclass_item opclass_drop alter_using
     335                 :             : %type <ival>  add_drop opt_asc_desc opt_nulls_order
     336                 :             : 
     337                 :             : %type <node>  alter_table_cmd alter_type_cmd opt_collate_clause
     338                 :             :        replica_identity partition_cmd index_partition_cmd
     339                 :             : %type <list>  alter_table_cmds alter_type_cmds
     340                 :             : %type <list>    alter_identity_column_option_list
     341                 :             : %type <defelt>  alter_identity_column_option
     342                 :             : %type <node>  set_statistics_value
     343                 :             : %type <str>       set_access_method_name
     344                 :             : 
     345                 :             : %type <list>  createdb_opt_list createdb_opt_items copy_opt_list
     346                 :             :                 transaction_mode_list
     347                 :             :                 create_extension_opt_list alter_extension_opt_list
     348                 :             : %type <defelt>    createdb_opt_item copy_opt_item
     349                 :             :                 transaction_mode_item
     350                 :             :                 create_extension_opt_item alter_extension_opt_item
     351                 :             : 
     352                 :             : %type <ival>  opt_lock lock_type cast_context
     353                 :             : %type <defelt>    drop_option
     354                 :             : %type <boolean>   opt_or_replace opt_no
     355                 :             :                 opt_grant_grant_option
     356                 :             :                 opt_nowait opt_if_exists opt_with_data
     357                 :             :                 opt_transaction_chain
     358                 :             : %type <list>  grant_role_opt_list
     359                 :             : %type <defelt>    grant_role_opt
     360                 :             : %type <node>  grant_role_opt_value
     361                 :             : %type <ival>  opt_nowait_or_skip
     362                 :             : 
     363                 :             : %type <list>  OptRoleList AlterOptRoleList
     364                 :             : %type <defelt>    CreateOptRoleElem AlterOptRoleElem
     365                 :             : 
     366                 :             : %type <str>       opt_type
     367                 :             : %type <str>       foreign_server_version opt_foreign_server_version
     368                 :             : %type <str>       opt_in_database
     369                 :             : 
     370                 :             : %type <str>       parameter_name
     371                 :             : %type <list>  OptSchemaEltList parameter_name_list
     372                 :             : 
     373                 :             : %type <chr>       am_type
     374                 :             : 
     375                 :             : %type <boolean> TriggerForSpec TriggerForType
     376                 :             : %type <ival>  TriggerActionTime
     377                 :             : %type <list>  TriggerEvents TriggerOneEvent
     378                 :             : %type <node>  TriggerFuncArg
     379                 :             : %type <node>  TriggerWhen
     380                 :             : %type <str>       TransitionRelName
     381                 :             : %type <boolean>   TransitionRowOrTable TransitionOldOrNew
     382                 :             : %type <node>  TriggerTransition
     383                 :             : 
     384                 :             : %type <list>  event_trigger_when_list event_trigger_value_list
     385                 :             : %type <defelt>    event_trigger_when_item
     386                 :             : %type <chr>       enable_trigger
     387                 :             : 
     388                 :             : %type <str>       copy_file_name
     389                 :             :                 access_method_clause attr_name
     390                 :             :                 table_access_method_clause name cursor_name file_name
     391                 :             :                 cluster_index_specification
     392                 :             : 
     393                 :             : %type <list>  func_name handler_name qual_Op qual_all_Op subquery_Op
     394                 :             :                 opt_inline_handler opt_validator validator_clause
     395                 :             :                 opt_collate
     396                 :             : 
     397                 :             : %type <range> qualified_name insert_target OptConstrFromTable
     398                 :             : 
     399                 :             : %type <str>       all_Op MathOp
     400                 :             : 
     401                 :             : %type <str>       row_security_cmd RowSecurityDefaultForCmd
     402                 :             : %type <boolean> RowSecurityDefaultPermissive
     403                 :             : %type <node>  RowSecurityOptionalWithCheck RowSecurityOptionalExpr
     404                 :             : %type <list>  RowSecurityDefaultToRole RowSecurityOptionalToRole
     405                 :             : 
     406                 :             : %type <str>       iso_level opt_encoding
     407                 :             : %type <rolespec> grantee
     408                 :             : %type <list>  grantee_list
     409                 :             : %type <accesspriv> privilege
     410                 :             : %type <list>  privileges privilege_list
     411                 :             : %type <privtarget> privilege_target
     412                 :             : %type <objwithargs> function_with_argtypes aggregate_with_argtypes operator_with_argtypes
     413                 :             : %type <list>  function_with_argtypes_list aggregate_with_argtypes_list operator_with_argtypes_list
     414                 :             : %type <ival>  defacl_privilege_target
     415                 :             : %type <defelt>    DefACLOption
     416                 :             : %type <list>  DefACLOptionList
     417                 :             : %type <ival>  import_qualification_type
     418                 :             : %type <importqual> import_qualification
     419                 :             : %type <node>  vacuum_relation
     420                 :             : %type <selectlimit> opt_select_limit select_limit limit_clause
     421                 :             : 
     422                 :             : %type <list>  parse_toplevel stmtmulti routine_body_stmt_list
     423                 :             :                 OptTableElementList TableElementList OptInherit definition
     424                 :             :                 OptTypedTableElementList TypedTableElementList
     425                 :             :                 reloptions opt_reloptions
     426                 :             :                 OptWith opt_definition func_args func_args_list
     427                 :             :                 func_args_with_defaults func_args_with_defaults_list
     428                 :             :                 aggr_args aggr_args_list
     429                 :             :                 func_as createfunc_opt_list opt_createfunc_opt_list alterfunc_opt_list
     430                 :             :                 old_aggr_definition old_aggr_list
     431                 :             :                 oper_argtypes RuleActionList RuleActionMulti
     432                 :             :                 opt_column_list columnList opt_name_list
     433                 :             :                 sort_clause opt_sort_clause sortby_list index_params
     434                 :             :                 stats_params
     435                 :             :                 opt_include opt_c_include index_including_params
     436                 :             :                 name_list role_list from_clause from_list opt_array_bounds
     437                 :             :                 qualified_name_list any_name any_name_list type_name_list
     438                 :             :                 any_operator expr_list attrs
     439                 :             :                 distinct_clause opt_distinct_clause
     440                 :             :                 target_list opt_target_list insert_column_list set_target_list
     441                 :             :                 merge_values_clause
     442                 :             :                 set_clause_list set_clause
     443                 :             :                 def_list operator_def_list indirection opt_indirection
     444                 :             :                 reloption_list TriggerFuncArgs opclass_item_list opclass_drop_list
     445                 :             :                 opclass_purpose opt_opfamily transaction_mode_list_or_empty
     446                 :             :                 OptTableFuncElementList TableFuncElementList opt_type_modifiers
     447                 :             :                 prep_type_clause
     448                 :             :                 execute_param_clause using_clause
     449                 :             :                 returning_with_clause returning_options
     450                 :             :                 opt_enum_val_list enum_val_list table_func_column_list
     451                 :             :                 create_generic_options alter_generic_options
     452                 :             :                 relation_expr_list dostmt_opt_list
     453                 :             :                 transform_element_list transform_type_list
     454                 :             :                 TriggerTransitions TriggerReferencing
     455                 :             :                 vacuum_relation_list opt_vacuum_relation_list
     456                 :             :                 drop_option_list pub_obj_list pub_all_obj_type_list
     457                 :             :                 pub_except_obj_list opt_pub_except_clause
     458                 :             : 
     459                 :             : %type <retclause> returning_clause
     460                 :             : %type <node>  returning_option
     461                 :             : %type <retoptionkind> returning_option_kind
     462                 :             : %type <node>  opt_routine_body
     463                 :             : %type <groupclause> group_clause
     464                 :             : %type <list>  group_by_list
     465                 :             : %type <node>  group_by_item empty_grouping_set rollup_clause cube_clause
     466                 :             : %type <node>  grouping_sets_clause
     467                 :             : 
     468                 :             : %type <list>  opt_fdw_options fdw_options
     469                 :             : %type <defelt>    fdw_option
     470                 :             : 
     471                 :             : %type <range> OptTempTableName
     472                 :             : %type <into>  into_clause create_as_target create_mv_target
     473                 :             : 
     474                 :             : %type <defelt>    createfunc_opt_item common_func_opt_item dostmt_opt_item
     475                 :             : %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
     476                 :             : %type <fun_param_mode> arg_class
     477                 :             : %type <typnam>    func_return func_type
     478                 :             : 
     479                 :             : %type <boolean>  opt_trusted opt_restart_seqs
     480                 :             : %type <ival>   OptTemp
     481                 :             : %type <ival>   OptNoLog
     482                 :             : %type <oncommit> OnCommitOption
     483                 :             : 
     484                 :             : %type <ival>  for_locking_strength opt_for_locking_strength
     485                 :             : %type <node>  for_locking_item
     486                 :             : %type <list>  for_locking_clause opt_for_locking_clause for_locking_items
     487                 :             : %type <list>  locked_rels_list
     488                 :             : %type <setquantifier> set_quantifier
     489                 :             : 
     490                 :             : %type <node>  join_qual
     491                 :             : %type <jtype> join_type
     492                 :             : 
     493                 :             : %type <list>  extract_list overlay_list position_list
     494                 :             : %type <list>  substr_list trim_list
     495                 :             : %type <list>  opt_interval interval_second
     496                 :             : %type <str>       unicode_normal_form
     497                 :             : 
     498                 :             : %type <boolean> opt_instead
     499                 :             : %type <boolean> opt_unique opt_verbose opt_full
     500                 :             : %type <boolean> opt_freeze opt_analyze opt_default
     501                 :             : %type <defelt>    opt_binary copy_delimiter
     502                 :             : 
     503                 :             : %type <boolean> copy_from opt_program
     504                 :             : 
     505                 :             : %type <ival>  event cursor_options opt_hold opt_set_data
     506                 :             : %type <objtype>   object_type_any_name object_type_name object_type_name_on_any_name
     507                 :             :                 drop_type_name
     508                 :             : 
     509                 :             : %type <node>  fetch_args select_limit_value
     510                 :             :                 offset_clause select_offset_value
     511                 :             :                 select_fetch_first_value I_or_F_const
     512                 :             : %type <ival>  row_or_rows first_or_next
     513                 :             : 
     514                 :             : %type <list>  OptSeqOptList SeqOptList OptParenthesizedSeqOptList
     515                 :             : %type <defelt>    SeqOptElem
     516                 :             : 
     517                 :             : %type <istmt> insert_rest
     518                 :             : %type <infer> opt_conf_expr
     519                 :             : %type <onconflict> opt_on_conflict
     520                 :             : %type <mergewhen> merge_insert merge_update merge_delete
     521                 :             : 
     522                 :             : %type <mergematch> merge_when_tgt_matched merge_when_tgt_not_matched
     523                 :             : %type <node>  merge_when_clause opt_merge_when_condition
     524                 :             : %type <list>  merge_when_list
     525                 :             : 
     526                 :             : %type <vsetstmt> generic_set set_rest set_rest_more generic_reset reset_rest
     527                 :             :                  SetResetClause FunctionSetResetClause
     528                 :             : 
     529                 :             : %type <node>  TableElement TypedTableElement ConstraintElem DomainConstraintElem TableFuncElement
     530                 :             : %type <node>  columnDef columnOptions optionalPeriodName
     531                 :             : %type <defelt>    def_elem reloption_elem old_aggr_elem operator_def_elem
     532                 :             : %type <node>  def_arg columnElem where_clause where_or_current_clause
     533                 :             :                 a_expr b_expr c_expr AexprConst indirection_el opt_slice_bound
     534                 :             :                 columnref having_clause func_table xmltable array_expr
     535                 :             :                 OptWhereClause operator_def_arg
     536                 :             : %type <list>  opt_column_and_period_list
     537                 :             : %type <list>  rowsfrom_item rowsfrom_list opt_col_def_list
     538                 :             : %type <boolean> opt_ordinality opt_without_overlaps
     539                 :             : %type <list>  ExclusionConstraintList ExclusionConstraintElem
     540                 :             : %type <list>  func_arg_list func_arg_list_opt
     541                 :             : %type <node>  func_arg_expr
     542                 :             : %type <list>  row explicit_row implicit_row type_list array_expr_list
     543                 :             : %type <node>  case_expr case_arg when_clause case_default
     544                 :             : %type <list>  when_clause_list
     545                 :             : %type <node>  opt_search_clause opt_cycle_clause
     546                 :             : %type <ival>  sub_type opt_materialized
     547                 :             : %type <node>  NumericOnly
     548                 :             : %type <list>  NumericOnly_list
     549                 :             : %type <alias> alias_clause opt_alias_clause opt_alias_clause_for_join_using
     550                 :             : %type <list>  func_alias_clause
     551                 :             : %type <sortby>    sortby
     552                 :             : %type <ielem> index_elem index_elem_options
     553                 :             : %type <selem> stats_param
     554                 :             : %type <node>  table_ref
     555                 :             : %type <jexpr> joined_table
     556                 :             : %type <range> relation_expr
     557                 :             : %type <range> extended_relation_expr
     558                 :             : %type <range> relation_expr_opt_alias
     559                 :             : %type <node>  tablesample_clause opt_repeatable_clause
     560                 :             : %type <target>    target_el set_target insert_column_item
     561                 :             : 
     562                 :             : %type <str>       generic_option_name
     563                 :             : %type <node>  generic_option_arg
     564                 :             : %type <defelt>    generic_option_elem alter_generic_option_elem
     565                 :             : %type <list>  generic_option_list alter_generic_option_list
     566                 :             : 
     567                 :             : %type <ival>  reindex_target_relation reindex_target_all
     568                 :             : 
     569                 :             : %type <node>  copy_generic_opt_arg copy_generic_opt_arg_list_item
     570                 :             : %type <defelt>    copy_generic_opt_elem
     571                 :             : %type <list>  copy_generic_opt_list copy_generic_opt_arg_list
     572                 :             : %type <list>  copy_options
     573                 :             : 
     574                 :             : %type <typnam>    Typename SimpleTypename ConstTypename
     575                 :             :                 GenericType Numeric opt_float JsonType
     576                 :             :                 Character ConstCharacter
     577                 :             :                 CharacterWithLength CharacterWithoutLength
     578                 :             :                 ConstDatetime ConstInterval
     579                 :             :                 Bit ConstBit BitWithLength BitWithoutLength
     580                 :             : %type <str>       character
     581                 :             : %type <str>       extract_arg
     582                 :             : %type <boolean> opt_varying opt_timezone opt_no_inherit
     583                 :             : 
     584                 :             : %type <ival>  Iconst SignedIconst
     585                 :             : %type <str>       Sconst comment_text notify_payload
     586                 :             : %type <str>       RoleId opt_boolean_or_string
     587                 :             : %type <list>  var_list
     588                 :             : %type <str>       ColId ColLabel BareColLabel
     589                 :             : %type <str>       NonReservedWord NonReservedWord_or_Sconst
     590                 :             : %type <str>       var_name type_function_name param_name
     591                 :             : %type <str>       createdb_opt_name plassign_target
     592                 :             : %type <node>  var_value zone_value
     593                 :             : %type <rolespec> auth_ident RoleSpec opt_granted_by
     594                 :             : %type <publicationobjectspec> PublicationObjSpec
     595                 :             : %type <publicationobjectspec> PublicationExceptObjSpec
     596                 :             : %type <publicationallobjectspec> PublicationAllObjSpec
     597                 :             : 
     598                 :             : %type <keyword> unreserved_keyword type_func_name_keyword
     599                 :             : %type <keyword> col_name_keyword reserved_keyword
     600                 :             : %type <keyword> bare_label_keyword
     601                 :             : 
     602                 :             : %type <node>  DomainConstraint TableConstraint TableLikeClause
     603                 :             : %type <ival>  TableLikeOptionList TableLikeOption
     604                 :             : %type <str>       column_compression opt_column_compression column_storage opt_column_storage
     605                 :             : %type <list>  ColQualList
     606                 :             : %type <node>  ColConstraint ColConstraintElem ConstraintAttr
     607                 :             : %type <ival>  key_match
     608                 :             : %type <keyaction> key_delete key_update key_action
     609                 :             : %type <keyactions> key_actions
     610                 :             : %type <ival>  ConstraintAttributeSpec ConstraintAttributeElem
     611                 :             : %type <str>       ExistingIndex
     612                 :             : 
     613                 :             : %type <list>  constraints_set_list
     614                 :             : %type <boolean> constraints_set_mode
     615                 :             : %type <str>       OptTableSpace OptConsTableSpace
     616                 :             : %type <rolespec> OptTableSpaceOwner
     617                 :             : %type <ival>  opt_check_option
     618                 :             : 
     619                 :             : %type <str>       opt_provider security_label
     620                 :             : 
     621                 :             : %type <target>    labeled_expr
     622                 :             : %type <list>  labeled_expr_list xml_attributes
     623                 :             : %type <node>  xml_root_version opt_xml_root_standalone
     624                 :             : %type <node>  xmlexists_argument
     625                 :             : %type <ival>  document_or_content
     626                 :             : %type <boolean>   xml_indent_option xml_whitespace_option
     627                 :             : %type <list>  xmltable_column_list xmltable_column_option_list
     628                 :             : %type <node>  xmltable_column_el
     629                 :             : %type <defelt>    xmltable_column_option_el
     630                 :             : %type <list>  xml_namespace_list
     631                 :             : %type <target>    xml_namespace_el
     632                 :             : 
     633                 :             : %type <node>  func_application func_expr_common_subexpr
     634                 :             : %type <node>  func_expr func_expr_windowless
     635                 :             : %type <node>  common_table_expr
     636                 :             : %type <with>  with_clause opt_with_clause
     637                 :             : %type <list>  cte_list
     638                 :             : 
     639                 :             : %type <list>  within_group_clause
     640                 :             : %type <node>  filter_clause
     641                 :             : %type <list>  window_clause window_definition_list opt_partition_clause
     642                 :             : %type <windef>    window_definition over_clause window_specification
     643                 :             :                 opt_frame_clause frame_extent frame_bound
     644                 :             : %type <ival>  null_treatment opt_window_exclusion_clause
     645                 :             : %type <str>       opt_existing_window_name
     646                 :             : %type <boolean> opt_if_not_exists
     647                 :             : %type <boolean> opt_unique_null_treatment
     648                 :             : %type <ival>  generated_when override_kind opt_virtual_or_stored
     649                 :             : %type <partspec>  PartitionSpec OptPartitionSpec
     650                 :             : %type <partelem>  part_elem
     651                 :             : %type <list>      part_params
     652                 :             : %type <partboundspec> PartitionBoundSpec
     653                 :             : %type <list>      hash_partbound
     654                 :             : %type <defelt>        hash_partbound_elem
     655                 :             : 
     656                 :             : %type <node>  json_format_clause
     657                 :             :                 json_format_clause_opt
     658                 :             :                 json_value_expr
     659                 :             :                 json_returning_clause_opt
     660                 :             :                 json_name_and_value
     661                 :             :                 json_aggregate_func
     662                 :             :                 json_argument
     663                 :             :                 json_behavior
     664                 :             :                 json_on_error_clause_opt
     665                 :             :                 json_table
     666                 :             :                 json_table_column_definition
     667                 :             :                 json_table_column_path_clause_opt
     668                 :             :                 json_table_plan_clause_opt
     669                 :             :                 json_table_plan
     670                 :             :                 json_table_plan_simple
     671                 :             :                 json_table_plan_outer
     672                 :             :                 json_table_plan_inner
     673                 :             :                 json_table_plan_union
     674                 :             :                 json_table_plan_cross
     675                 :             :                 json_table_plan_primary
     676                 :             : %type <list>  json_name_and_value_list
     677                 :             :                 json_value_expr_list
     678                 :             :                 json_array_aggregate_order_by_clause_opt
     679                 :             :                 json_arguments
     680                 :             :                 json_behavior_clause_opt
     681                 :             :                 json_passing_clause_opt
     682                 :             :                 json_table_column_definition_list
     683                 :             : %type <str>       json_table_path_name_opt
     684                 :             : %type <ival>  json_behavior_type
     685                 :             :                 json_predicate_type_constraint
     686                 :             :                 json_quotes_clause_opt
     687                 :             :                 json_table_default_plan_choices
     688                 :             :                 json_table_default_plan_inner_outer
     689                 :             :                 json_table_default_plan_union_cross
     690                 :             :                 json_wrapper_behavior
     691                 :             : %type <boolean>   json_key_uniqueness_constraint_opt
     692                 :             :                 json_object_constructor_null_clause_opt
     693                 :             :                 json_array_constructor_null_clause_opt
     694                 :             : 
     695                 :             : /*
     696                 :             :  * Non-keyword token types.  These are hard-wired into the "flex" lexer.
     697                 :             :  * They must be listed first so that their numeric codes do not depend on
     698                 :             :  * the set of keywords.  PL/pgSQL depends on this so that it can share the
     699                 :             :  * same lexer.  If you add/change tokens here, fix PL/pgSQL to match!
     700                 :             :  *
     701                 :             :  * UIDENT and USCONST are reduced to IDENT and SCONST in parser.c, so that
     702                 :             :  * they need no productions here; but we must assign token codes to them.
     703                 :             :  *
     704                 :             :  * DOT_DOT is unused in the core SQL grammar, and so will always provoke
     705                 :             :  * parse errors.  It is needed by PL/pgSQL.
     706                 :             :  */
     707                 :             : %token <str>  IDENT UIDENT FCONST SCONST USCONST BCONST XCONST Op
     708                 :             : %token <ival> ICONST PARAM
     709                 :             : %token          TYPECAST DOT_DOT COLON_EQUALS EQUALS_GREATER
     710                 :             : %token          LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     711                 :             : 
     712                 :             : /*
     713                 :             :  * If you want to make any keyword changes, update the keyword table in
     714                 :             :  * src/include/parser/kwlist.h and add new keywords to the appropriate one
     715                 :             :  * of the reserved-or-not-so-reserved keyword lists, below; search
     716                 :             :  * this file for "Keyword category lists".
     717                 :             :  */
     718                 :             : 
     719                 :             : /* ordinary key words in alphabetical order */
     720                 :             : %token <keyword> ABORT_P ABSENT ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
     721                 :             :     AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
     722                 :             :     ASENSITIVE ASSERTION ASSIGNMENT ASYMMETRIC ATOMIC AT ATTACH ATTRIBUTE AUTHORIZATION
     723                 :             : 
     724                 :             :     BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
     725                 :             :     BOOLEAN_P BOTH BREADTH BY
     726                 :             : 
     727                 :             :     CACHE CALL CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
     728                 :             :     CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
     729                 :             :     CLUSTER COALESCE COLLATE COLLATION COLUMN COLUMNS COMMENT COMMENTS COMMIT
     730                 :             :     COMMITTED COMPRESSION CONCURRENTLY CONDITIONAL CONFIGURATION CONFLICT
     731                 :             :     CONNECTION CONSTRAINT CONSTRAINTS CONTENT_P CONTINUE_P CONVERSION_P COPY
     732                 :             :     COST CREATE CROSS CSV CUBE CURRENT_P
     733                 :             :     CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
     734                 :             :     CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
     735                 :             : 
     736                 :             :     DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
     737                 :             :     DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DEPENDS DEPTH DESC
     738                 :             :     DETACH DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P
     739                 :             :     DOUBLE_P DROP
     740                 :             : 
     741                 :             :     EACH ELSE EMPTY_P ENABLE_P ENCODING ENCRYPTED END_P ENFORCED ENUM_P ERROR_P
     742                 :             :     ESCAPE EVENT EXCEPT EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
     743                 :             :     EXPRESSION EXTENSION EXTERNAL EXTRACT
     744                 :             : 
     745                 :             :     FALSE_P FAMILY FETCH FILTER FINALIZE FIRST_P FLOAT_P FOLLOWING FOR
     746                 :             :     FORCE FOREIGN FORMAT FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
     747                 :             : 
     748                 :             :     GENERATED GLOBAL GRANT GRANTED GREATEST GROUP_P GROUPING GROUPS
     749                 :             : 
     750                 :             :     HANDLER HAVING HEADER_P HOLD HOUR_P
     751                 :             : 
     752                 :             :     IDENTITY_P IF_P IGNORE_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IMPORT_P IN_P INCLUDE
     753                 :             :     INCLUDING INCREMENT INDENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
     754                 :             :     INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
     755                 :             :     INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
     756                 :             : 
     757                 :             :     JOIN JSON JSON_ARRAY JSON_ARRAYAGG JSON_EXISTS JSON_OBJECT JSON_OBJECTAGG
     758                 :             :     JSON_QUERY JSON_SCALAR JSON_SERIALIZE JSON_TABLE JSON_VALUE
     759                 :             : 
     760                 :             :     KEEP KEY KEYS
     761                 :             : 
     762                 :             :     LABEL LANGUAGE LARGE_P LAST_P LATERAL_P
     763                 :             :     LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
     764                 :             :     LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P LOCKED LOGGED LSN_P
     765                 :             : 
     766                 :             :     MAPPING MATCH MATCHED MATERIALIZED MAXVALUE MERGE MERGE_ACTION METHOD
     767                 :             :     MINUTE_P MINVALUE MODE MONTH_P MOVE
     768                 :             : 
     769                 :             :     NAME_P NAMES NATIONAL NATURAL NCHAR NESTED NEW NEXT NFC NFD NFKC NFKD NO
     770                 :             :     NONE NORMALIZE NORMALIZED
     771                 :             :     NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
     772                 :             :     NULLS_P NUMERIC
     773                 :             : 
     774                 :             :     OBJECT_P OBJECTS_P OF OFF OFFSET OIDS OLD OMIT ON ONLY OPERATOR OPTION OPTIONS OR
     775                 :             :     ORDER ORDINALITY OTHERS OUT_P OUTER_P
     776                 :             :     OVER OVERLAPS OVERLAY OVERRIDING OWNED OWNER
     777                 :             : 
     778                 :             :     PARALLEL PARAMETER PARSER PARTIAL PARTITION PASSING PASSWORD PATH
     779                 :             :     PERIOD PLACING PLAN PLANS POLICY
     780                 :             :     POSITION PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
     781                 :             :     PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROCEDURES PROGRAM PUBLICATION
     782                 :             : 
     783                 :             :     QUOTE QUOTES
     784                 :             : 
     785                 :             :     RANGE READ REAL REASSIGN RECURSIVE REF_P REFERENCES REFERENCING
     786                 :             :     REFRESH REINDEX RELATIVE_P RELEASE RENAME REPACK REPEATABLE REPLACE REPLICA
     787                 :             :     RESET RESPECT_P RESTART RESTRICT RETURN RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK ROLLUP
     788                 :             :     ROUTINE ROUTINES ROW ROWS RULE
     789                 :             : 
     790                 :             :     SAVEPOINT SCALAR SCHEMA SCHEMAS SCROLL SEARCH SECOND_P SECURITY SELECT
     791                 :             :     SEQUENCE SEQUENCES
     792                 :             :     SERIALIZABLE SERVER SESSION SESSION_USER SET SETS SETOF SHARE SHOW
     793                 :             :     SIMILAR SIMPLE SKIP SMALLINT SNAPSHOT SOME SOURCE SQL_P STABLE STANDALONE_P
     794                 :             :     START STATEMENT STATISTICS STDIN STDOUT STORAGE STORED STRICT_P STRING_P STRIP_P
     795                 :             :     SUBSCRIPTION SUBSTRING SUPPORT SYMMETRIC SYSID SYSTEM_P SYSTEM_USER
     796                 :             : 
     797                 :             :     TABLE TABLES TABLESAMPLE TABLESPACE TARGET TEMP TEMPLATE TEMPORARY TEXT_P THEN
     798                 :             :     TIES TIME TIMESTAMP TO TRAILING TRANSACTION TRANSFORM
     799                 :             :     TREAT TRIGGER TRIM TRUE_P
     800                 :             :     TRUNCATE TRUSTED TYPE_P TYPES_P
     801                 :             : 
     802                 :             :     UESCAPE UNBOUNDED UNCONDITIONAL UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN
     803                 :             :     UNLISTEN UNLOGGED UNTIL UPDATE USER USING
     804                 :             : 
     805                 :             :     VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
     806                 :             :     VERBOSE VERSION_P VIEW VIEWS VIRTUAL VOLATILE
     807                 :             : 
     808                 :             :     WAIT WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
     809                 :             : 
     810                 :             :     XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLNAMESPACES
     811                 :             :     XMLPARSE XMLPI XMLROOT XMLSERIALIZE XMLTABLE
     812                 :             : 
     813                 :             :     YEAR_P YES_P
     814                 :             : 
     815                 :             :     ZONE
     816                 :             : 
     817                 :             : /*
     818                 :             :  * The grammar thinks these are keywords, but they are not in the kwlist.h
     819                 :             :  * list and so can never be entered directly.  The filter in parser.c
     820                 :             :  * creates these tokens when required (based on looking one token ahead).
     821                 :             :  *
     822                 :             :  * NOT_LA exists so that productions such as NOT LIKE can be given the same
     823                 :             :  * precedence as LIKE; otherwise they'd effectively have the same precedence
     824                 :             :  * as NOT, at least with respect to their left-hand subexpression.
     825                 :             :  * FORMAT_LA, NULLS_LA, WITH_LA, and WITHOUT_LA are needed to make the grammar
     826                 :             :  * LALR(1).
     827                 :             :  */
     828                 :             : %token      FORMAT_LA NOT_LA NULLS_LA WITH_LA WITHOUT_LA
     829                 :             : 
     830                 :             : /*
     831                 :             :  * The grammar likewise thinks these tokens are keywords, but they are never
     832                 :             :  * generated by the scanner.  Rather, they can be injected by parser.c as
     833                 :             :  * the initial token of the string (using the lookahead-token mechanism
     834                 :             :  * implemented there).  This provides a way to tell the grammar to parse
     835                 :             :  * something other than the usual list of SQL commands.
     836                 :             :  */
     837                 :             : %token      MODE_TYPE_NAME
     838                 :             : %token      MODE_PLPGSQL_EXPR
     839                 :             : %token      MODE_PLPGSQL_ASSIGN1
     840                 :             : %token      MODE_PLPGSQL_ASSIGN2
     841                 :             : %token      MODE_PLPGSQL_ASSIGN3
     842                 :             : 
     843                 :             : 
     844                 :             : /* Precedence: lowest to highest */
     845                 :             : %left       UNION EXCEPT
     846                 :             : %left       INTERSECT
     847                 :             : %left       OR
     848                 :             : %left       AND
     849                 :             : %right      NOT
     850                 :             : %nonassoc   IS ISNULL NOTNULL   /* IS sets precedence for IS NULL, etc */
     851                 :             : %nonassoc   '<' '>' '=' LESS_EQUALS GREATER_EQUALS NOT_EQUALS
     852                 :             : %nonassoc   BETWEEN IN_P LIKE ILIKE SIMILAR NOT_LA
     853                 :             : %nonassoc   ESCAPE          /* ESCAPE must be just above LIKE/ILIKE/SIMILAR */
     854                 :             : 
     855                 :             : /*
     856                 :             :  * Sometimes it is necessary to assign precedence to keywords that are not
     857                 :             :  * really part of the operator hierarchy, in order to resolve grammar
     858                 :             :  * ambiguities.  It's best to avoid doing so whenever possible, because such
     859                 :             :  * assignments have global effect and may hide ambiguities besides the one
     860                 :             :  * you intended to solve.  (Attaching a precedence to a single rule with
     861                 :             :  * %prec is far safer and should be preferred.)  If you must give precedence
     862                 :             :  * to a new keyword, try very hard to give it the same precedence as IDENT.
     863                 :             :  * If the keyword has IDENT's precedence then it clearly acts the same as
     864                 :             :  * non-keywords and other similar keywords, thus reducing the risk of
     865                 :             :  * unexpected precedence effects.
     866                 :             :  *
     867                 :             :  * We used to need to assign IDENT an explicit precedence just less than Op,
     868                 :             :  * to support target_el without AS.  While that's not really necessary since
     869                 :             :  * we removed postfix operators, we continue to do so because it provides a
     870                 :             :  * reference point for a precedence level that we can assign to other
     871                 :             :  * keywords that lack a natural precedence level.
     872                 :             :  *
     873                 :             :  * We need to do this for PARTITION, RANGE, ROWS, and GROUPS to support
     874                 :             :  * opt_existing_window_name (see comment there).
     875                 :             :  *
     876                 :             :  * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
     877                 :             :  * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
     878                 :             :  * there is no principled way to distinguish these from the productions
     879                 :             :  * a_expr PRECEDING/FOLLOWING.  We hack this up by giving UNBOUNDED slightly
     880                 :             :  * lower precedence than PRECEDING and FOLLOWING.  At present this doesn't
     881                 :             :  * appear to cause UNBOUNDED to be treated differently from other unreserved
     882                 :             :  * keywords anywhere else in the grammar, but it's definitely risky.  We can
     883                 :             :  * blame any funny behavior of UNBOUNDED on the SQL standard, though.
     884                 :             :  *
     885                 :             :  * To support CUBE and ROLLUP in GROUP BY without reserving them, we give them
     886                 :             :  * an explicit priority lower than '(', so that a rule with CUBE '(' will shift
     887                 :             :  * rather than reducing a conflicting rule that takes CUBE as a function name.
     888                 :             :  * Using the same precedence as IDENT seems right for the reasons given above.
     889                 :             :  *
     890                 :             :  * SET is likewise assigned the same precedence as IDENT, to support the
     891                 :             :  * relation_expr_opt_alias production (see comment there).
     892                 :             :  *
     893                 :             :  * KEYS, OBJECT_P, SCALAR, VALUE_P, WITH, and WITHOUT are similarly assigned
     894                 :             :  * the same precedence as IDENT.  This allows resolving conflicts in the
     895                 :             :  * json_predicate_type_constraint and json_key_uniqueness_constraint_opt
     896                 :             :  * productions (see comments there).
     897                 :             :  *
     898                 :             :  * Like the UNBOUNDED PRECEDING/FOLLOWING case, NESTED is assigned a lower
     899                 :             :  * precedence than PATH to fix ambiguity in the json_table production.
     900                 :             :  */
     901                 :             : %nonassoc   UNBOUNDED NESTED /* ideally would have same precedence as IDENT */
     902                 :             : %nonassoc   IDENT PARTITION RANGE ROWS GROUPS PRECEDING FOLLOWING CUBE ROLLUP
     903                 :             :             SET KEYS OBJECT_P SCALAR VALUE_P WITH WITHOUT PATH
     904                 :             : %left       Op OPERATOR     /* multi-character ops and user-defined operators */
     905                 :             : %left       '+' '-'
     906                 :             : %left       '*' '/' '%'
     907                 :             : %left       '^'
     908                 :             : /* Unary Operators */
     909                 :             : %left       AT              /* sets precedence for AT TIME ZONE, AT LOCAL */
     910                 :             : %left       COLLATE
     911                 :             : %right      UMINUS
     912                 :             : %left       '[' ']'
     913                 :             : %left       '(' ')'
     914                 :             : %left       TYPECAST
     915                 :             : %left       '.'
     916                 :             : /*
     917                 :             :  * These might seem to be low-precedence, but actually they are not part
     918                 :             :  * of the arithmetic hierarchy at all in their use as JOIN operators.
     919                 :             :  * We make them high-precedence to support their use as function names.
     920                 :             :  * They wouldn't be given a precedence at all, were it not that we need
     921                 :             :  * left-associativity among the JOIN rules themselves.
     922                 :             :  */
     923                 :             : %left       JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
     924                 :             : 
     925                 :             : %%
     926                 :             : 
     927                 :             : /*
     928                 :             :  *  The target production for the whole parse.
     929                 :             :  *
     930                 :             :  * Ordinarily we parse a list of statements, but if we see one of the
     931                 :             :  * special MODE_XXX symbols as first token, we parse something else.
     932                 :             :  * The options here correspond to enum RawParseMode, which see for details.
     933                 :             :  */
     934                 :             : parse_toplevel:
     935                 :             :             stmtmulti
     936                 :             :             {
     937                 :      461868 :                 pg_yyget_extra(yyscanner)->parsetree = $1;
     938                 :             :                 (void) yynerrs;     /* suppress compiler warning */
     939                 :             :             }
     940                 :             :             | MODE_TYPE_NAME Typename
     941                 :             :             {
     942                 :        6436 :                 pg_yyget_extra(yyscanner)->parsetree = list_make1($2);
     943                 :             :             }
     944                 :             :             | MODE_PLPGSQL_EXPR PLpgSQL_Expr
     945                 :             :             {
     946                 :       20685 :                 pg_yyget_extra(yyscanner)->parsetree =
     947                 :       20685 :                     list_make1(makeRawStmt($2, @2));
     948                 :             :             }
     949                 :             :             | MODE_PLPGSQL_ASSIGN1 PLAssignStmt
     950                 :             :             {
     951                 :        3835 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     952                 :             : 
     953                 :        3835 :                 n->nnames = 1;
     954                 :        3835 :                 pg_yyget_extra(yyscanner)->parsetree =
     955                 :        3835 :                     list_make1(makeRawStmt((Node *) n, @2));
     956                 :             :             }
     957                 :             :             | MODE_PLPGSQL_ASSIGN2 PLAssignStmt
     958                 :             :             {
     959                 :         423 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     960                 :             : 
     961                 :         423 :                 n->nnames = 2;
     962                 :         423 :                 pg_yyget_extra(yyscanner)->parsetree =
     963                 :         423 :                     list_make1(makeRawStmt((Node *) n, @2));
     964                 :             :             }
     965                 :             :             | MODE_PLPGSQL_ASSIGN3 PLAssignStmt
     966                 :             :             {
     967                 :          14 :                 PLAssignStmt *n = (PLAssignStmt *) $2;
     968                 :             : 
     969                 :          14 :                 n->nnames = 3;
     970                 :          14 :                 pg_yyget_extra(yyscanner)->parsetree =
     971                 :          14 :                     list_make1(makeRawStmt((Node *) n, @2));
     972                 :             :             }
     973                 :             :         ;
     974                 :             : 
     975                 :             : /*
     976                 :             :  * At top level, we wrap each stmt with a RawStmt node carrying start location
     977                 :             :  * and length of the stmt's text.
     978                 :             :  * We also take care to discard empty statements entirely (which among other
     979                 :             :  * things dodges the problem of assigning them a location).
     980                 :             :  */
     981                 :             : stmtmulti:  stmtmulti ';' toplevel_stmt
     982                 :             :                 {
     983         [ +  + ]:      387317 :                     if ($1 != NIL)
     984                 :             :                     {
     985                 :             :                         /* update length of previous stmt */
     986                 :      386671 :                         updateRawStmtEnd(llast_node(RawStmt, $1), @2);
     987                 :             :                     }
     988         [ +  + ]:      387316 :                     if ($3 != NULL)
     989                 :       31809 :                         $$ = lappend($1, makeRawStmt($3, @3));
     990                 :             :                     else
     991                 :      355507 :                         $$ = $1;
     992                 :             :                 }
     993                 :             :             | toplevel_stmt
     994                 :             :                 {
     995         [ +  + ]:      461873 :                     if ($1 != NULL)
     996                 :      460785 :                         $$ = list_make1(makeRawStmt($1, @1));
     997                 :             :                     else
     998                 :        1088 :                         $$ = NIL;
     999                 :             :                 }
    1000                 :             :         ;
    1001                 :             : 
    1002                 :             : /*
    1003                 :             :  * toplevel_stmt includes BEGIN and END.  stmt does not include them, because
    1004                 :             :  * those words have different meanings in function bodies.
    1005                 :             :  */
    1006                 :             : toplevel_stmt:
    1007                 :             :             stmt
    1008                 :             :             | TransactionStmtLegacy
    1009                 :             :         ;
    1010                 :             : 
    1011                 :             : stmt:
    1012                 :             :             AlterEventTrigStmt
    1013                 :             :             | AlterCollationStmt
    1014                 :             :             | AlterDatabaseStmt
    1015                 :             :             | AlterDatabaseSetStmt
    1016                 :             :             | AlterDefaultPrivilegesStmt
    1017                 :             :             | AlterDomainStmt
    1018                 :             :             | AlterEnumStmt
    1019                 :             :             | AlterExtensionStmt
    1020                 :             :             | AlterExtensionContentsStmt
    1021                 :             :             | AlterFdwStmt
    1022                 :             :             | AlterForeignServerStmt
    1023                 :             :             | AlterFunctionStmt
    1024                 :             :             | AlterGroupStmt
    1025                 :             :             | AlterObjectDependsStmt
    1026                 :             :             | AlterObjectSchemaStmt
    1027                 :             :             | AlterOwnerStmt
    1028                 :             :             | AlterOperatorStmt
    1029                 :             :             | AlterTypeStmt
    1030                 :             :             | AlterPolicyStmt
    1031                 :             :             | AlterSeqStmt
    1032                 :             :             | AlterSystemStmt
    1033                 :             :             | AlterTableStmt
    1034                 :             :             | AlterTblSpcStmt
    1035                 :             :             | AlterCompositeTypeStmt
    1036                 :             :             | AlterPublicationStmt
    1037                 :             :             | AlterRoleSetStmt
    1038                 :             :             | AlterRoleStmt
    1039                 :             :             | AlterSubscriptionStmt
    1040                 :             :             | AlterStatsStmt
    1041                 :             :             | AlterTSConfigurationStmt
    1042                 :             :             | AlterTSDictionaryStmt
    1043                 :             :             | AlterUserMappingStmt
    1044                 :             :             | AnalyzeStmt
    1045                 :             :             | CallStmt
    1046                 :             :             | CheckPointStmt
    1047                 :             :             | ClosePortalStmt
    1048                 :             :             | CommentStmt
    1049                 :             :             | ConstraintsSetStmt
    1050                 :             :             | CopyStmt
    1051                 :             :             | CreateAmStmt
    1052                 :             :             | CreateAsStmt
    1053                 :             :             | CreateAssertionStmt
    1054                 :             :             | CreateCastStmt
    1055                 :             :             | CreateConversionStmt
    1056                 :             :             | CreateDomainStmt
    1057                 :             :             | CreateExtensionStmt
    1058                 :             :             | CreateFdwStmt
    1059                 :             :             | CreateForeignServerStmt
    1060                 :             :             | CreateForeignTableStmt
    1061                 :             :             | CreateFunctionStmt
    1062                 :             :             | CreateGroupStmt
    1063                 :             :             | CreateMatViewStmt
    1064                 :             :             | CreateOpClassStmt
    1065                 :             :             | CreateOpFamilyStmt
    1066                 :             :             | CreatePublicationStmt
    1067                 :             :             | AlterOpFamilyStmt
    1068                 :             :             | CreatePolicyStmt
    1069                 :             :             | CreatePLangStmt
    1070                 :             :             | CreateSchemaStmt
    1071                 :             :             | CreateSeqStmt
    1072                 :             :             | CreateStmt
    1073                 :             :             | CreateSubscriptionStmt
    1074                 :             :             | CreateStatsStmt
    1075                 :             :             | CreateTableSpaceStmt
    1076                 :             :             | CreateTransformStmt
    1077                 :             :             | CreateTrigStmt
    1078                 :             :             | CreateEventTrigStmt
    1079                 :             :             | CreateRoleStmt
    1080                 :             :             | CreateUserStmt
    1081                 :             :             | CreateUserMappingStmt
    1082                 :             :             | CreatedbStmt
    1083                 :             :             | DeallocateStmt
    1084                 :             :             | DeclareCursorStmt
    1085                 :             :             | DefineStmt
    1086                 :             :             | DeleteStmt
    1087                 :             :             | DiscardStmt
    1088                 :             :             | DoStmt
    1089                 :             :             | DropCastStmt
    1090                 :             :             | DropOpClassStmt
    1091                 :             :             | DropOpFamilyStmt
    1092                 :             :             | DropOwnedStmt
    1093                 :             :             | DropStmt
    1094                 :             :             | DropSubscriptionStmt
    1095                 :             :             | DropTableSpaceStmt
    1096                 :             :             | DropTransformStmt
    1097                 :             :             | DropRoleStmt
    1098                 :             :             | DropUserMappingStmt
    1099                 :             :             | DropdbStmt
    1100                 :             :             | ExecuteStmt
    1101                 :             :             | ExplainStmt
    1102                 :             :             | FetchStmt
    1103                 :             :             | GrantStmt
    1104                 :             :             | GrantRoleStmt
    1105                 :             :             | ImportForeignSchemaStmt
    1106                 :             :             | IndexStmt
    1107                 :             :             | InsertStmt
    1108                 :             :             | ListenStmt
    1109                 :             :             | RefreshMatViewStmt
    1110                 :             :             | LoadStmt
    1111                 :             :             | LockStmt
    1112                 :             :             | MergeStmt
    1113                 :             :             | NotifyStmt
    1114                 :             :             | PrepareStmt
    1115                 :             :             | ReassignOwnedStmt
    1116                 :             :             | ReindexStmt
    1117                 :             :             | RemoveAggrStmt
    1118                 :             :             | RemoveFuncStmt
    1119                 :             :             | RemoveOperStmt
    1120                 :             :             | RenameStmt
    1121                 :             :             | RepackStmt
    1122                 :             :             | RevokeStmt
    1123                 :             :             | RevokeRoleStmt
    1124                 :             :             | RuleStmt
    1125                 :             :             | SecLabelStmt
    1126                 :             :             | SelectStmt
    1127                 :             :             | TransactionStmt
    1128                 :             :             | TruncateStmt
    1129                 :             :             | UnlistenStmt
    1130                 :             :             | UpdateStmt
    1131                 :             :             | VacuumStmt
    1132                 :             :             | VariableResetStmt
    1133                 :             :             | VariableSetStmt
    1134                 :             :             | VariableShowStmt
    1135                 :             :             | ViewStmt
    1136                 :             :             | WaitStmt
    1137                 :             :             | /*EMPTY*/
    1138                 :      356611 :                 { $$ = NULL; }
    1139                 :             :         ;
    1140                 :             : 
    1141                 :             : /*
    1142                 :             :  * Generic supporting productions for DDL
    1143                 :             :  */
    1144                 :             : opt_single_name:
    1145                 :        3519 :             ColId                           { $$ = $1; }
    1146                 :        1233 :             | /* EMPTY */                   { $$ = NULL; }
    1147                 :             :         ;
    1148                 :             : 
    1149                 :             : opt_qualified_name:
    1150                 :        1389 :             any_name                        { $$ = $1; }
    1151                 :       10775 :             | /*EMPTY*/                     { $$ = NIL; }
    1152                 :             :         ;
    1153                 :             : 
    1154                 :             : opt_concurrently:
    1155                 :         706 :             CONCURRENTLY                    { $$ = true; }
    1156                 :        5180 :             | /*EMPTY*/                     { $$ = false; }
    1157                 :             :         ;
    1158                 :             : 
    1159                 :             : opt_usingindex:
    1160                 :           4 :             USING INDEX                     { $$ = true; }
    1161                 :          69 :             | /* EMPTY */                   { $$ = false; }
    1162                 :             :         ;
    1163                 :             : 
    1164                 :             : opt_drop_behavior:
    1165                 :        1343 :             CASCADE                         { $$ = DROP_CASCADE; }
    1166                 :         111 :             | RESTRICT                      { $$ = DROP_RESTRICT; }
    1167                 :       22023 :             | /* EMPTY */                   { $$ = DROP_RESTRICT; /* default */ }
    1168                 :             :         ;
    1169                 :             : 
    1170                 :             : opt_utility_option_list:
    1171                 :         258 :             '(' utility_option_list ')'     { $$ = $2; }
    1172                 :        3796 :             | /* EMPTY */                   { $$ = NULL; }
    1173                 :             :         ;
    1174                 :             : 
    1175                 :             : utility_option_list:
    1176                 :             :             utility_option_elem
    1177                 :             :                 {
    1178                 :       16020 :                     $$ = list_make1($1);
    1179                 :             :                 }
    1180                 :             :             | utility_option_list ',' utility_option_elem
    1181                 :             :                 {
    1182                 :        9011 :                     $$ = lappend($1, $3);
    1183                 :             :                 }
    1184                 :             :         ;
    1185                 :             : 
    1186                 :             : utility_option_elem:
    1187                 :             :             utility_option_name utility_option_arg
    1188                 :             :                 {
    1189                 :       25031 :                     $$ = makeDefElem($1, $2, @1);
    1190                 :             :                 }
    1191                 :             :         ;
    1192                 :             : 
    1193                 :             : utility_option_name:
    1194                 :       22608 :             NonReservedWord                 { $$ = $1; }
    1195                 :        2333 :             | analyze_keyword               { $$ = "analyze"; }
    1196                 :          94 :             | FORMAT_LA                     { $$ = "format"; }
    1197                 :             :         ;
    1198                 :             : 
    1199                 :             : utility_option_arg:
    1200                 :       13636 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    1201                 :         211 :             | NumericOnly                   { $$ = (Node *) $1; }
    1202                 :       11184 :             | /* EMPTY */                   { $$ = NULL; }
    1203                 :             :         ;
    1204                 :             : 
    1205                 :             : /*****************************************************************************
    1206                 :             :  *
    1207                 :             :  * CALL statement
    1208                 :             :  *
    1209                 :             :  *****************************************************************************/
    1210                 :             : 
    1211                 :             : CallStmt:   CALL func_application
    1212                 :             :                 {
    1213                 :         364 :                     CallStmt   *n = makeNode(CallStmt);
    1214                 :             : 
    1215                 :         364 :                     n->funccall = castNode(FuncCall, $2);
    1216                 :         364 :                     $$ = (Node *) n;
    1217                 :             :                 }
    1218                 :             :         ;
    1219                 :             : 
    1220                 :             : /*****************************************************************************
    1221                 :             :  *
    1222                 :             :  * Create a new Postgres DBMS role
    1223                 :             :  *
    1224                 :             :  *****************************************************************************/
    1225                 :             : 
    1226                 :             : CreateRoleStmt:
    1227                 :             :             CREATE ROLE RoleId opt_with OptRoleList
    1228                 :             :                 {
    1229                 :         962 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1230                 :             : 
    1231                 :         962 :                     n->stmt_type = ROLESTMT_ROLE;
    1232                 :         962 :                     n->role = $3;
    1233                 :         962 :                     n->options = $5;
    1234                 :         962 :                     $$ = (Node *) n;
    1235                 :             :                 }
    1236                 :             :         ;
    1237                 :             : 
    1238                 :             : 
    1239                 :             : opt_with:   WITH
    1240                 :             :             | WITH_LA
    1241                 :             :             | /*EMPTY*/
    1242                 :             :         ;
    1243                 :             : 
    1244                 :             : /*
    1245                 :             :  * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
    1246                 :             :  * for backwards compatibility).  Note: the only option required by SQL99
    1247                 :             :  * is "WITH ADMIN name".
    1248                 :             :  */
    1249                 :             : OptRoleList:
    1250                 :         741 :             OptRoleList CreateOptRoleElem           { $$ = lappend($1, $2); }
    1251                 :        1282 :             | /* EMPTY */                           { $$ = NIL; }
    1252                 :             :         ;
    1253                 :             : 
    1254                 :             : AlterOptRoleList:
    1255                 :         446 :             AlterOptRoleList AlterOptRoleElem       { $$ = lappend($1, $2); }
    1256                 :         262 :             | /* EMPTY */                           { $$ = NIL; }
    1257                 :             :         ;
    1258                 :             : 
    1259                 :             : AlterOptRoleElem:
    1260                 :             :             PASSWORD Sconst
    1261                 :             :                 {
    1262                 :         119 :                     $$ = makeDefElem("password",
    1263                 :         119 :                                      (Node *) makeString($2), @1);
    1264                 :             :                 }
    1265                 :             :             | PASSWORD NULL_P
    1266                 :             :                 {
    1267                 :           8 :                     $$ = makeDefElem("password", NULL, @1);
    1268                 :             :                 }
    1269                 :             :             | ENCRYPTED PASSWORD Sconst
    1270                 :             :                 {
    1271                 :             :                     /*
    1272                 :             :                      * These days, passwords are always stored in encrypted
    1273                 :             :                      * form, so there is no difference between PASSWORD and
    1274                 :             :                      * ENCRYPTED PASSWORD.
    1275                 :             :                      */
    1276                 :           9 :                     $$ = makeDefElem("password",
    1277                 :           9 :                                      (Node *) makeString($3), @1);
    1278                 :             :                 }
    1279                 :             :             | UNENCRYPTED PASSWORD Sconst
    1280                 :             :                 {
    1281         [ #  # ]:           0 :                     ereport(ERROR,
    1282                 :             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1283                 :             :                              errmsg("UNENCRYPTED PASSWORD is no longer supported"),
    1284                 :             :                              errhint("Remove UNENCRYPTED to store the password in encrypted form instead."),
    1285                 :             :                              parser_errposition(@1)));
    1286                 :             :                 }
    1287                 :             :             | INHERIT
    1288                 :             :                 {
    1289                 :          61 :                     $$ = makeDefElem("inherit", (Node *) makeBoolean(true), @1);
    1290                 :             :                 }
    1291                 :             :             | CONNECTION LIMIT SignedIconst
    1292                 :             :                 {
    1293                 :          17 :                     $$ = makeDefElem("connectionlimit", (Node *) makeInteger($3), @1);
    1294                 :             :                 }
    1295                 :             :             | VALID UNTIL Sconst
    1296                 :             :                 {
    1297                 :           5 :                     $$ = makeDefElem("validUntil", (Node *) makeString($3), @1);
    1298                 :             :                 }
    1299                 :             :         /*  Supported but not documented for roles, for use by ALTER GROUP. */
    1300                 :             :             | USER role_list
    1301                 :             :                 {
    1302                 :           4 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1303                 :             :                 }
    1304                 :             :             | IDENT
    1305                 :             :                 {
    1306                 :             :                     /*
    1307                 :             :                      * We handle identifiers that aren't parser keywords with
    1308                 :             :                      * the following special-case codes, to avoid bloating the
    1309                 :             :                      * size of the main parser.
    1310                 :             :                      */
    1311         [ +  + ]:         855 :                     if (strcmp($1, "superuser") == 0)
    1312                 :         114 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(true), @1);
    1313         [ +  + ]:         741 :                     else if (strcmp($1, "nosuperuser") == 0)
    1314                 :          65 :                         $$ = makeDefElem("superuser", (Node *) makeBoolean(false), @1);
    1315         [ +  + ]:         676 :                     else if (strcmp($1, "createrole") == 0)
    1316                 :          63 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(true), @1);
    1317         [ +  + ]:         613 :                     else if (strcmp($1, "nocreaterole") == 0)
    1318                 :          29 :                         $$ = makeDefElem("createrole", (Node *) makeBoolean(false), @1);
    1319         [ +  + ]:         584 :                     else if (strcmp($1, "replication") == 0)
    1320                 :          78 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(true), @1);
    1321         [ +  + ]:         506 :                     else if (strcmp($1, "noreplication") == 0)
    1322                 :          58 :                         $$ = makeDefElem("isreplication", (Node *) makeBoolean(false), @1);
    1323         [ +  + ]:         448 :                     else if (strcmp($1, "createdb") == 0)
    1324                 :          56 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(true), @1);
    1325         [ +  + ]:         392 :                     else if (strcmp($1, "nocreatedb") == 0)
    1326                 :          34 :                         $$ = makeDefElem("createdb", (Node *) makeBoolean(false), @1);
    1327         [ +  + ]:         358 :                     else if (strcmp($1, "login") == 0)
    1328                 :         165 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(true), @1);
    1329         [ +  + ]:         193 :                     else if (strcmp($1, "nologin") == 0)
    1330                 :          72 :                         $$ = makeDefElem("canlogin", (Node *) makeBoolean(false), @1);
    1331         [ +  + ]:         121 :                     else if (strcmp($1, "bypassrls") == 0)
    1332                 :          53 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(true), @1);
    1333         [ +  + ]:          68 :                     else if (strcmp($1, "nobypassrls") == 0)
    1334                 :          44 :                         $$ = makeDefElem("bypassrls", (Node *) makeBoolean(false), @1);
    1335         [ +  - ]:          24 :                     else if (strcmp($1, "noinherit") == 0)
    1336                 :             :                     {
    1337                 :             :                         /*
    1338                 :             :                          * Note that INHERIT is a keyword, so it's handled by main parser, but
    1339                 :             :                          * NOINHERIT is handled here.
    1340                 :             :                          */
    1341                 :          24 :                         $$ = makeDefElem("inherit", (Node *) makeBoolean(false), @1);
    1342                 :             :                     }
    1343                 :             :                     else
    1344         [ #  # ]:           0 :                         ereport(ERROR,
    1345                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    1346                 :             :                                  errmsg("unrecognized role option \"%s\"", $1),
    1347                 :             :                                      parser_errposition(@1)));
    1348                 :             :                 }
    1349                 :             :         ;
    1350                 :             : 
    1351                 :             : CreateOptRoleElem:
    1352                 :         632 :             AlterOptRoleElem            { $$ = $1; }
    1353                 :             :             /* The following are not supported by ALTER ROLE/USER/GROUP */
    1354                 :             :             | SYSID Iconst
    1355                 :             :                 {
    1356                 :           4 :                     $$ = makeDefElem("sysid", (Node *) makeInteger($2), @1);
    1357                 :             :                 }
    1358                 :             :             | ADMIN role_list
    1359                 :             :                 {
    1360                 :          14 :                     $$ = makeDefElem("adminmembers", (Node *) $2, @1);
    1361                 :             :                 }
    1362                 :             :             | ROLE role_list
    1363                 :             :                 {
    1364                 :          26 :                     $$ = makeDefElem("rolemembers", (Node *) $2, @1);
    1365                 :             :                 }
    1366                 :             :             | IN_P ROLE role_list
    1367                 :             :                 {
    1368                 :          65 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1369                 :             :                 }
    1370                 :             :             | IN_P GROUP_P role_list
    1371                 :             :                 {
    1372                 :           0 :                     $$ = makeDefElem("addroleto", (Node *) $3, @1);
    1373                 :             :                 }
    1374                 :             :         ;
    1375                 :             : 
    1376                 :             : 
    1377                 :             : /*****************************************************************************
    1378                 :             :  *
    1379                 :             :  * Create a new Postgres DBMS user (role with implied login ability)
    1380                 :             :  *
    1381                 :             :  *****************************************************************************/
    1382                 :             : 
    1383                 :             : CreateUserStmt:
    1384                 :             :             CREATE USER RoleId opt_with OptRoleList
    1385                 :             :                 {
    1386                 :         304 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1387                 :             : 
    1388                 :         304 :                     n->stmt_type = ROLESTMT_USER;
    1389                 :         304 :                     n->role = $3;
    1390                 :         304 :                     n->options = $5;
    1391                 :         304 :                     $$ = (Node *) n;
    1392                 :             :                 }
    1393                 :             :         ;
    1394                 :             : 
    1395                 :             : 
    1396                 :             : /*****************************************************************************
    1397                 :             :  *
    1398                 :             :  * Alter a postgresql DBMS role
    1399                 :             :  *
    1400                 :             :  *****************************************************************************/
    1401                 :             : 
    1402                 :             : AlterRoleStmt:
    1403                 :             :             ALTER ROLE RoleSpec opt_with AlterOptRoleList
    1404                 :             :                  {
    1405                 :         213 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1406                 :             : 
    1407                 :         213 :                     n->role = $3;
    1408                 :         213 :                     n->action = +1;  /* add, if there are members */
    1409                 :         213 :                     n->options = $5;
    1410                 :         213 :                     $$ = (Node *) n;
    1411                 :             :                  }
    1412                 :             :             | ALTER USER RoleSpec opt_with AlterOptRoleList
    1413                 :             :                  {
    1414                 :          49 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1415                 :             : 
    1416                 :          49 :                     n->role = $3;
    1417                 :          49 :                     n->action = +1;  /* add, if there are members */
    1418                 :          49 :                     n->options = $5;
    1419                 :          49 :                     $$ = (Node *) n;
    1420                 :             :                  }
    1421                 :             :         ;
    1422                 :             : 
    1423                 :             : opt_in_database:
    1424                 :          50 :                /* EMPTY */                  { $$ = NULL; }
    1425                 :           4 :             | IN_P DATABASE name    { $$ = $3; }
    1426                 :             :         ;
    1427                 :             : 
    1428                 :             : AlterRoleSetStmt:
    1429                 :             :             ALTER ROLE RoleSpec opt_in_database SetResetClause
    1430                 :             :                 {
    1431                 :          34 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1432                 :             : 
    1433                 :          34 :                     n->role = $3;
    1434                 :          34 :                     n->database = $4;
    1435                 :          34 :                     n->setstmt = $5;
    1436                 :          34 :                     $$ = (Node *) n;
    1437                 :             :                 }
    1438                 :             :             | ALTER ROLE ALL opt_in_database SetResetClause
    1439                 :             :                 {
    1440                 :           2 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1441                 :             : 
    1442                 :           2 :                     n->role = NULL;
    1443                 :           2 :                     n->database = $4;
    1444                 :           2 :                     n->setstmt = $5;
    1445                 :           2 :                     $$ = (Node *) n;
    1446                 :             :                 }
    1447                 :             :             | ALTER USER RoleSpec opt_in_database SetResetClause
    1448                 :             :                 {
    1449                 :          14 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1450                 :             : 
    1451                 :          14 :                     n->role = $3;
    1452                 :          14 :                     n->database = $4;
    1453                 :          14 :                     n->setstmt = $5;
    1454                 :          14 :                     $$ = (Node *) n;
    1455                 :             :                 }
    1456                 :             :             | ALTER USER ALL opt_in_database SetResetClause
    1457                 :             :                 {
    1458                 :           2 :                     AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
    1459                 :             : 
    1460                 :           2 :                     n->role = NULL;
    1461                 :           2 :                     n->database = $4;
    1462                 :           2 :                     n->setstmt = $5;
    1463                 :           2 :                     $$ = (Node *) n;
    1464                 :             :                 }
    1465                 :             :         ;
    1466                 :             : 
    1467                 :             : 
    1468                 :             : /*****************************************************************************
    1469                 :             :  *
    1470                 :             :  * Drop a postgresql DBMS role
    1471                 :             :  *
    1472                 :             :  * XXX Ideally this would have CASCADE/RESTRICT options, but a role
    1473                 :             :  * might own objects in multiple databases, and there is presently no way to
    1474                 :             :  * implement cascading to other databases.  So we always behave as RESTRICT.
    1475                 :             :  *****************************************************************************/
    1476                 :             : 
    1477                 :             : DropRoleStmt:
    1478                 :             :             DROP ROLE role_list
    1479                 :             :                 {
    1480                 :         771 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1481                 :             : 
    1482                 :         771 :                     n->missing_ok = false;
    1483                 :         771 :                     n->roles = $3;
    1484                 :         771 :                     $$ = (Node *) n;
    1485                 :             :                 }
    1486                 :             :             | DROP ROLE IF_P EXISTS role_list
    1487                 :             :                 {
    1488                 :         100 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1489                 :             : 
    1490                 :         100 :                     n->missing_ok = true;
    1491                 :         100 :                     n->roles = $5;
    1492                 :         100 :                     $$ = (Node *) n;
    1493                 :             :                 }
    1494                 :             :             | DROP USER role_list
    1495                 :             :                 {
    1496                 :         276 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1497                 :             : 
    1498                 :         276 :                     n->missing_ok = false;
    1499                 :         276 :                     n->roles = $3;
    1500                 :         276 :                     $$ = (Node *) n;
    1501                 :             :                 }
    1502                 :             :             | DROP USER IF_P EXISTS role_list
    1503                 :             :                 {
    1504                 :          24 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1505                 :             : 
    1506                 :          24 :                     n->roles = $5;
    1507                 :          24 :                     n->missing_ok = true;
    1508                 :          24 :                     $$ = (Node *) n;
    1509                 :             :                 }
    1510                 :             :             | DROP GROUP_P role_list
    1511                 :             :                 {
    1512                 :          24 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1513                 :             : 
    1514                 :          24 :                     n->missing_ok = false;
    1515                 :          24 :                     n->roles = $3;
    1516                 :          24 :                     $$ = (Node *) n;
    1517                 :             :                 }
    1518                 :             :             | DROP GROUP_P IF_P EXISTS role_list
    1519                 :             :                 {
    1520                 :           4 :                     DropRoleStmt *n = makeNode(DropRoleStmt);
    1521                 :             : 
    1522                 :           4 :                     n->missing_ok = true;
    1523                 :           4 :                     n->roles = $5;
    1524                 :           4 :                     $$ = (Node *) n;
    1525                 :             :                 }
    1526                 :             :             ;
    1527                 :             : 
    1528                 :             : 
    1529                 :             : /*****************************************************************************
    1530                 :             :  *
    1531                 :             :  * Create a postgresql group (role without login ability)
    1532                 :             :  *
    1533                 :             :  *****************************************************************************/
    1534                 :             : 
    1535                 :             : CreateGroupStmt:
    1536                 :             :             CREATE GROUP_P RoleId opt_with OptRoleList
    1537                 :             :                 {
    1538                 :          16 :                     CreateRoleStmt *n = makeNode(CreateRoleStmt);
    1539                 :             : 
    1540                 :          16 :                     n->stmt_type = ROLESTMT_GROUP;
    1541                 :          16 :                     n->role = $3;
    1542                 :          16 :                     n->options = $5;
    1543                 :          16 :                     $$ = (Node *) n;
    1544                 :             :                 }
    1545                 :             :         ;
    1546                 :             : 
    1547                 :             : 
    1548                 :             : /*****************************************************************************
    1549                 :             :  *
    1550                 :             :  * Alter a postgresql group
    1551                 :             :  *
    1552                 :             :  *****************************************************************************/
    1553                 :             : 
    1554                 :             : AlterGroupStmt:
    1555                 :             :             ALTER GROUP_P RoleSpec add_drop USER role_list
    1556                 :             :                 {
    1557                 :          32 :                     AlterRoleStmt *n = makeNode(AlterRoleStmt);
    1558                 :             : 
    1559                 :          32 :                     n->role = $3;
    1560                 :          32 :                     n->action = $4;
    1561                 :          32 :                     n->options = list_make1(makeDefElem("rolemembers",
    1562                 :             :                                                         (Node *) $6, @6));
    1563                 :          32 :                     $$ = (Node *) n;
    1564                 :             :                 }
    1565                 :             :         ;
    1566                 :             : 
    1567                 :          58 : add_drop:   ADD_P                                   { $$ = +1; }
    1568                 :         109 :             | DROP                                  { $$ = -1; }
    1569                 :             :         ;
    1570                 :             : 
    1571                 :             : 
    1572                 :             : /*****************************************************************************
    1573                 :             :  *
    1574                 :             :  * Manipulate a schema
    1575                 :             :  *
    1576                 :             :  *****************************************************************************/
    1577                 :             : 
    1578                 :             : CreateSchemaStmt:
    1579                 :             :             CREATE SCHEMA opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1580                 :             :                 {
    1581                 :         102 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1582                 :             : 
    1583                 :             :                     /* One can omit the schema name or the authorization id. */
    1584                 :         102 :                     n->schemaname = $3;
    1585                 :         102 :                     n->authrole = $5;
    1586                 :         102 :                     n->schemaElts = $6;
    1587                 :         102 :                     n->if_not_exists = false;
    1588                 :         102 :                     $$ = (Node *) n;
    1589                 :             :                 }
    1590                 :             :             | CREATE SCHEMA ColId OptSchemaEltList
    1591                 :             :                 {
    1592                 :         612 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1593                 :             : 
    1594                 :             :                     /* ...but not both */
    1595                 :         612 :                     n->schemaname = $3;
    1596                 :         612 :                     n->authrole = NULL;
    1597                 :         612 :                     n->schemaElts = $4;
    1598                 :         612 :                     n->if_not_exists = false;
    1599                 :         612 :                     $$ = (Node *) n;
    1600                 :             :                 }
    1601                 :             :             | CREATE SCHEMA IF_P NOT EXISTS opt_single_name AUTHORIZATION RoleSpec OptSchemaEltList
    1602                 :             :                 {
    1603                 :           9 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1604                 :             : 
    1605                 :             :                     /* schema name can be omitted here, too */
    1606                 :           9 :                     n->schemaname = $6;
    1607                 :           9 :                     n->authrole = $8;
    1608         [ -  + ]:           9 :                     if ($9 != NIL)
    1609         [ #  # ]:           0 :                         ereport(ERROR,
    1610                 :             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1611                 :             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1612                 :             :                                  parser_errposition(@9)));
    1613                 :           9 :                     n->schemaElts = $9;
    1614                 :           9 :                     n->if_not_exists = true;
    1615                 :           9 :                     $$ = (Node *) n;
    1616                 :             :                 }
    1617                 :             :             | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
    1618                 :             :                 {
    1619                 :          19 :                     CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
    1620                 :             : 
    1621                 :             :                     /* ...but not here */
    1622                 :          19 :                     n->schemaname = $6;
    1623                 :          19 :                     n->authrole = NULL;
    1624         [ +  + ]:          19 :                     if ($7 != NIL)
    1625         [ +  - ]:           4 :                         ereport(ERROR,
    1626                 :             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1627                 :             :                                  errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
    1628                 :             :                                  parser_errposition(@7)));
    1629                 :          15 :                     n->schemaElts = $7;
    1630                 :          15 :                     n->if_not_exists = true;
    1631                 :          15 :                     $$ = (Node *) n;
    1632                 :             :                 }
    1633                 :             :         ;
    1634                 :             : 
    1635                 :             : OptSchemaEltList:
    1636                 :             :             OptSchemaEltList schema_stmt
    1637                 :             :                 {
    1638                 :         419 :                     $$ = lappend($1, $2);
    1639                 :             :                 }
    1640                 :             :             | /* EMPTY */
    1641                 :         742 :                 { $$ = NIL; }
    1642                 :             :         ;
    1643                 :             : 
    1644                 :             : /*
    1645                 :             :  *  schema_stmt are the ones that can show up inside a CREATE SCHEMA
    1646                 :             :  *  statement (in addition to by themselves).
    1647                 :             :  */
    1648                 :             : schema_stmt:
    1649                 :             :             CreateStmt
    1650                 :             :             | IndexStmt
    1651                 :             :             | CreateSeqStmt
    1652                 :             :             | CreateTrigStmt
    1653                 :             :             | GrantStmt
    1654                 :             :             | ViewStmt
    1655                 :             :         ;
    1656                 :             : 
    1657                 :             : 
    1658                 :             : /*****************************************************************************
    1659                 :             :  *
    1660                 :             :  * Set PG internal variable
    1661                 :             :  *    SET name TO 'var_value'
    1662                 :             :  * Include SQL syntax (thomas 1997-10-22):
    1663                 :             :  *    SET TIME ZONE 'var_value'
    1664                 :             :  *
    1665                 :             :  *****************************************************************************/
    1666                 :             : 
    1667                 :             : VariableSetStmt:
    1668                 :             :             SET set_rest
    1669                 :             :                 {
    1670                 :       13644 :                     VariableSetStmt *n = $2;
    1671                 :             : 
    1672                 :       13644 :                     n->is_local = false;
    1673                 :       13644 :                     $$ = (Node *) n;
    1674                 :             :                 }
    1675                 :             :             | SET LOCAL set_rest
    1676                 :             :                 {
    1677                 :        1012 :                     VariableSetStmt *n = $3;
    1678                 :             : 
    1679                 :        1012 :                     n->is_local = true;
    1680                 :        1012 :                     $$ = (Node *) n;
    1681                 :             :                 }
    1682                 :             :             | SET SESSION set_rest
    1683                 :             :                 {
    1684                 :          53 :                     VariableSetStmt *n = $3;
    1685                 :             : 
    1686                 :          53 :                     n->is_local = false;
    1687                 :          53 :                     $$ = (Node *) n;
    1688                 :             :                 }
    1689                 :             :         ;
    1690                 :             : 
    1691                 :             : set_rest:
    1692                 :             :             TRANSACTION transaction_mode_list
    1693                 :             :                 {
    1694                 :         320 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1695                 :             : 
    1696                 :         320 :                     n->kind = VAR_SET_MULTI;
    1697                 :         320 :                     n->name = "TRANSACTION";
    1698                 :         320 :                     n->args = $2;
    1699                 :         320 :                     n->jumble_args = true;
    1700                 :         320 :                     n->location = -1;
    1701                 :         320 :                     $$ = n;
    1702                 :             :                 }
    1703                 :             :             | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
    1704                 :             :                 {
    1705                 :          12 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1706                 :             : 
    1707                 :          12 :                     n->kind = VAR_SET_MULTI;
    1708                 :          12 :                     n->name = "SESSION CHARACTERISTICS";
    1709                 :          12 :                     n->args = $5;
    1710                 :          12 :                     n->jumble_args = true;
    1711                 :          12 :                     n->location = -1;
    1712                 :          12 :                     $$ = n;
    1713                 :             :                 }
    1714                 :             :             | set_rest_more
    1715                 :             :             ;
    1716                 :             : 
    1717                 :             : generic_set:
    1718                 :             :             var_name TO var_list
    1719                 :             :                 {
    1720                 :        3256 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1721                 :             : 
    1722                 :        3255 :                     n->kind = VAR_SET_VALUE;
    1723                 :        3255 :                     n->name = $1;
    1724                 :        3255 :                     n->args = $3;
    1725                 :        3255 :                     n->location = @3;
    1726                 :        3255 :                     $$ = n;
    1727                 :             :                 }
    1728                 :             :             | var_name '=' var_list
    1729                 :             :                 {
    1730                 :        9318 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1731                 :             : 
    1732                 :        9318 :                     n->kind = VAR_SET_VALUE;
    1733                 :        9318 :                     n->name = $1;
    1734                 :        9318 :                     n->args = $3;
    1735                 :        9318 :                     n->location = @3;
    1736                 :        9318 :                     $$ = n;
    1737                 :             :                 }
    1738                 :             :             | var_name TO NULL_P
    1739                 :             :                 {
    1740                 :           5 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1741                 :             : 
    1742                 :           5 :                     n->kind = VAR_SET_VALUE;
    1743                 :           5 :                     n->name = $1;
    1744                 :           5 :                     n->args = list_make1(makeNullAConst(@3));
    1745                 :           5 :                     n->location = @3;
    1746                 :           5 :                     $$ = n;
    1747                 :             :                 }
    1748                 :             :             | var_name '=' NULL_P
    1749                 :             :                 {
    1750                 :          12 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1751                 :             : 
    1752                 :          12 :                     n->kind = VAR_SET_VALUE;
    1753                 :          12 :                     n->name = $1;
    1754                 :          12 :                     n->args = list_make1(makeNullAConst(@3));
    1755                 :          12 :                     n->location = @3;
    1756                 :          12 :                     $$ = n;
    1757                 :             :                 }
    1758                 :             :             | var_name TO DEFAULT
    1759                 :             :                 {
    1760                 :          90 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1761                 :             : 
    1762                 :          90 :                     n->kind = VAR_SET_DEFAULT;
    1763                 :          90 :                     n->name = $1;
    1764                 :          90 :                     n->location = -1;
    1765                 :          90 :                     $$ = n;
    1766                 :             :                 }
    1767                 :             :             | var_name '=' DEFAULT
    1768                 :             :                 {
    1769                 :           7 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1770                 :             : 
    1771                 :           7 :                     n->kind = VAR_SET_DEFAULT;
    1772                 :           7 :                     n->name = $1;
    1773                 :           7 :                     n->location = -1;
    1774                 :           7 :                     $$ = n;
    1775                 :             :                 }
    1776                 :             :         ;
    1777                 :             : 
    1778                 :             : set_rest_more:  /* Generic SET syntaxes: */
    1779                 :       12588 :             generic_set                         {$$ = $1;}
    1780                 :             :             | var_name FROM CURRENT_P
    1781                 :             :                 {
    1782                 :           2 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1783                 :             : 
    1784                 :           2 :                     n->kind = VAR_SET_CURRENT;
    1785                 :           2 :                     n->name = $1;
    1786                 :           2 :                     n->location = -1;
    1787                 :           2 :                     $$ = n;
    1788                 :             :                 }
    1789                 :             :             /* Special syntaxes mandated by SQL standard: */
    1790                 :             :             | TIME ZONE zone_value
    1791                 :             :                 {
    1792                 :          67 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1793                 :             : 
    1794                 :          67 :                     n->kind = VAR_SET_VALUE;
    1795                 :          67 :                     n->name = "timezone";
    1796                 :          67 :                     n->location = -1;
    1797                 :          67 :                     n->jumble_args = true;
    1798         [ +  + ]:          67 :                     if ($3 != NULL)
    1799                 :          57 :                         n->args = list_make1($3);
    1800                 :             :                     else
    1801                 :          10 :                         n->kind = VAR_SET_DEFAULT;
    1802                 :          67 :                     $$ = n;
    1803                 :             :                 }
    1804                 :             :             | CATALOG_P Sconst
    1805                 :             :                 {
    1806         [ #  # ]:           0 :                     ereport(ERROR,
    1807                 :             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    1808                 :             :                              errmsg("current database cannot be changed"),
    1809                 :             :                              parser_errposition(@2)));
    1810                 :             :                     $$ = NULL; /*not reached*/
    1811                 :             :                 }
    1812                 :             :             | SCHEMA Sconst
    1813                 :             :                 {
    1814                 :           2 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1815                 :             : 
    1816                 :           2 :                     n->kind = VAR_SET_VALUE;
    1817                 :           2 :                     n->name = "search_path";
    1818                 :           2 :                     n->args = list_make1(makeStringConst($2, @2));
    1819                 :           2 :                     n->location = @2;
    1820                 :           2 :                     $$ = n;
    1821                 :             :                 }
    1822                 :             :             | NAMES opt_encoding
    1823                 :             :                 {
    1824                 :           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1825                 :             : 
    1826                 :           0 :                     n->kind = VAR_SET_VALUE;
    1827                 :           0 :                     n->name = "client_encoding";
    1828                 :           0 :                     n->location = @2;
    1829         [ #  # ]:           0 :                     if ($2 != NULL)
    1830                 :           0 :                         n->args = list_make1(makeStringConst($2, @2));
    1831                 :             :                     else
    1832                 :           0 :                         n->kind = VAR_SET_DEFAULT;
    1833                 :           0 :                     $$ = n;
    1834                 :             :                 }
    1835                 :             :             | ROLE NonReservedWord_or_Sconst
    1836                 :             :                 {
    1837                 :         690 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1838                 :             : 
    1839                 :         690 :                     n->kind = VAR_SET_VALUE;
    1840                 :         690 :                     n->name = "role";
    1841                 :         690 :                     n->args = list_make1(makeStringConst($2, @2));
    1842                 :         690 :                     n->location = @2;
    1843                 :         690 :                     $$ = n;
    1844                 :             :                 }
    1845                 :             :             | SESSION AUTHORIZATION NonReservedWord_or_Sconst
    1846                 :             :                 {
    1847                 :        1799 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1848                 :             : 
    1849                 :        1799 :                     n->kind = VAR_SET_VALUE;
    1850                 :        1799 :                     n->name = "session_authorization";
    1851                 :        1799 :                     n->args = list_make1(makeStringConst($3, @3));
    1852                 :        1799 :                     n->location = @3;
    1853                 :        1799 :                     $$ = n;
    1854                 :             :                 }
    1855                 :             :             | SESSION AUTHORIZATION DEFAULT
    1856                 :             :                 {
    1857                 :           2 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1858                 :             : 
    1859                 :           2 :                     n->kind = VAR_SET_DEFAULT;
    1860                 :           2 :                     n->name = "session_authorization";
    1861                 :           2 :                     n->location = -1;
    1862                 :           2 :                     $$ = n;
    1863                 :             :                 }
    1864                 :             :             | XML_P OPTION document_or_content
    1865                 :             :                 {
    1866                 :          10 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1867                 :             : 
    1868                 :          10 :                     n->kind = VAR_SET_VALUE;
    1869                 :          10 :                     n->name = "xmloption";
    1870         [ +  + ]:          10 :                     n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
    1871                 :          10 :                     n->jumble_args = true;
    1872                 :          10 :                     n->location = -1;
    1873                 :          10 :                     $$ = n;
    1874                 :             :                 }
    1875                 :             :             /* Special syntaxes invented by PostgreSQL: */
    1876                 :             :             | TRANSACTION SNAPSHOT Sconst
    1877                 :             :                 {
    1878                 :          25 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1879                 :             : 
    1880                 :          25 :                     n->kind = VAR_SET_MULTI;
    1881                 :          25 :                     n->name = "TRANSACTION SNAPSHOT";
    1882                 :          25 :                     n->args = list_make1(makeStringConst($3, @3));
    1883                 :          25 :                     n->location = @3;
    1884                 :          25 :                     $$ = n;
    1885                 :             :                 }
    1886                 :             :         ;
    1887                 :             : 
    1888                 :       16003 : var_name:   ColId                               { $$ = $1; }
    1889                 :             :             | var_name '.' ColId
    1890                 :         481 :                 { $$ = psprintf("%s.%s", $1, $3); }
    1891                 :             :         ;
    1892                 :             : 
    1893                 :       12574 : var_list:   var_value                               { $$ = list_make1($1); }
    1894                 :         141 :             | var_list ',' var_value                { $$ = lappend($1, $3); }
    1895                 :             :         ;
    1896                 :             : 
    1897                 :             : var_value:  opt_boolean_or_string
    1898                 :        9562 :                 { $$ = makeStringConst($1, @1); }
    1899                 :             :             | NumericOnly
    1900                 :        3153 :                 { $$ = makeAConst($1, @1); }
    1901                 :             :         ;
    1902                 :             : 
    1903                 :           0 : iso_level:  READ UNCOMMITTED                        { $$ = "read uncommitted"; }
    1904                 :         568 :             | READ COMMITTED                        { $$ = "read committed"; }
    1905                 :        1437 :             | REPEATABLE READ                       { $$ = "repeatable read"; }
    1906                 :        1657 :             | SERIALIZABLE                          { $$ = "serializable"; }
    1907                 :             :         ;
    1908                 :             : 
    1909                 :             : opt_boolean_or_string:
    1910                 :         447 :             TRUE_P                                  { $$ = "true"; }
    1911                 :         872 :             | FALSE_P                               { $$ = "false"; }
    1912                 :        1597 :             | ON                                    { $$ = "on"; }
    1913                 :             :             /*
    1914                 :             :              * OFF is also accepted as a boolean value, but is handled by
    1915                 :             :              * the NonReservedWord rule.  The action for booleans and strings
    1916                 :             :              * is the same, so we don't need to distinguish them here.
    1917                 :             :              */
    1918                 :       22055 :             | NonReservedWord_or_Sconst             { $$ = $1; }
    1919                 :             :         ;
    1920                 :             : 
    1921                 :             : /* Timezone values can be:
    1922                 :             :  * - a string such as 'pst8pdt'
    1923                 :             :  * - an identifier such as "pst8pdt"
    1924                 :             :  * - an integer or floating point number
    1925                 :             :  * - a time interval per SQL99
    1926                 :             :  * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
    1927                 :             :  * so use IDENT (meaning we reject anything that is a key word).
    1928                 :             :  */
    1929                 :             : zone_value:
    1930                 :             :             Sconst
    1931                 :             :                 {
    1932                 :          39 :                     $$ = makeStringConst($1, @1);
    1933                 :             :                 }
    1934                 :             :             | IDENT
    1935                 :             :                 {
    1936                 :           2 :                     $$ = makeStringConst($1, @1);
    1937                 :             :                 }
    1938                 :             :             | ConstInterval Sconst opt_interval
    1939                 :             :                 {
    1940                 :           0 :                     TypeName   *t = $1;
    1941                 :             : 
    1942         [ #  # ]:           0 :                     if ($3 != NIL)
    1943                 :             :                     {
    1944                 :           0 :                         A_Const    *n = (A_Const *) linitial($3);
    1945                 :             : 
    1946         [ #  # ]:           0 :                         if ((n->val.ival.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
    1947         [ #  # ]:           0 :                             ereport(ERROR,
    1948                 :             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    1949                 :             :                                      errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
    1950                 :             :                                      parser_errposition(@3)));
    1951                 :             :                     }
    1952                 :           0 :                     t->typmods = $3;
    1953                 :           0 :                     $$ = makeStringConstCast($2, @2, t);
    1954                 :             :                 }
    1955                 :             :             | ConstInterval '(' Iconst ')' Sconst
    1956                 :             :                 {
    1957                 :           0 :                     TypeName   *t = $1;
    1958                 :             : 
    1959                 :           0 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
    1960                 :             :                                             makeIntConst($3, @3));
    1961                 :           0 :                     $$ = makeStringConstCast($5, @5, t);
    1962                 :             :                 }
    1963                 :          16 :             | NumericOnly                           { $$ = makeAConst($1, @1); }
    1964                 :           9 :             | DEFAULT                               { $$ = NULL; }
    1965                 :           1 :             | LOCAL                                 { $$ = NULL; }
    1966                 :             :         ;
    1967                 :             : 
    1968                 :             : opt_encoding:
    1969                 :           0 :             Sconst                                  { $$ = $1; }
    1970                 :           0 :             | DEFAULT                               { $$ = NULL; }
    1971                 :           0 :             | /*EMPTY*/                             { $$ = NULL; }
    1972                 :             :         ;
    1973                 :             : 
    1974                 :             : NonReservedWord_or_Sconst:
    1975                 :       33918 :             NonReservedWord                         { $$ = $1; }
    1976                 :        4181 :             | Sconst                                { $$ = $1; }
    1977                 :             :         ;
    1978                 :             : 
    1979                 :             : VariableResetStmt:
    1980                 :        3307 :             RESET reset_rest                        { $$ = (Node *) $2; }
    1981                 :             :         ;
    1982                 :             : 
    1983                 :             : reset_rest:
    1984                 :        2728 :             generic_reset                           { $$ = $1; }
    1985                 :             :             | TIME ZONE
    1986                 :             :                 {
    1987                 :           9 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1988                 :             : 
    1989                 :           9 :                     n->kind = VAR_RESET;
    1990                 :           9 :                     n->name = "timezone";
    1991                 :           9 :                     n->location = -1;
    1992                 :           9 :                     $$ = n;
    1993                 :             :                 }
    1994                 :             :             | TRANSACTION ISOLATION LEVEL
    1995                 :             :                 {
    1996                 :           0 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    1997                 :             : 
    1998                 :           0 :                     n->kind = VAR_RESET;
    1999                 :           0 :                     n->name = "transaction_isolation";
    2000                 :           0 :                     n->location = -1;
    2001                 :           0 :                     $$ = n;
    2002                 :             :                 }
    2003                 :             :             | SESSION AUTHORIZATION
    2004                 :             :                 {
    2005                 :         570 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    2006                 :             : 
    2007                 :         570 :                     n->kind = VAR_RESET;
    2008                 :         570 :                     n->name = "session_authorization";
    2009                 :         570 :                     n->location = -1;
    2010                 :         570 :                     $$ = n;
    2011                 :             :                 }
    2012                 :             :         ;
    2013                 :             : 
    2014                 :             : generic_reset:
    2015                 :             :             var_name
    2016                 :             :                 {
    2017                 :        2740 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    2018                 :             : 
    2019                 :        2740 :                     n->kind = VAR_RESET;
    2020                 :        2740 :                     n->name = $1;
    2021                 :        2740 :                     n->location = -1;
    2022                 :        2740 :                     $$ = n;
    2023                 :             :                 }
    2024                 :             :             | ALL
    2025                 :             :                 {
    2026                 :          17 :                     VariableSetStmt *n = makeNode(VariableSetStmt);
    2027                 :             : 
    2028                 :          17 :                     n->kind = VAR_RESET_ALL;
    2029                 :          17 :                     n->location = -1;
    2030                 :          17 :                     $$ = n;
    2031                 :             :                 }
    2032                 :             :         ;
    2033                 :             : 
    2034                 :             : /* SetResetClause allows SET or RESET without LOCAL */
    2035                 :             : SetResetClause:
    2036                 :         719 :             SET set_rest                    { $$ = $2; }
    2037                 :          21 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    2038                 :             :         ;
    2039                 :             : 
    2040                 :             : /* SetResetClause allows SET or RESET without LOCAL */
    2041                 :             : FunctionSetResetClause:
    2042                 :          89 :             SET set_rest_more               { $$ = $2; }
    2043                 :           8 :             | VariableResetStmt             { $$ = (VariableSetStmt *) $1; }
    2044                 :             :         ;
    2045                 :             : 
    2046                 :             : 
    2047                 :             : VariableShowStmt:
    2048                 :             :             SHOW var_name
    2049                 :             :                 {
    2050                 :         573 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2051                 :             : 
    2052                 :         573 :                     n->name = $2;
    2053                 :         573 :                     $$ = (Node *) n;
    2054                 :             :                 }
    2055                 :             :             | SHOW TIME ZONE
    2056                 :             :                 {
    2057                 :           6 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2058                 :             : 
    2059                 :           6 :                     n->name = "timezone";
    2060                 :           6 :                     $$ = (Node *) n;
    2061                 :             :                 }
    2062                 :             :             | SHOW TRANSACTION ISOLATION LEVEL
    2063                 :             :                 {
    2064                 :           2 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2065                 :             : 
    2066                 :           2 :                     n->name = "transaction_isolation";
    2067                 :           2 :                     $$ = (Node *) n;
    2068                 :             :                 }
    2069                 :             :             | SHOW SESSION AUTHORIZATION
    2070                 :             :                 {
    2071                 :           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2072                 :             : 
    2073                 :           0 :                     n->name = "session_authorization";
    2074                 :           0 :                     $$ = (Node *) n;
    2075                 :             :                 }
    2076                 :             :             | SHOW ALL
    2077                 :             :                 {
    2078                 :           0 :                     VariableShowStmt *n = makeNode(VariableShowStmt);
    2079                 :             : 
    2080                 :           0 :                     n->name = "all";
    2081                 :           0 :                     $$ = (Node *) n;
    2082                 :             :                 }
    2083                 :             :         ;
    2084                 :             : 
    2085                 :             : 
    2086                 :             : ConstraintsSetStmt:
    2087                 :             :             SET CONSTRAINTS constraints_set_list constraints_set_mode
    2088                 :             :                 {
    2089                 :          72 :                     ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
    2090                 :             : 
    2091                 :          72 :                     n->constraints = $3;
    2092                 :          72 :                     n->deferred = $4;
    2093                 :          72 :                     $$ = (Node *) n;
    2094                 :             :                 }
    2095                 :             :         ;
    2096                 :             : 
    2097                 :             : constraints_set_list:
    2098                 :          40 :             ALL                                     { $$ = NIL; }
    2099                 :          32 :             | qualified_name_list                   { $$ = $1; }
    2100                 :             :         ;
    2101                 :             : 
    2102                 :             : constraints_set_mode:
    2103                 :          45 :             DEFERRED                                { $$ = true; }
    2104                 :          27 :             | IMMEDIATE                             { $$ = false; }
    2105                 :             :         ;
    2106                 :             : 
    2107                 :             : 
    2108                 :             : /*
    2109                 :             :  * Checkpoint statement
    2110                 :             :  */
    2111                 :             : CheckPointStmt:
    2112                 :             :             CHECKPOINT opt_utility_option_list
    2113                 :             :                 {
    2114                 :         156 :                     CheckPointStmt *n = makeNode(CheckPointStmt);
    2115                 :             : 
    2116                 :         156 :                     $$ = (Node *) n;
    2117                 :         156 :                     n->options = $2;
    2118                 :             :                 }
    2119                 :             :         ;
    2120                 :             : 
    2121                 :             : 
    2122                 :             : /*****************************************************************************
    2123                 :             :  *
    2124                 :             :  * DISCARD { ALL | TEMP | PLANS | SEQUENCES }
    2125                 :             :  *
    2126                 :             :  *****************************************************************************/
    2127                 :             : 
    2128                 :             : DiscardStmt:
    2129                 :             :             DISCARD ALL
    2130                 :             :                 {
    2131                 :           4 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2132                 :             : 
    2133                 :           4 :                     n->target = DISCARD_ALL;
    2134                 :           4 :                     $$ = (Node *) n;
    2135                 :             :                 }
    2136                 :             :             | DISCARD TEMP
    2137                 :             :                 {
    2138                 :           9 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2139                 :             : 
    2140                 :           9 :                     n->target = DISCARD_TEMP;
    2141                 :           9 :                     $$ = (Node *) n;
    2142                 :             :                 }
    2143                 :             :             | DISCARD TEMPORARY
    2144                 :             :                 {
    2145                 :           0 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2146                 :             : 
    2147                 :           0 :                     n->target = DISCARD_TEMP;
    2148                 :           0 :                     $$ = (Node *) n;
    2149                 :             :                 }
    2150                 :             :             | DISCARD PLANS
    2151                 :             :                 {
    2152                 :           3 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2153                 :             : 
    2154                 :           3 :                     n->target = DISCARD_PLANS;
    2155                 :           3 :                     $$ = (Node *) n;
    2156                 :             :                 }
    2157                 :             :             | DISCARD SEQUENCES
    2158                 :             :                 {
    2159                 :           8 :                     DiscardStmt *n = makeNode(DiscardStmt);
    2160                 :             : 
    2161                 :           8 :                     n->target = DISCARD_SEQUENCES;
    2162                 :           8 :                     $$ = (Node *) n;
    2163                 :             :                 }
    2164                 :             : 
    2165                 :             :         ;
    2166                 :             : 
    2167                 :             : 
    2168                 :             : /*****************************************************************************
    2169                 :             :  *
    2170                 :             :  *  ALTER [ TABLE | INDEX | SEQUENCE | VIEW | MATERIALIZED VIEW | FOREIGN TABLE ] variations
    2171                 :             :  *
    2172                 :             :  * Note: we accept all subcommands for each of the variants, and sort
    2173                 :             :  * out what's really legal at execution time.
    2174                 :             :  *****************************************************************************/
    2175                 :             : 
    2176                 :             : AlterTableStmt:
    2177                 :             :             ALTER TABLE relation_expr alter_table_cmds
    2178                 :             :                 {
    2179                 :       17022 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2180                 :             : 
    2181                 :       17022 :                     n->relation = $3;
    2182                 :       17022 :                     n->cmds = $4;
    2183                 :       17022 :                     n->objtype = OBJECT_TABLE;
    2184                 :       17022 :                     n->missing_ok = false;
    2185                 :       17022 :                     $$ = (Node *) n;
    2186                 :             :                 }
    2187                 :             :         |   ALTER TABLE IF_P EXISTS relation_expr alter_table_cmds
    2188                 :             :                 {
    2189                 :          36 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2190                 :             : 
    2191                 :          36 :                     n->relation = $5;
    2192                 :          36 :                     n->cmds = $6;
    2193                 :          36 :                     n->objtype = OBJECT_TABLE;
    2194                 :          36 :                     n->missing_ok = true;
    2195                 :          36 :                     $$ = (Node *) n;
    2196                 :             :                 }
    2197                 :             :         |   ALTER TABLE relation_expr partition_cmd
    2198                 :             :                 {
    2199                 :        1946 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2200                 :             : 
    2201                 :        1946 :                     n->relation = $3;
    2202                 :        1946 :                     n->cmds = list_make1($4);
    2203                 :        1946 :                     n->objtype = OBJECT_TABLE;
    2204                 :        1946 :                     n->missing_ok = false;
    2205                 :        1946 :                     $$ = (Node *) n;
    2206                 :             :                 }
    2207                 :             :         |   ALTER TABLE IF_P EXISTS relation_expr partition_cmd
    2208                 :             :                 {
    2209                 :           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2210                 :             : 
    2211                 :           0 :                     n->relation = $5;
    2212                 :           0 :                     n->cmds = list_make1($6);
    2213                 :           0 :                     n->objtype = OBJECT_TABLE;
    2214                 :           0 :                     n->missing_ok = true;
    2215                 :           0 :                     $$ = (Node *) n;
    2216                 :             :                 }
    2217                 :             :         |   ALTER TABLE ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2218                 :             :                 {
    2219                 :             :                     AlterTableMoveAllStmt *n =
    2220                 :           7 :                         makeNode(AlterTableMoveAllStmt);
    2221                 :             : 
    2222                 :           7 :                     n->orig_tablespacename = $6;
    2223                 :           7 :                     n->objtype = OBJECT_TABLE;
    2224                 :           7 :                     n->roles = NIL;
    2225                 :           7 :                     n->new_tablespacename = $9;
    2226                 :           7 :                     n->nowait = $10;
    2227                 :           7 :                     $$ = (Node *) n;
    2228                 :             :                 }
    2229                 :             :         |   ALTER TABLE ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2230                 :             :                 {
    2231                 :             :                     AlterTableMoveAllStmt *n =
    2232                 :           0 :                         makeNode(AlterTableMoveAllStmt);
    2233                 :             : 
    2234                 :           0 :                     n->orig_tablespacename = $6;
    2235                 :           0 :                     n->objtype = OBJECT_TABLE;
    2236                 :           0 :                     n->roles = $9;
    2237                 :           0 :                     n->new_tablespacename = $12;
    2238                 :           0 :                     n->nowait = $13;
    2239                 :           0 :                     $$ = (Node *) n;
    2240                 :             :                 }
    2241                 :             :         |   ALTER INDEX qualified_name alter_table_cmds
    2242                 :             :                 {
    2243                 :         146 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2244                 :             : 
    2245                 :         146 :                     n->relation = $3;
    2246                 :         146 :                     n->cmds = $4;
    2247                 :         146 :                     n->objtype = OBJECT_INDEX;
    2248                 :         146 :                     n->missing_ok = false;
    2249                 :         146 :                     $$ = (Node *) n;
    2250                 :             :                 }
    2251                 :             :         |   ALTER INDEX IF_P EXISTS qualified_name alter_table_cmds
    2252                 :             :                 {
    2253                 :           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2254                 :             : 
    2255                 :           0 :                     n->relation = $5;
    2256                 :           0 :                     n->cmds = $6;
    2257                 :           0 :                     n->objtype = OBJECT_INDEX;
    2258                 :           0 :                     n->missing_ok = true;
    2259                 :           0 :                     $$ = (Node *) n;
    2260                 :             :                 }
    2261                 :             :         |   ALTER INDEX qualified_name index_partition_cmd
    2262                 :             :                 {
    2263                 :         290 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2264                 :             : 
    2265                 :         290 :                     n->relation = $3;
    2266                 :         290 :                     n->cmds = list_make1($4);
    2267                 :         290 :                     n->objtype = OBJECT_INDEX;
    2268                 :         290 :                     n->missing_ok = false;
    2269                 :         290 :                     $$ = (Node *) n;
    2270                 :             :                 }
    2271                 :             :         |   ALTER INDEX ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2272                 :             :                 {
    2273                 :             :                     AlterTableMoveAllStmt *n =
    2274                 :           3 :                         makeNode(AlterTableMoveAllStmt);
    2275                 :             : 
    2276                 :           3 :                     n->orig_tablespacename = $6;
    2277                 :           3 :                     n->objtype = OBJECT_INDEX;
    2278                 :           3 :                     n->roles = NIL;
    2279                 :           3 :                     n->new_tablespacename = $9;
    2280                 :           3 :                     n->nowait = $10;
    2281                 :           3 :                     $$ = (Node *) n;
    2282                 :             :                 }
    2283                 :             :         |   ALTER INDEX ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2284                 :             :                 {
    2285                 :             :                     AlterTableMoveAllStmt *n =
    2286                 :           0 :                         makeNode(AlterTableMoveAllStmt);
    2287                 :             : 
    2288                 :           0 :                     n->orig_tablespacename = $6;
    2289                 :           0 :                     n->objtype = OBJECT_INDEX;
    2290                 :           0 :                     n->roles = $9;
    2291                 :           0 :                     n->new_tablespacename = $12;
    2292                 :           0 :                     n->nowait = $13;
    2293                 :           0 :                     $$ = (Node *) n;
    2294                 :             :                 }
    2295                 :             :         |   ALTER SEQUENCE qualified_name alter_table_cmds
    2296                 :             :                 {
    2297                 :          51 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2298                 :             : 
    2299                 :          51 :                     n->relation = $3;
    2300                 :          51 :                     n->cmds = $4;
    2301                 :          51 :                     n->objtype = OBJECT_SEQUENCE;
    2302                 :          51 :                     n->missing_ok = false;
    2303                 :          51 :                     $$ = (Node *) n;
    2304                 :             :                 }
    2305                 :             :         |   ALTER SEQUENCE IF_P EXISTS qualified_name alter_table_cmds
    2306                 :             :                 {
    2307                 :           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2308                 :             : 
    2309                 :           0 :                     n->relation = $5;
    2310                 :           0 :                     n->cmds = $6;
    2311                 :           0 :                     n->objtype = OBJECT_SEQUENCE;
    2312                 :           0 :                     n->missing_ok = true;
    2313                 :           0 :                     $$ = (Node *) n;
    2314                 :             :                 }
    2315                 :             :         |   ALTER VIEW qualified_name alter_table_cmds
    2316                 :             :                 {
    2317                 :         150 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2318                 :             : 
    2319                 :         150 :                     n->relation = $3;
    2320                 :         150 :                     n->cmds = $4;
    2321                 :         150 :                     n->objtype = OBJECT_VIEW;
    2322                 :         150 :                     n->missing_ok = false;
    2323                 :         150 :                     $$ = (Node *) n;
    2324                 :             :                 }
    2325                 :             :         |   ALTER VIEW IF_P EXISTS qualified_name alter_table_cmds
    2326                 :             :                 {
    2327                 :           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2328                 :             : 
    2329                 :           0 :                     n->relation = $5;
    2330                 :           0 :                     n->cmds = $6;
    2331                 :           0 :                     n->objtype = OBJECT_VIEW;
    2332                 :           0 :                     n->missing_ok = true;
    2333                 :           0 :                     $$ = (Node *) n;
    2334                 :             :                 }
    2335                 :             :         |   ALTER MATERIALIZED VIEW qualified_name alter_table_cmds
    2336                 :             :                 {
    2337                 :          29 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2338                 :             : 
    2339                 :          29 :                     n->relation = $4;
    2340                 :          29 :                     n->cmds = $5;
    2341                 :          29 :                     n->objtype = OBJECT_MATVIEW;
    2342                 :          29 :                     n->missing_ok = false;
    2343                 :          29 :                     $$ = (Node *) n;
    2344                 :             :                 }
    2345                 :             :         |   ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name alter_table_cmds
    2346                 :             :                 {
    2347                 :           0 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2348                 :             : 
    2349                 :           0 :                     n->relation = $6;
    2350                 :           0 :                     n->cmds = $7;
    2351                 :           0 :                     n->objtype = OBJECT_MATVIEW;
    2352                 :           0 :                     n->missing_ok = true;
    2353                 :           0 :                     $$ = (Node *) n;
    2354                 :             :                 }
    2355                 :             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name SET TABLESPACE name opt_nowait
    2356                 :             :                 {
    2357                 :             :                     AlterTableMoveAllStmt *n =
    2358                 :           6 :                         makeNode(AlterTableMoveAllStmt);
    2359                 :             : 
    2360                 :           6 :                     n->orig_tablespacename = $7;
    2361                 :           6 :                     n->objtype = OBJECT_MATVIEW;
    2362                 :           6 :                     n->roles = NIL;
    2363                 :           6 :                     n->new_tablespacename = $10;
    2364                 :           6 :                     n->nowait = $11;
    2365                 :           6 :                     $$ = (Node *) n;
    2366                 :             :                 }
    2367                 :             :         |   ALTER MATERIALIZED VIEW ALL IN_P TABLESPACE name OWNED BY role_list SET TABLESPACE name opt_nowait
    2368                 :             :                 {
    2369                 :             :                     AlterTableMoveAllStmt *n =
    2370                 :           0 :                         makeNode(AlterTableMoveAllStmt);
    2371                 :             : 
    2372                 :           0 :                     n->orig_tablespacename = $7;
    2373                 :           0 :                     n->objtype = OBJECT_MATVIEW;
    2374                 :           0 :                     n->roles = $10;
    2375                 :           0 :                     n->new_tablespacename = $13;
    2376                 :           0 :                     n->nowait = $14;
    2377                 :           0 :                     $$ = (Node *) n;
    2378                 :             :                 }
    2379                 :             :         |   ALTER FOREIGN TABLE relation_expr alter_table_cmds
    2380                 :             :                 {
    2381                 :         251 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2382                 :             : 
    2383                 :         251 :                     n->relation = $4;
    2384                 :         251 :                     n->cmds = $5;
    2385                 :         251 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2386                 :         251 :                     n->missing_ok = false;
    2387                 :         251 :                     $$ = (Node *) n;
    2388                 :             :                 }
    2389                 :             :         |   ALTER FOREIGN TABLE IF_P EXISTS relation_expr alter_table_cmds
    2390                 :             :                 {
    2391                 :          88 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    2392                 :             : 
    2393                 :          88 :                     n->relation = $6;
    2394                 :          88 :                     n->cmds = $7;
    2395                 :          88 :                     n->objtype = OBJECT_FOREIGN_TABLE;
    2396                 :          88 :                     n->missing_ok = true;
    2397                 :          88 :                     $$ = (Node *) n;
    2398                 :             :                 }
    2399                 :             :         ;
    2400                 :             : 
    2401                 :             : alter_table_cmds:
    2402                 :       17773 :             alter_table_cmd                         { $$ = list_make1($1); }
    2403                 :         694 :             | alter_table_cmds ',' alter_table_cmd  { $$ = lappend($1, $3); }
    2404                 :             :         ;
    2405                 :             : 
    2406                 :             : partition_cmd:
    2407                 :             :             /* ALTER TABLE <name> ATTACH PARTITION <table_name> FOR VALUES */
    2408                 :             :             ATTACH PARTITION qualified_name PartitionBoundSpec
    2409                 :             :                 {
    2410                 :        1557 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2411                 :        1557 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2412                 :             : 
    2413                 :        1557 :                     n->subtype = AT_AttachPartition;
    2414                 :        1557 :                     cmd->name = $3;
    2415                 :        1557 :                     cmd->bound = $4;
    2416                 :        1557 :                     cmd->concurrent = false;
    2417                 :        1557 :                     n->def = (Node *) cmd;
    2418                 :             : 
    2419                 :        1557 :                     $$ = (Node *) n;
    2420                 :             :                 }
    2421                 :             :             /* ALTER TABLE <name> DETACH PARTITION <partition_name> [CONCURRENTLY] */
    2422                 :             :             | DETACH PARTITION qualified_name opt_concurrently
    2423                 :             :                 {
    2424                 :         378 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2425                 :         378 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2426                 :             : 
    2427                 :         378 :                     n->subtype = AT_DetachPartition;
    2428                 :         378 :                     cmd->name = $3;
    2429                 :         378 :                     cmd->bound = NULL;
    2430                 :         378 :                     cmd->concurrent = $4;
    2431                 :         378 :                     n->def = (Node *) cmd;
    2432                 :             : 
    2433                 :         378 :                     $$ = (Node *) n;
    2434                 :             :                 }
    2435                 :             :             | DETACH PARTITION qualified_name FINALIZE
    2436                 :             :                 {
    2437                 :          11 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2438                 :          11 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2439                 :             : 
    2440                 :          11 :                     n->subtype = AT_DetachPartitionFinalize;
    2441                 :          11 :                     cmd->name = $3;
    2442                 :          11 :                     cmd->bound = NULL;
    2443                 :          11 :                     cmd->concurrent = false;
    2444                 :          11 :                     n->def = (Node *) cmd;
    2445                 :          11 :                     $$ = (Node *) n;
    2446                 :             :                 }
    2447                 :             :         ;
    2448                 :             : 
    2449                 :             : index_partition_cmd:
    2450                 :             :             /* ALTER INDEX <name> ATTACH PARTITION <index_name> */
    2451                 :             :             ATTACH PARTITION qualified_name
    2452                 :             :                 {
    2453                 :         290 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2454                 :         290 :                     PartitionCmd *cmd = makeNode(PartitionCmd);
    2455                 :             : 
    2456                 :         290 :                     n->subtype = AT_AttachPartition;
    2457                 :         290 :                     cmd->name = $3;
    2458                 :         290 :                     cmd->bound = NULL;
    2459                 :         290 :                     cmd->concurrent = false;
    2460                 :         290 :                     n->def = (Node *) cmd;
    2461                 :             : 
    2462                 :         290 :                     $$ = (Node *) n;
    2463                 :             :                 }
    2464                 :             :         ;
    2465                 :             : 
    2466                 :             : alter_table_cmd:
    2467                 :             :             /* ALTER TABLE <name> ADD <coldef> */
    2468                 :             :             ADD_P columnDef
    2469                 :             :                 {
    2470                 :         138 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2471                 :             : 
    2472                 :         138 :                     n->subtype = AT_AddColumn;
    2473                 :         138 :                     n->def = $2;
    2474                 :         138 :                     n->missing_ok = false;
    2475                 :         138 :                     $$ = (Node *) n;
    2476                 :             :                 }
    2477                 :             :             /* ALTER TABLE <name> ADD IF NOT EXISTS <coldef> */
    2478                 :             :             | ADD_P IF_P NOT EXISTS columnDef
    2479                 :             :                 {
    2480                 :           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2481                 :             : 
    2482                 :           4 :                     n->subtype = AT_AddColumn;
    2483                 :           4 :                     n->def = $5;
    2484                 :           4 :                     n->missing_ok = true;
    2485                 :           4 :                     $$ = (Node *) n;
    2486                 :             :                 }
    2487                 :             :             /* ALTER TABLE <name> ADD COLUMN <coldef> */
    2488                 :             :             | ADD_P COLUMN columnDef
    2489                 :             :                 {
    2490                 :        1378 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2491                 :             : 
    2492                 :        1378 :                     n->subtype = AT_AddColumn;
    2493                 :        1378 :                     n->def = $3;
    2494                 :        1378 :                     n->missing_ok = false;
    2495                 :        1378 :                     $$ = (Node *) n;
    2496                 :             :                 }
    2497                 :             :             /* ALTER TABLE <name> ADD COLUMN IF NOT EXISTS <coldef> */
    2498                 :             :             | ADD_P COLUMN IF_P NOT EXISTS columnDef
    2499                 :             :                 {
    2500                 :          48 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2501                 :             : 
    2502                 :          48 :                     n->subtype = AT_AddColumn;
    2503                 :          48 :                     n->def = $6;
    2504                 :          48 :                     n->missing_ok = true;
    2505                 :          48 :                     $$ = (Node *) n;
    2506                 :             :                 }
    2507                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> {SET DEFAULT <expr>|DROP DEFAULT} */
    2508                 :             :             | ALTER opt_column ColId alter_column_default
    2509                 :             :                 {
    2510                 :         365 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2511                 :             : 
    2512                 :         365 :                     n->subtype = AT_ColumnDefault;
    2513                 :         365 :                     n->name = $3;
    2514                 :         365 :                     n->def = $4;
    2515                 :         365 :                     $$ = (Node *) n;
    2516                 :             :                 }
    2517                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP NOT NULL */
    2518                 :             :             | ALTER opt_column ColId DROP NOT NULL_P
    2519                 :             :                 {
    2520                 :         194 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2521                 :             : 
    2522                 :         194 :                     n->subtype = AT_DropNotNull;
    2523                 :         194 :                     n->name = $3;
    2524                 :         194 :                     $$ = (Node *) n;
    2525                 :             :                 }
    2526                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET NOT NULL */
    2527                 :             :             | ALTER opt_column ColId SET NOT NULL_P
    2528                 :             :                 {
    2529                 :         289 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2530                 :             : 
    2531                 :         289 :                     n->subtype = AT_SetNotNull;
    2532                 :         289 :                     n->name = $3;
    2533                 :         289 :                     $$ = (Node *) n;
    2534                 :             :                 }
    2535                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET EXPRESSION AS <expr> */
    2536                 :             :             | ALTER opt_column ColId SET EXPRESSION AS '(' a_expr ')'
    2537                 :             :                 {
    2538                 :         153 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2539                 :             : 
    2540                 :         153 :                     n->subtype = AT_SetExpression;
    2541                 :         153 :                     n->name = $3;
    2542                 :         153 :                     n->def = $8;
    2543                 :         153 :                     $$ = (Node *) n;
    2544                 :             :                 }
    2545                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION */
    2546                 :             :             | ALTER opt_column ColId DROP EXPRESSION
    2547                 :             :                 {
    2548                 :          57 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2549                 :             : 
    2550                 :          57 :                     n->subtype = AT_DropExpression;
    2551                 :          57 :                     n->name = $3;
    2552                 :          57 :                     $$ = (Node *) n;
    2553                 :             :                 }
    2554                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP EXPRESSION IF EXISTS */
    2555                 :             :             | ALTER opt_column ColId DROP EXPRESSION IF_P EXISTS
    2556                 :             :                 {
    2557                 :           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2558                 :             : 
    2559                 :           8 :                     n->subtype = AT_DropExpression;
    2560                 :           8 :                     n->name = $3;
    2561                 :           8 :                     n->missing_ok = true;
    2562                 :           8 :                     $$ = (Node *) n;
    2563                 :             :                 }
    2564                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STATISTICS */
    2565                 :             :             | ALTER opt_column ColId SET STATISTICS set_statistics_value
    2566                 :             :                 {
    2567                 :          44 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2568                 :             : 
    2569                 :          44 :                     n->subtype = AT_SetStatistics;
    2570                 :          44 :                     n->name = $3;
    2571                 :          44 :                     n->def = $6;
    2572                 :          44 :                     $$ = (Node *) n;
    2573                 :             :                 }
    2574                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colnum> SET STATISTICS */
    2575                 :             :             | ALTER opt_column Iconst SET STATISTICS set_statistics_value
    2576                 :             :                 {
    2577                 :          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2578                 :             : 
    2579   [ +  +  -  + ]:          46 :                     if ($3 <= 0 || $3 > PG_INT16_MAX)
    2580         [ +  - ]:           4 :                         ereport(ERROR,
    2581                 :             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
    2582                 :             :                                  errmsg("column number must be in range from 1 to %d", PG_INT16_MAX),
    2583                 :             :                                  parser_errposition(@3)));
    2584                 :             : 
    2585                 :          42 :                     n->subtype = AT_SetStatistics;
    2586                 :          42 :                     n->num = (int16) $3;
    2587                 :          42 :                     n->def = $6;
    2588                 :          42 :                     $$ = (Node *) n;
    2589                 :             :                 }
    2590                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET ( column_parameter = value [, ... ] ) */
    2591                 :             :             | ALTER opt_column ColId SET reloptions
    2592                 :             :                 {
    2593                 :          25 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2594                 :             : 
    2595                 :          25 :                     n->subtype = AT_SetOptions;
    2596                 :          25 :                     n->name = $3;
    2597                 :          25 :                     n->def = (Node *) $5;
    2598                 :          25 :                     $$ = (Node *) n;
    2599                 :             :                 }
    2600                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> RESET ( column_parameter [, ... ] ) */
    2601                 :             :             | ALTER opt_column ColId RESET reloptions
    2602                 :             :                 {
    2603                 :           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2604                 :             : 
    2605                 :           4 :                     n->subtype = AT_ResetOptions;
    2606                 :           4 :                     n->name = $3;
    2607                 :           4 :                     n->def = (Node *) $5;
    2608                 :           4 :                     $$ = (Node *) n;
    2609                 :             :                 }
    2610                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET STORAGE <storagemode> */
    2611                 :             :             | ALTER opt_column ColId SET column_storage
    2612                 :             :                 {
    2613                 :         219 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2614                 :             : 
    2615                 :         219 :                     n->subtype = AT_SetStorage;
    2616                 :         219 :                     n->name = $3;
    2617                 :         219 :                     n->def = (Node *) makeString($5);
    2618                 :         219 :                     $$ = (Node *) n;
    2619                 :             :                 }
    2620                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET COMPRESSION <cm> */
    2621                 :             :             | ALTER opt_column ColId SET column_compression
    2622                 :             :                 {
    2623                 :          48 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2624                 :             : 
    2625                 :          48 :                     n->subtype = AT_SetCompression;
    2626                 :          48 :                     n->name = $3;
    2627                 :          48 :                     n->def = (Node *) makeString($5);
    2628                 :          48 :                     $$ = (Node *) n;
    2629                 :             :                 }
    2630                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> ADD GENERATED ... AS IDENTITY ... */
    2631                 :             :             | ALTER opt_column ColId ADD_P GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    2632                 :             :                 {
    2633                 :         107 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2634                 :         107 :                     Constraint *c = makeNode(Constraint);
    2635                 :             : 
    2636                 :         107 :                     c->contype = CONSTR_IDENTITY;
    2637                 :         107 :                     c->generated_when = $6;
    2638                 :         107 :                     c->options = $9;
    2639                 :         107 :                     c->location = @5;
    2640                 :             : 
    2641                 :         107 :                     n->subtype = AT_AddIdentity;
    2642                 :         107 :                     n->name = $3;
    2643                 :         107 :                     n->def = (Node *) c;
    2644                 :             : 
    2645                 :         107 :                     $$ = (Node *) n;
    2646                 :             :                 }
    2647                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> SET <sequence options>/RESET */
    2648                 :             :             | ALTER opt_column ColId alter_identity_column_option_list
    2649                 :             :                 {
    2650                 :          41 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2651                 :             : 
    2652                 :          41 :                     n->subtype = AT_SetIdentity;
    2653                 :          41 :                     n->name = $3;
    2654                 :          41 :                     n->def = (Node *) $4;
    2655                 :          41 :                     $$ = (Node *) n;
    2656                 :             :                 }
    2657                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY */
    2658                 :             :             | ALTER opt_column ColId DROP IDENTITY_P
    2659                 :             :                 {
    2660                 :          33 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2661                 :             : 
    2662                 :          33 :                     n->subtype = AT_DropIdentity;
    2663                 :          33 :                     n->name = $3;
    2664                 :          33 :                     n->missing_ok = false;
    2665                 :          33 :                     $$ = (Node *) n;
    2666                 :             :                 }
    2667                 :             :             /* ALTER TABLE <name> ALTER [COLUMN] <colname> DROP IDENTITY IF EXISTS */
    2668                 :             :             | ALTER opt_column ColId DROP IDENTITY_P IF_P EXISTS
    2669                 :             :                 {
    2670                 :           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2671                 :             : 
    2672                 :           4 :                     n->subtype = AT_DropIdentity;
    2673                 :           4 :                     n->name = $3;
    2674                 :           4 :                     n->missing_ok = true;
    2675                 :           4 :                     $$ = (Node *) n;
    2676                 :             :                 }
    2677                 :             :             /* ALTER TABLE <name> DROP [COLUMN] IF EXISTS <colname> [RESTRICT|CASCADE] */
    2678                 :             :             | DROP opt_column IF_P EXISTS ColId opt_drop_behavior
    2679                 :             :                 {
    2680                 :          16 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2681                 :             : 
    2682                 :          16 :                     n->subtype = AT_DropColumn;
    2683                 :          16 :                     n->name = $5;
    2684                 :          16 :                     n->behavior = $6;
    2685                 :          16 :                     n->missing_ok = true;
    2686                 :          16 :                     $$ = (Node *) n;
    2687                 :             :                 }
    2688                 :             :             /* ALTER TABLE <name> DROP [COLUMN] <colname> [RESTRICT|CASCADE] */
    2689                 :             :             | DROP opt_column ColId opt_drop_behavior
    2690                 :             :                 {
    2691                 :        1048 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2692                 :             : 
    2693                 :        1048 :                     n->subtype = AT_DropColumn;
    2694                 :        1048 :                     n->name = $3;
    2695                 :        1048 :                     n->behavior = $4;
    2696                 :        1048 :                     n->missing_ok = false;
    2697                 :        1048 :                     $$ = (Node *) n;
    2698                 :             :                 }
    2699                 :             :             /*
    2700                 :             :              * ALTER TABLE <name> ALTER [COLUMN] <colname> [SET DATA] TYPE <typename>
    2701                 :             :              *      [ USING <expression> ]
    2702                 :             :              */
    2703                 :             :             | ALTER opt_column ColId opt_set_data TYPE_P Typename opt_collate_clause alter_using
    2704                 :             :                 {
    2705                 :         766 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2706                 :         766 :                     ColumnDef *def = makeNode(ColumnDef);
    2707                 :             : 
    2708                 :         766 :                     n->subtype = AT_AlterColumnType;
    2709                 :         766 :                     n->name = $3;
    2710                 :         766 :                     n->def = (Node *) def;
    2711                 :             :                     /* We only use these fields of the ColumnDef node */
    2712                 :         766 :                     def->typeName = $6;
    2713                 :         766 :                     def->collClause = (CollateClause *) $7;
    2714                 :         766 :                     def->raw_default = $8;
    2715                 :         766 :                     def->location = @3;
    2716                 :         766 :                     $$ = (Node *) n;
    2717                 :             :                 }
    2718                 :             :             /* ALTER FOREIGN TABLE <name> ALTER [COLUMN] <colname> OPTIONS */
    2719                 :             :             | ALTER opt_column ColId alter_generic_options
    2720                 :             :                 {
    2721                 :          33 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2722                 :             : 
    2723                 :          33 :                     n->subtype = AT_AlterColumnGenericOptions;
    2724                 :          33 :                     n->name = $3;
    2725                 :          33 :                     n->def = (Node *) $4;
    2726                 :          33 :                     $$ = (Node *) n;
    2727                 :             :                 }
    2728                 :             :             /* ALTER TABLE <name> ADD CONSTRAINT ... */
    2729                 :             :             | ADD_P TableConstraint
    2730                 :             :                 {
    2731                 :        8947 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2732                 :             : 
    2733                 :        8947 :                     n->subtype = AT_AddConstraint;
    2734                 :        8947 :                     n->def = $2;
    2735                 :        8947 :                     $$ = (Node *) n;
    2736                 :             :                 }
    2737                 :             :             /* ALTER TABLE <name> ALTER CONSTRAINT ... */
    2738                 :             :             | ALTER CONSTRAINT name ConstraintAttributeSpec
    2739                 :             :                 {
    2740                 :         300 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2741                 :         300 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2742                 :             : 
    2743                 :         300 :                     n->subtype = AT_AlterConstraint;
    2744                 :         300 :                     n->def = (Node *) c;
    2745                 :         300 :                     c->conname = $3;
    2746         [ +  + ]:         300 :                     if ($4 & (CAS_NOT_ENFORCED | CAS_ENFORCED))
    2747                 :         192 :                         c->alterEnforceability = true;
    2748         [ +  + ]:         300 :                     if ($4 & (CAS_DEFERRABLE | CAS_NOT_DEFERRABLE |
    2749                 :             :                               CAS_INITIALLY_DEFERRED | CAS_INITIALLY_IMMEDIATE))
    2750                 :          80 :                         c->alterDeferrability = true;
    2751         [ +  + ]:         300 :                     if ($4 & CAS_NO_INHERIT)
    2752                 :          24 :                         c->alterInheritability = true;
    2753                 :             :                     /* handle unsupported case with specific error message */
    2754         [ +  + ]:         300 :                     if ($4 & CAS_NOT_VALID)
    2755         [ +  - ]:           8 :                         ereport(ERROR,
    2756                 :             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    2757                 :             :                                 errmsg("constraints cannot be altered to be NOT VALID"),
    2758                 :             :                                 parser_errposition(@4));
    2759                 :         292 :                     processCASbits($4, @4, "FOREIGN KEY",
    2760                 :             :                                     &c->deferrable,
    2761                 :             :                                     &c->initdeferred,
    2762                 :             :                                     &c->is_enforced,
    2763                 :             :                                     NULL,
    2764                 :             :                                     &c->noinherit,
    2765                 :             :                                     yyscanner);
    2766                 :         292 :                     $$ = (Node *) n;
    2767                 :             :                 }
    2768                 :             :             /* ALTER TABLE <name> ALTER CONSTRAINT INHERIT */
    2769                 :             :             | ALTER CONSTRAINT name INHERIT
    2770                 :             :                 {
    2771                 :          44 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2772                 :          44 :                     ATAlterConstraint *c = makeNode(ATAlterConstraint);
    2773                 :             : 
    2774                 :          44 :                     n->subtype = AT_AlterConstraint;
    2775                 :          44 :                     n->def = (Node *) c;
    2776                 :          44 :                     c->conname = $3;
    2777                 :          44 :                     c->alterInheritability = true;
    2778                 :          44 :                     c->noinherit = false;
    2779                 :             : 
    2780                 :          44 :                     $$ = (Node *) n;
    2781                 :             :                 }
    2782                 :             :             /* ALTER TABLE <name> VALIDATE CONSTRAINT ... */
    2783                 :             :             | VALIDATE CONSTRAINT name
    2784                 :             :                 {
    2785                 :         288 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2786                 :             : 
    2787                 :         288 :                     n->subtype = AT_ValidateConstraint;
    2788                 :         288 :                     n->name = $3;
    2789                 :         288 :                     $$ = (Node *) n;
    2790                 :             :                 }
    2791                 :             :             /* ALTER TABLE <name> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
    2792                 :             :             | DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
    2793                 :             :                 {
    2794                 :          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2795                 :             : 
    2796                 :          12 :                     n->subtype = AT_DropConstraint;
    2797                 :          12 :                     n->name = $5;
    2798                 :          12 :                     n->behavior = $6;
    2799                 :          12 :                     n->missing_ok = true;
    2800                 :          12 :                     $$ = (Node *) n;
    2801                 :             :                 }
    2802                 :             :             /* ALTER TABLE <name> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
    2803                 :             :             | DROP CONSTRAINT name opt_drop_behavior
    2804                 :             :                 {
    2805                 :         559 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2806                 :             : 
    2807                 :         559 :                     n->subtype = AT_DropConstraint;
    2808                 :         559 :                     n->name = $3;
    2809                 :         559 :                     n->behavior = $4;
    2810                 :         559 :                     n->missing_ok = false;
    2811                 :         559 :                     $$ = (Node *) n;
    2812                 :             :                 }
    2813                 :             :             /* ALTER TABLE <name> SET WITHOUT OIDS, for backward compat */
    2814                 :             :             | SET WITHOUT OIDS
    2815                 :             :                 {
    2816                 :           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2817                 :             : 
    2818                 :           4 :                     n->subtype = AT_DropOids;
    2819                 :           4 :                     $$ = (Node *) n;
    2820                 :             :                 }
    2821                 :             :             /* ALTER TABLE <name> CLUSTER ON <indexname> */
    2822                 :             :             | CLUSTER ON name
    2823                 :             :                 {
    2824                 :          31 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2825                 :             : 
    2826                 :          31 :                     n->subtype = AT_ClusterOn;
    2827                 :          31 :                     n->name = $3;
    2828                 :          31 :                     $$ = (Node *) n;
    2829                 :             :                 }
    2830                 :             :             /* ALTER TABLE <name> SET WITHOUT CLUSTER */
    2831                 :             :             | SET WITHOUT CLUSTER
    2832                 :             :                 {
    2833                 :          12 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2834                 :             : 
    2835                 :          12 :                     n->subtype = AT_DropCluster;
    2836                 :          12 :                     n->name = NULL;
    2837                 :          12 :                     $$ = (Node *) n;
    2838                 :             :                 }
    2839                 :             :             /* ALTER TABLE <name> SET LOGGED */
    2840                 :             :             | SET LOGGED
    2841                 :             :                 {
    2842                 :          34 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2843                 :             : 
    2844                 :          34 :                     n->subtype = AT_SetLogged;
    2845                 :          34 :                     $$ = (Node *) n;
    2846                 :             :                 }
    2847                 :             :             /* ALTER TABLE <name> SET UNLOGGED */
    2848                 :             :             | SET UNLOGGED
    2849                 :             :                 {
    2850                 :          45 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2851                 :             : 
    2852                 :          45 :                     n->subtype = AT_SetUnLogged;
    2853                 :          45 :                     $$ = (Node *) n;
    2854                 :             :                 }
    2855                 :             :             /* ALTER TABLE <name> ENABLE TRIGGER <trig> */
    2856                 :             :             | ENABLE_P TRIGGER name
    2857                 :             :                 {
    2858                 :          65 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2859                 :             : 
    2860                 :          65 :                     n->subtype = AT_EnableTrig;
    2861                 :          65 :                     n->name = $3;
    2862                 :          65 :                     $$ = (Node *) n;
    2863                 :             :                 }
    2864                 :             :             /* ALTER TABLE <name> ENABLE ALWAYS TRIGGER <trig> */
    2865                 :             :             | ENABLE_P ALWAYS TRIGGER name
    2866                 :             :                 {
    2867                 :          27 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2868                 :             : 
    2869                 :          27 :                     n->subtype = AT_EnableAlwaysTrig;
    2870                 :          27 :                     n->name = $4;
    2871                 :          27 :                     $$ = (Node *) n;
    2872                 :             :                 }
    2873                 :             :             /* ALTER TABLE <name> ENABLE REPLICA TRIGGER <trig> */
    2874                 :             :             | ENABLE_P REPLICA TRIGGER name
    2875                 :             :                 {
    2876                 :           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2877                 :             : 
    2878                 :           8 :                     n->subtype = AT_EnableReplicaTrig;
    2879                 :           8 :                     n->name = $4;
    2880                 :           8 :                     $$ = (Node *) n;
    2881                 :             :                 }
    2882                 :             :             /* ALTER TABLE <name> ENABLE TRIGGER ALL */
    2883                 :             :             | ENABLE_P TRIGGER ALL
    2884                 :             :                 {
    2885                 :           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2886                 :             : 
    2887                 :           0 :                     n->subtype = AT_EnableTrigAll;
    2888                 :           0 :                     $$ = (Node *) n;
    2889                 :             :                 }
    2890                 :             :             /* ALTER TABLE <name> ENABLE TRIGGER USER */
    2891                 :             :             | ENABLE_P TRIGGER USER
    2892                 :             :                 {
    2893                 :           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2894                 :             : 
    2895                 :           0 :                     n->subtype = AT_EnableTrigUser;
    2896                 :           0 :                     $$ = (Node *) n;
    2897                 :             :                 }
    2898                 :             :             /* ALTER TABLE <name> DISABLE TRIGGER <trig> */
    2899                 :             :             | DISABLE_P TRIGGER name
    2900                 :             :                 {
    2901                 :          75 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2902                 :             : 
    2903                 :          75 :                     n->subtype = AT_DisableTrig;
    2904                 :          75 :                     n->name = $3;
    2905                 :          75 :                     $$ = (Node *) n;
    2906                 :             :                 }
    2907                 :             :             /* ALTER TABLE <name> DISABLE TRIGGER ALL */
    2908                 :             :             | DISABLE_P TRIGGER ALL
    2909                 :             :                 {
    2910                 :           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2911                 :             : 
    2912                 :           8 :                     n->subtype = AT_DisableTrigAll;
    2913                 :           8 :                     $$ = (Node *) n;
    2914                 :             :                 }
    2915                 :             :             /* ALTER TABLE <name> DISABLE TRIGGER USER */
    2916                 :             :             | DISABLE_P TRIGGER USER
    2917                 :             :                 {
    2918                 :           8 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2919                 :             : 
    2920                 :           8 :                     n->subtype = AT_DisableTrigUser;
    2921                 :           8 :                     $$ = (Node *) n;
    2922                 :             :                 }
    2923                 :             :             /* ALTER TABLE <name> ENABLE RULE <rule> */
    2924                 :             :             | ENABLE_P RULE name
    2925                 :             :                 {
    2926                 :           5 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2927                 :             : 
    2928                 :           5 :                     n->subtype = AT_EnableRule;
    2929                 :           5 :                     n->name = $3;
    2930                 :           5 :                     $$ = (Node *) n;
    2931                 :             :                 }
    2932                 :             :             /* ALTER TABLE <name> ENABLE ALWAYS RULE <rule> */
    2933                 :             :             | ENABLE_P ALWAYS RULE name
    2934                 :             :                 {
    2935                 :           0 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2936                 :             : 
    2937                 :           0 :                     n->subtype = AT_EnableAlwaysRule;
    2938                 :           0 :                     n->name = $4;
    2939                 :           0 :                     $$ = (Node *) n;
    2940                 :             :                 }
    2941                 :             :             /* ALTER TABLE <name> ENABLE REPLICA RULE <rule> */
    2942                 :             :             | ENABLE_P REPLICA RULE name
    2943                 :             :                 {
    2944                 :           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2945                 :             : 
    2946                 :           4 :                     n->subtype = AT_EnableReplicaRule;
    2947                 :           4 :                     n->name = $4;
    2948                 :           4 :                     $$ = (Node *) n;
    2949                 :             :                 }
    2950                 :             :             /* ALTER TABLE <name> DISABLE RULE <rule> */
    2951                 :             :             | DISABLE_P RULE name
    2952                 :             :                 {
    2953                 :          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2954                 :             : 
    2955                 :          20 :                     n->subtype = AT_DisableRule;
    2956                 :          20 :                     n->name = $3;
    2957                 :          20 :                     $$ = (Node *) n;
    2958                 :             :                 }
    2959                 :             :             /* ALTER TABLE <name> INHERIT <parent> */
    2960                 :             :             | INHERIT qualified_name
    2961                 :             :                 {
    2962                 :         301 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2963                 :             : 
    2964                 :         301 :                     n->subtype = AT_AddInherit;
    2965                 :         301 :                     n->def = (Node *) $2;
    2966                 :         301 :                     $$ = (Node *) n;
    2967                 :             :                 }
    2968                 :             :             /* ALTER TABLE <name> NO INHERIT <parent> */
    2969                 :             :             | NO INHERIT qualified_name
    2970                 :             :                 {
    2971                 :          73 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2972                 :             : 
    2973                 :          73 :                     n->subtype = AT_DropInherit;
    2974                 :          73 :                     n->def = (Node *) $3;
    2975                 :          73 :                     $$ = (Node *) n;
    2976                 :             :                 }
    2977                 :             :             /* ALTER TABLE <name> OF <type_name> */
    2978                 :             :             | OF any_name
    2979                 :             :                 {
    2980                 :          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2981                 :          50 :                     TypeName   *def = makeTypeNameFromNameList($2);
    2982                 :             : 
    2983                 :          50 :                     def->location = @2;
    2984                 :          50 :                     n->subtype = AT_AddOf;
    2985                 :          50 :                     n->def = (Node *) def;
    2986                 :          50 :                     $$ = (Node *) n;
    2987                 :             :                 }
    2988                 :             :             /* ALTER TABLE <name> NOT OF */
    2989                 :             :             | NOT OF
    2990                 :             :                 {
    2991                 :           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    2992                 :             : 
    2993                 :           4 :                     n->subtype = AT_DropOf;
    2994                 :           4 :                     $$ = (Node *) n;
    2995                 :             :                 }
    2996                 :             :             /* ALTER TABLE <name> OWNER TO RoleSpec */
    2997                 :             :             | OWNER TO RoleSpec
    2998                 :             :                 {
    2999                 :        1111 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3000                 :             : 
    3001                 :        1111 :                     n->subtype = AT_ChangeOwner;
    3002                 :        1111 :                     n->newowner = $3;
    3003                 :        1111 :                     $$ = (Node *) n;
    3004                 :             :                 }
    3005                 :             :             /* ALTER TABLE <name> SET ACCESS METHOD { <amname> | DEFAULT } */
    3006                 :             :             | SET ACCESS METHOD set_access_method_name
    3007                 :             :                 {
    3008                 :          85 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3009                 :             : 
    3010                 :          85 :                     n->subtype = AT_SetAccessMethod;
    3011                 :          85 :                     n->name = $4;
    3012                 :          85 :                     $$ = (Node *) n;
    3013                 :             :                 }
    3014                 :             :             /* ALTER TABLE <name> SET TABLESPACE <tablespacename> */
    3015                 :             :             | SET TABLESPACE name
    3016                 :             :                 {
    3017                 :          75 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3018                 :             : 
    3019                 :          75 :                     n->subtype = AT_SetTableSpace;
    3020                 :          75 :                     n->name = $3;
    3021                 :          75 :                     $$ = (Node *) n;
    3022                 :             :                 }
    3023                 :             :             /* ALTER TABLE <name> SET (...) */
    3024                 :             :             | SET reloptions
    3025                 :             :                 {
    3026                 :         417 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3027                 :             : 
    3028                 :         417 :                     n->subtype = AT_SetRelOptions;
    3029                 :         417 :                     n->def = (Node *) $2;
    3030                 :         417 :                     $$ = (Node *) n;
    3031                 :             :                 }
    3032                 :             :             /* ALTER TABLE <name> RESET (...) */
    3033                 :             :             | RESET reloptions
    3034                 :             :                 {
    3035                 :         123 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3036                 :             : 
    3037                 :         123 :                     n->subtype = AT_ResetRelOptions;
    3038                 :         123 :                     n->def = (Node *) $2;
    3039                 :         123 :                     $$ = (Node *) n;
    3040                 :             :                 }
    3041                 :             :             /* ALTER TABLE <name> REPLICA IDENTITY */
    3042                 :             :             | REPLICA IDENTITY_P replica_identity
    3043                 :             :                 {
    3044                 :         317 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3045                 :             : 
    3046                 :         317 :                     n->subtype = AT_ReplicaIdentity;
    3047                 :         317 :                     n->def = $3;
    3048                 :         317 :                     $$ = (Node *) n;
    3049                 :             :                 }
    3050                 :             :             /* ALTER TABLE <name> ENABLE ROW LEVEL SECURITY */
    3051                 :             :             | ENABLE_P ROW LEVEL SECURITY
    3052                 :             :                 {
    3053                 :         230 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3054                 :             : 
    3055                 :         230 :                     n->subtype = AT_EnableRowSecurity;
    3056                 :         230 :                     $$ = (Node *) n;
    3057                 :             :                 }
    3058                 :             :             /* ALTER TABLE <name> DISABLE ROW LEVEL SECURITY */
    3059                 :             :             | DISABLE_P ROW LEVEL SECURITY
    3060                 :             :                 {
    3061                 :           6 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3062                 :             : 
    3063                 :           6 :                     n->subtype = AT_DisableRowSecurity;
    3064                 :           6 :                     $$ = (Node *) n;
    3065                 :             :                 }
    3066                 :             :             /* ALTER TABLE <name> FORCE ROW LEVEL SECURITY */
    3067                 :             :             | FORCE ROW LEVEL SECURITY
    3068                 :             :                 {
    3069                 :          65 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3070                 :             : 
    3071                 :          65 :                     n->subtype = AT_ForceRowSecurity;
    3072                 :          65 :                     $$ = (Node *) n;
    3073                 :             :                 }
    3074                 :             :             /* ALTER TABLE <name> NO FORCE ROW LEVEL SECURITY */
    3075                 :             :             | NO FORCE ROW LEVEL SECURITY
    3076                 :             :                 {
    3077                 :          20 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3078                 :             : 
    3079                 :          20 :                     n->subtype = AT_NoForceRowSecurity;
    3080                 :          20 :                     $$ = (Node *) n;
    3081                 :             :                 }
    3082                 :             :             | alter_generic_options
    3083                 :             :                 {
    3084                 :          38 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3085                 :             : 
    3086                 :          38 :                     n->subtype = AT_GenericOptions;
    3087                 :          38 :                     n->def = (Node *) $1;
    3088                 :          38 :                     $$ = (Node *) n;
    3089                 :             :                 }
    3090                 :             :         ;
    3091                 :             : 
    3092                 :             : alter_column_default:
    3093                 :         250 :             SET DEFAULT a_expr          { $$ = $3; }
    3094                 :         124 :             | DROP DEFAULT              { $$ = NULL; }
    3095                 :             :         ;
    3096                 :             : 
    3097                 :             : opt_collate_clause:
    3098                 :             :             COLLATE any_name
    3099                 :             :                 {
    3100                 :          12 :                     CollateClause *n = makeNode(CollateClause);
    3101                 :             : 
    3102                 :          12 :                     n->arg = NULL;
    3103                 :          12 :                     n->collname = $2;
    3104                 :          12 :                     n->location = @1;
    3105                 :          12 :                     $$ = (Node *) n;
    3106                 :             :                 }
    3107                 :        3126 :             | /* EMPTY */               { $$ = NULL; }
    3108                 :             :         ;
    3109                 :             : 
    3110                 :             : alter_using:
    3111                 :         119 :             USING a_expr                { $$ = $2; }
    3112                 :         647 :             | /* EMPTY */               { $$ = NULL; }
    3113                 :             :         ;
    3114                 :             : 
    3115                 :             : replica_identity:
    3116                 :             :             NOTHING
    3117                 :             :                 {
    3118                 :          30 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3119                 :             : 
    3120                 :          30 :                     n->identity_type = REPLICA_IDENTITY_NOTHING;
    3121                 :          30 :                     n->name = NULL;
    3122                 :          30 :                     $$ = (Node *) n;
    3123                 :             :                 }
    3124                 :             :             | FULL
    3125                 :             :                 {
    3126                 :          99 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3127                 :             : 
    3128                 :          99 :                     n->identity_type = REPLICA_IDENTITY_FULL;
    3129                 :          99 :                     n->name = NULL;
    3130                 :          99 :                     $$ = (Node *) n;
    3131                 :             :                 }
    3132                 :             :             | DEFAULT
    3133                 :             :                 {
    3134                 :           5 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3135                 :             : 
    3136                 :           5 :                     n->identity_type = REPLICA_IDENTITY_DEFAULT;
    3137                 :           5 :                     n->name = NULL;
    3138                 :           5 :                     $$ = (Node *) n;
    3139                 :             :                 }
    3140                 :             :             | USING INDEX name
    3141                 :             :                 {
    3142                 :         183 :                     ReplicaIdentityStmt *n = makeNode(ReplicaIdentityStmt);
    3143                 :             : 
    3144                 :         183 :                     n->identity_type = REPLICA_IDENTITY_INDEX;
    3145                 :         183 :                     n->name = $3;
    3146                 :         183 :                     $$ = (Node *) n;
    3147                 :             :                 }
    3148                 :             : ;
    3149                 :             : 
    3150                 :             : reloptions:
    3151                 :        1953 :             '(' reloption_list ')'                  { $$ = $2; }
    3152                 :             :         ;
    3153                 :             : 
    3154                 :         613 : opt_reloptions:     WITH reloptions                 { $$ = $2; }
    3155                 :       15175 :              |      /* EMPTY */                     { $$ = NIL; }
    3156                 :             :         ;
    3157                 :             : 
    3158                 :             : reloption_list:
    3159                 :        1953 :             reloption_elem                          { $$ = list_make1($1); }
    3160                 :         182 :             | reloption_list ',' reloption_elem     { $$ = lappend($1, $3); }
    3161                 :             :         ;
    3162                 :             : 
    3163                 :             : /* This should match def_elem and also allow qualified names */
    3164                 :             : reloption_elem:
    3165                 :             :             ColLabel '=' def_arg
    3166                 :             :                 {
    3167                 :        1696 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    3168                 :             :                 }
    3169                 :             :             | ColLabel
    3170                 :             :                 {
    3171                 :         383 :                     $$ = makeDefElem($1, NULL, @1);
    3172                 :             :                 }
    3173                 :             :             | ColLabel '.' ColLabel '=' def_arg
    3174                 :             :                 {
    3175                 :          52 :                     $$ = makeDefElemExtended($1, $3, (Node *) $5,
    3176                 :          52 :                                              DEFELEM_UNSPEC, @1);
    3177                 :             :                 }
    3178                 :             :             | ColLabel '.' ColLabel
    3179                 :             :                 {
    3180                 :           4 :                     $$ = makeDefElemExtended($1, $3, NULL, DEFELEM_UNSPEC, @1);
    3181                 :             :                 }
    3182                 :             :         ;
    3183                 :             : 
    3184                 :             : alter_identity_column_option_list:
    3185                 :             :             alter_identity_column_option
    3186                 :          41 :                 { $$ = list_make1($1); }
    3187                 :             :             | alter_identity_column_option_list alter_identity_column_option
    3188                 :          40 :                 { $$ = lappend($1, $2); }
    3189                 :             :         ;
    3190                 :             : 
    3191                 :             : alter_identity_column_option:
    3192                 :             :             RESTART
    3193                 :             :                 {
    3194                 :          16 :                     $$ = makeDefElem("restart", NULL, @1);
    3195                 :             :                 }
    3196                 :             :             | RESTART opt_with NumericOnly
    3197                 :             :                 {
    3198                 :           0 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    3199                 :             :                 }
    3200                 :             :             | SET SeqOptElem
    3201                 :             :                 {
    3202         [ +  - ]:          36 :                     if (strcmp($2->defname, "as") == 0 ||
    3203         [ +  - ]:          36 :                         strcmp($2->defname, "restart") == 0 ||
    3204         [ -  + ]:          36 :                         strcmp($2->defname, "owned_by") == 0)
    3205         [ #  # ]:           0 :                         ereport(ERROR,
    3206                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3207                 :             :                                  errmsg("sequence option \"%s\" not supported here", $2->defname),
    3208                 :             :                                  parser_errposition(@2)));
    3209                 :          36 :                     $$ = $2;
    3210                 :             :                 }
    3211                 :             :             | SET GENERATED generated_when
    3212                 :             :                 {
    3213                 :          29 :                     $$ = makeDefElem("generated", (Node *) makeInteger($3), @1);
    3214                 :             :                 }
    3215                 :             :         ;
    3216                 :             : 
    3217                 :             : set_statistics_value:
    3218                 :         105 :             SignedIconst                    { $$ = (Node *) makeInteger($1); }
    3219                 :           2 :             | DEFAULT                       { $$ = NULL; }
    3220                 :             :         ;
    3221                 :             : 
    3222                 :             : set_access_method_name:
    3223                 :          61 :             ColId                           { $$ = $1; }
    3224                 :          24 :             | DEFAULT                       { $$ = NULL; }
    3225                 :             :         ;
    3226                 :             : 
    3227                 :             : PartitionBoundSpec:
    3228                 :             :             /* a HASH partition */
    3229                 :             :             FOR VALUES WITH '(' hash_partbound ')'
    3230                 :             :                 {
    3231                 :             :                     ListCell   *lc;
    3232                 :         472 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3233                 :             : 
    3234                 :         472 :                     n->strategy = PARTITION_STRATEGY_HASH;
    3235                 :         472 :                     n->modulus = n->remainder = -1;
    3236                 :             : 
    3237   [ +  -  +  +  :        1416 :                     foreach (lc, $5)
                   +  + ]
    3238                 :             :                     {
    3239                 :         944 :                         DefElem    *opt = lfirst_node(DefElem, lc);
    3240                 :             : 
    3241         [ +  + ]:         944 :                         if (strcmp(opt->defname, "modulus") == 0)
    3242                 :             :                         {
    3243         [ -  + ]:         472 :                             if (n->modulus != -1)
    3244         [ #  # ]:           0 :                                 ereport(ERROR,
    3245                 :             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3246                 :             :                                          errmsg("modulus for hash partition provided more than once"),
    3247                 :             :                                          parser_errposition(opt->location)));
    3248                 :         472 :                             n->modulus = defGetInt32(opt);
    3249                 :             :                         }
    3250         [ +  - ]:         472 :                         else if (strcmp(opt->defname, "remainder") == 0)
    3251                 :             :                         {
    3252         [ -  + ]:         472 :                             if (n->remainder != -1)
    3253         [ #  # ]:           0 :                                 ereport(ERROR,
    3254                 :             :                                         (errcode(ERRCODE_DUPLICATE_OBJECT),
    3255                 :             :                                          errmsg("remainder for hash partition provided more than once"),
    3256                 :             :                                          parser_errposition(opt->location)));
    3257                 :         472 :                             n->remainder = defGetInt32(opt);
    3258                 :             :                         }
    3259                 :             :                         else
    3260         [ #  # ]:           0 :                             ereport(ERROR,
    3261                 :             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
    3262                 :             :                                      errmsg("unrecognized hash partition bound specification \"%s\"",
    3263                 :             :                                             opt->defname),
    3264                 :             :                                      parser_errposition(opt->location)));
    3265                 :             :                     }
    3266                 :             : 
    3267         [ -  + ]:         472 :                     if (n->modulus == -1)
    3268         [ #  # ]:           0 :                         ereport(ERROR,
    3269                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3270                 :             :                                  errmsg("modulus for hash partition must be specified"),
    3271                 :             :                                  parser_errposition(@3)));
    3272         [ -  + ]:         472 :                     if (n->remainder == -1)
    3273         [ #  # ]:           0 :                         ereport(ERROR,
    3274                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3275                 :             :                                  errmsg("remainder for hash partition must be specified"),
    3276                 :             :                                  parser_errposition(@3)));
    3277                 :             : 
    3278                 :         472 :                     n->location = @3;
    3279                 :             : 
    3280                 :         472 :                     $$ = n;
    3281                 :             :                 }
    3282                 :             : 
    3283                 :             :             /* a LIST partition */
    3284                 :             :             | FOR VALUES IN_P '(' expr_list ')'
    3285                 :             :                 {
    3286                 :        3137 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3287                 :             : 
    3288                 :        3137 :                     n->strategy = PARTITION_STRATEGY_LIST;
    3289                 :        3137 :                     n->is_default = false;
    3290                 :        3137 :                     n->listdatums = $5;
    3291                 :        3137 :                     n->location = @3;
    3292                 :             : 
    3293                 :        3137 :                     $$ = n;
    3294                 :             :                 }
    3295                 :             : 
    3296                 :             :             /* a RANGE partition */
    3297                 :             :             | FOR VALUES FROM '(' expr_list ')' TO '(' expr_list ')'
    3298                 :             :                 {
    3299                 :        3522 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3300                 :             : 
    3301                 :        3522 :                     n->strategy = PARTITION_STRATEGY_RANGE;
    3302                 :        3522 :                     n->is_default = false;
    3303                 :        3522 :                     n->lowerdatums = $5;
    3304                 :        3522 :                     n->upperdatums = $9;
    3305                 :        3522 :                     n->location = @3;
    3306                 :             : 
    3307                 :        3522 :                     $$ = n;
    3308                 :             :                 }
    3309                 :             : 
    3310                 :             :             /* a DEFAULT partition */
    3311                 :             :             | DEFAULT
    3312                 :             :                 {
    3313                 :         422 :                     PartitionBoundSpec *n = makeNode(PartitionBoundSpec);
    3314                 :             : 
    3315                 :         422 :                     n->is_default = true;
    3316                 :         422 :                     n->location = @1;
    3317                 :             : 
    3318                 :         422 :                     $$ = n;
    3319                 :             :                 }
    3320                 :             :         ;
    3321                 :             : 
    3322                 :             : hash_partbound_elem:
    3323                 :             :         NonReservedWord Iconst
    3324                 :             :             {
    3325                 :         944 :                 $$ = makeDefElem($1, (Node *) makeInteger($2), @1);
    3326                 :             :             }
    3327                 :             :         ;
    3328                 :             : 
    3329                 :             : hash_partbound:
    3330                 :             :         hash_partbound_elem
    3331                 :             :             {
    3332                 :         472 :                 $$ = list_make1($1);
    3333                 :             :             }
    3334                 :             :         | hash_partbound ',' hash_partbound_elem
    3335                 :             :             {
    3336                 :         472 :                 $$ = lappend($1, $3);
    3337                 :             :             }
    3338                 :             :         ;
    3339                 :             : 
    3340                 :             : /*****************************************************************************
    3341                 :             :  *
    3342                 :             :  *  ALTER TYPE
    3343                 :             :  *
    3344                 :             :  * really variants of the ALTER TABLE subcommands with different spellings
    3345                 :             :  *****************************************************************************/
    3346                 :             : 
    3347                 :             : AlterCompositeTypeStmt:
    3348                 :             :             ALTER TYPE_P any_name alter_type_cmds
    3349                 :             :                 {
    3350                 :         145 :                     AlterTableStmt *n = makeNode(AlterTableStmt);
    3351                 :             : 
    3352                 :             :                     /* can't use qualified_name, sigh */
    3353                 :         145 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
    3354                 :         145 :                     n->cmds = $4;
    3355                 :         145 :                     n->objtype = OBJECT_TYPE;
    3356                 :         145 :                     $$ = (Node *) n;
    3357                 :             :                 }
    3358                 :             :             ;
    3359                 :             : 
    3360                 :             : alter_type_cmds:
    3361                 :         145 :             alter_type_cmd                          { $$ = list_make1($1); }
    3362                 :           8 :             | alter_type_cmds ',' alter_type_cmd    { $$ = lappend($1, $3); }
    3363                 :             :         ;
    3364                 :             : 
    3365                 :             : alter_type_cmd:
    3366                 :             :             /* ALTER TYPE <name> ADD ATTRIBUTE <coldef> [RESTRICT|CASCADE] */
    3367                 :             :             ADD_P ATTRIBUTE TableFuncElement opt_drop_behavior
    3368                 :             :                 {
    3369                 :          46 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3370                 :             : 
    3371                 :          46 :                     n->subtype = AT_AddColumn;
    3372                 :          46 :                     n->def = $3;
    3373                 :          46 :                     n->behavior = $4;
    3374                 :          46 :                     $$ = (Node *) n;
    3375                 :             :                 }
    3376                 :             :             /* ALTER TYPE <name> DROP ATTRIBUTE IF EXISTS <attname> [RESTRICT|CASCADE] */
    3377                 :             :             | DROP ATTRIBUTE IF_P EXISTS ColId opt_drop_behavior
    3378                 :             :                 {
    3379                 :           4 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3380                 :             : 
    3381                 :           4 :                     n->subtype = AT_DropColumn;
    3382                 :           4 :                     n->name = $5;
    3383                 :           4 :                     n->behavior = $6;
    3384                 :           4 :                     n->missing_ok = true;
    3385                 :           4 :                     $$ = (Node *) n;
    3386                 :             :                 }
    3387                 :             :             /* ALTER TYPE <name> DROP ATTRIBUTE <attname> [RESTRICT|CASCADE] */
    3388                 :             :             | DROP ATTRIBUTE ColId opt_drop_behavior
    3389                 :             :                 {
    3390                 :          50 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3391                 :             : 
    3392                 :          50 :                     n->subtype = AT_DropColumn;
    3393                 :          50 :                     n->name = $3;
    3394                 :          50 :                     n->behavior = $4;
    3395                 :          50 :                     n->missing_ok = false;
    3396                 :          50 :                     $$ = (Node *) n;
    3397                 :             :                 }
    3398                 :             :             /* ALTER TYPE <name> ALTER ATTRIBUTE <attname> [SET DATA] TYPE <typename> [RESTRICT|CASCADE] */
    3399                 :             :             | ALTER ATTRIBUTE ColId opt_set_data TYPE_P Typename opt_collate_clause opt_drop_behavior
    3400                 :             :                 {
    3401                 :          53 :                     AlterTableCmd *n = makeNode(AlterTableCmd);
    3402                 :          53 :                     ColumnDef *def = makeNode(ColumnDef);
    3403                 :             : 
    3404                 :          53 :                     n->subtype = AT_AlterColumnType;
    3405                 :          53 :                     n->name = $3;
    3406                 :          53 :                     n->def = (Node *) def;
    3407                 :          53 :                     n->behavior = $8;
    3408                 :             :                     /* We only use these fields of the ColumnDef node */
    3409                 :          53 :                     def->typeName = $6;
    3410                 :          53 :                     def->collClause = (CollateClause *) $7;
    3411                 :          53 :                     def->raw_default = NULL;
    3412                 :          53 :                     def->location = @3;
    3413                 :          53 :                     $$ = (Node *) n;
    3414                 :             :                 }
    3415                 :             :         ;
    3416                 :             : 
    3417                 :             : 
    3418                 :             : /*****************************************************************************
    3419                 :             :  *
    3420                 :             :  *      QUERY :
    3421                 :             :  *              close <portalname>
    3422                 :             :  *
    3423                 :             :  *****************************************************************************/
    3424                 :             : 
    3425                 :             : ClosePortalStmt:
    3426                 :             :             CLOSE cursor_name
    3427                 :             :                 {
    3428                 :        1227 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3429                 :             : 
    3430                 :        1227 :                     n->portalname = $2;
    3431                 :        1227 :                     $$ = (Node *) n;
    3432                 :             :                 }
    3433                 :             :             | CLOSE ALL
    3434                 :             :                 {
    3435                 :           8 :                     ClosePortalStmt *n = makeNode(ClosePortalStmt);
    3436                 :             : 
    3437                 :           8 :                     n->portalname = NULL;
    3438                 :           8 :                     $$ = (Node *) n;
    3439                 :             :                 }
    3440                 :             :         ;
    3441                 :             : 
    3442                 :             : 
    3443                 :             : /*****************************************************************************
    3444                 :             :  *
    3445                 :             :  *      QUERY :
    3446                 :             :  *              COPY relname [(columnList)] FROM/TO file [WITH] [(options)]
    3447                 :             :  *              COPY ( query ) TO file  [WITH] [(options)]
    3448                 :             :  *
    3449                 :             :  *              where 'query' can be one of:
    3450                 :             :  *              { SELECT | UPDATE | INSERT | DELETE | MERGE }
    3451                 :             :  *
    3452                 :             :  *              and 'file' can be one of:
    3453                 :             :  *              { PROGRAM 'command' | STDIN | STDOUT | 'filename' }
    3454                 :             :  *
    3455                 :             :  *              In the preferred syntax the options are comma-separated
    3456                 :             :  *              and use generic identifiers instead of keywords.  The pre-9.0
    3457                 :             :  *              syntax had a hard-wired, space-separated set of options.
    3458                 :             :  *
    3459                 :             :  *              Really old syntax, from versions 7.2 and prior:
    3460                 :             :  *              COPY [ BINARY ] table FROM/TO file
    3461                 :             :  *                  [ [ USING ] DELIMITERS 'delimiter' ] ]
    3462                 :             :  *                  [ WITH NULL AS 'null string' ]
    3463                 :             :  *              This option placement is not supported with COPY (query...).
    3464                 :             :  *
    3465                 :             :  *****************************************************************************/
    3466                 :             : 
    3467                 :             : CopyStmt:   COPY opt_binary qualified_name opt_column_list
    3468                 :             :             copy_from opt_program copy_file_name copy_delimiter opt_with
    3469                 :             :             copy_options where_clause
    3470                 :             :                 {
    3471                 :        6179 :                     CopyStmt *n = makeNode(CopyStmt);
    3472                 :             : 
    3473                 :        6179 :                     n->relation = $3;
    3474                 :        6179 :                     n->query = NULL;
    3475                 :        6179 :                     n->attlist = $4;
    3476                 :        6179 :                     n->is_from = $5;
    3477                 :        6179 :                     n->is_program = $6;
    3478                 :        6179 :                     n->filename = $7;
    3479                 :        6179 :                     n->whereClause = $11;
    3480                 :             : 
    3481   [ +  +  -  + ]:        6179 :                     if (n->is_program && n->filename == NULL)
    3482         [ #  # ]:           0 :                         ereport(ERROR,
    3483                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3484                 :             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3485                 :             :                                  parser_errposition(@8)));
    3486                 :             : 
    3487   [ +  +  +  + ]:        6179 :                     if (!n->is_from && n->whereClause != NULL)
    3488         [ +  - ]:           4 :                         ereport(ERROR,
    3489                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3490                 :             :                                  errmsg("WHERE clause not allowed with COPY TO"),
    3491                 :             :                                  errhint("Try the COPY (SELECT ... WHERE ...) TO variant."),
    3492                 :             :                                  parser_errposition(@11)));
    3493                 :             : 
    3494                 :        6175 :                     n->options = NIL;
    3495                 :             :                     /* Concatenate user-supplied flags */
    3496         [ +  + ]:        6175 :                     if ($2)
    3497                 :           8 :                         n->options = lappend(n->options, $2);
    3498         [ -  + ]:        6175 :                     if ($8)
    3499                 :           0 :                         n->options = lappend(n->options, $8);
    3500         [ +  + ]:        6175 :                     if ($10)
    3501                 :         861 :                         n->options = list_concat(n->options, $10);
    3502                 :        6175 :                     $$ = (Node *) n;
    3503                 :             :                 }
    3504                 :             :             | COPY '(' PreparableStmt ')' TO opt_program copy_file_name opt_with copy_options
    3505                 :             :                 {
    3506                 :         365 :                     CopyStmt *n = makeNode(CopyStmt);
    3507                 :             : 
    3508                 :         365 :                     n->relation = NULL;
    3509                 :         365 :                     n->query = $3;
    3510                 :         365 :                     n->attlist = NIL;
    3511                 :         365 :                     n->is_from = false;
    3512                 :         365 :                     n->is_program = $6;
    3513                 :         365 :                     n->filename = $7;
    3514                 :         365 :                     n->options = $9;
    3515                 :             : 
    3516   [ -  +  -  - ]:         365 :                     if (n->is_program && n->filename == NULL)
    3517         [ #  # ]:           0 :                         ereport(ERROR,
    3518                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    3519                 :             :                                  errmsg("STDIN/STDOUT not allowed with PROGRAM"),
    3520                 :             :                                  parser_errposition(@5)));
    3521                 :             : 
    3522                 :         365 :                     $$ = (Node *) n;
    3523                 :             :                 }
    3524                 :             :         ;
    3525                 :             : 
    3526                 :             : copy_from:
    3527                 :        1251 :             FROM                                    { $$ = true; }
    3528                 :        4928 :             | TO                                    { $$ = false; }
    3529                 :             :         ;
    3530                 :             : 
    3531                 :             : opt_program:
    3532                 :           1 :             PROGRAM                                 { $$ = true; }
    3533                 :        6543 :             | /* EMPTY */                           { $$ = false; }
    3534                 :             :         ;
    3535                 :             : 
    3536                 :             : /*
    3537                 :             :  * copy_file_name NULL indicates stdio is used. Whether stdin or stdout is
    3538                 :             :  * used depends on the direction. (It really doesn't make sense to copy from
    3539                 :             :  * stdout. We silently correct the "typo".)        - AY 9/94
    3540                 :             :  */
    3541                 :             : copy_file_name:
    3542                 :         318 :             Sconst                                  { $$ = $1; }
    3543                 :         991 :             | STDIN                                 { $$ = NULL; }
    3544                 :        5235 :             | STDOUT                                { $$ = NULL; }
    3545                 :             :         ;
    3546                 :             : 
    3547                 :        5827 : copy_options: copy_opt_list                         { $$ = $1; }
    3548                 :         717 :             | '(' copy_generic_opt_list ')'         { $$ = $2; }
    3549                 :             :         ;
    3550                 :             : 
    3551                 :             : /* old COPY option syntax */
    3552                 :             : copy_opt_list:
    3553                 :         344 :             copy_opt_list copy_opt_item             { $$ = lappend($1, $2); }
    3554                 :        5827 :             | /* EMPTY */                           { $$ = NIL; }
    3555                 :             :         ;
    3556                 :             : 
    3557                 :             : copy_opt_item:
    3558                 :             :             BINARY
    3559                 :             :                 {
    3560                 :           0 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3561                 :             :                 }
    3562                 :             :             | FREEZE
    3563                 :             :                 {
    3564                 :          32 :                     $$ = makeDefElem("freeze", (Node *) makeBoolean(true), @1);
    3565                 :             :                 }
    3566                 :             :             | DELIMITER opt_as Sconst
    3567                 :             :                 {
    3568                 :         116 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @1);
    3569                 :             :                 }
    3570                 :             :             | NULL_P opt_as Sconst
    3571                 :             :                 {
    3572                 :          32 :                     $$ = makeDefElem("null", (Node *) makeString($3), @1);
    3573                 :             :                 }
    3574                 :             :             | CSV
    3575                 :             :                 {
    3576                 :         100 :                     $$ = makeDefElem("format", (Node *) makeString("csv"), @1);
    3577                 :             :                 }
    3578                 :             :             | JSON
    3579                 :             :                 {
    3580                 :           8 :                     $$ = makeDefElem("format", (Node *) makeString("json"), @1);
    3581                 :             :                 }
    3582                 :             :             | HEADER_P
    3583                 :             :                 {
    3584                 :          12 :                     $$ = makeDefElem("header", (Node *) makeBoolean(true), @1);
    3585                 :             :                 }
    3586                 :             :             | QUOTE opt_as Sconst
    3587                 :             :                 {
    3588                 :          12 :                     $$ = makeDefElem("quote", (Node *) makeString($3), @1);
    3589                 :             :                 }
    3590                 :             :             | ESCAPE opt_as Sconst
    3591                 :             :                 {
    3592                 :          12 :                     $$ = makeDefElem("escape", (Node *) makeString($3), @1);
    3593                 :             :                 }
    3594                 :             :             | FORCE QUOTE columnList
    3595                 :             :                 {
    3596                 :           8 :                     $$ = makeDefElem("force_quote", (Node *) $3, @1);
    3597                 :             :                 }
    3598                 :             :             | FORCE QUOTE '*'
    3599                 :             :                 {
    3600                 :           4 :                     $$ = makeDefElem("force_quote", (Node *) makeNode(A_Star), @1);
    3601                 :             :                 }
    3602                 :             :             | FORCE NOT NULL_P columnList
    3603                 :             :                 {
    3604                 :           0 :                     $$ = makeDefElem("force_not_null", (Node *) $4, @1);
    3605                 :             :                 }
    3606                 :             :             | FORCE NOT NULL_P '*'
    3607                 :             :                 {
    3608                 :           0 :                     $$ = makeDefElem("force_not_null", (Node *) makeNode(A_Star), @1);
    3609                 :             :                 }
    3610                 :             :             | FORCE NULL_P columnList
    3611                 :             :                 {
    3612                 :           0 :                     $$ = makeDefElem("force_null", (Node *) $3, @1);
    3613                 :             :                 }
    3614                 :             :             | FORCE NULL_P '*'
    3615                 :             :                 {
    3616                 :           0 :                     $$ = makeDefElem("force_null", (Node *) makeNode(A_Star), @1);
    3617                 :             :                 }
    3618                 :             :             | ENCODING Sconst
    3619                 :             :                 {
    3620                 :           8 :                     $$ = makeDefElem("encoding", (Node *) makeString($2), @1);
    3621                 :             :                 }
    3622                 :             :         ;
    3623                 :             : 
    3624                 :             : /* The following exist for backward compatibility with very old versions */
    3625                 :             : 
    3626                 :             : opt_binary:
    3627                 :             :             BINARY
    3628                 :             :                 {
    3629                 :           8 :                     $$ = makeDefElem("format", (Node *) makeString("binary"), @1);
    3630                 :             :                 }
    3631                 :        6171 :             | /*EMPTY*/                             { $$ = NULL; }
    3632                 :             :         ;
    3633                 :             : 
    3634                 :             : copy_delimiter:
    3635                 :             :             opt_using DELIMITERS Sconst
    3636                 :             :                 {
    3637                 :           0 :                     $$ = makeDefElem("delimiter", (Node *) makeString($3), @2);
    3638                 :             :                 }
    3639                 :        6179 :             | /*EMPTY*/                             { $$ = NULL; }
    3640                 :             :         ;
    3641                 :             : 
    3642                 :             : opt_using:
    3643                 :             :             USING
    3644                 :             :             | /*EMPTY*/
    3645                 :             :         ;
    3646                 :             : 
    3647                 :             : /* new COPY option syntax */
    3648                 :             : copy_generic_opt_list:
    3649                 :             :             copy_generic_opt_elem
    3650                 :             :                 {
    3651                 :         717 :                     $$ = list_make1($1);
    3652                 :             :                 }
    3653                 :             :             | copy_generic_opt_list ',' copy_generic_opt_elem
    3654                 :             :                 {
    3655                 :         439 :                     $$ = lappend($1, $3);
    3656                 :             :                 }
    3657                 :             :         ;
    3658                 :             : 
    3659                 :             : copy_generic_opt_elem:
    3660                 :             :             ColLabel copy_generic_opt_arg
    3661                 :             :                 {
    3662                 :        1008 :                     $$ = makeDefElem($1, $2, @1);
    3663                 :             :                 }
    3664                 :             :             | FORMAT_LA copy_generic_opt_arg
    3665                 :             :                 {
    3666                 :         148 :                     $$ = makeDefElem("format", $2, @1);
    3667                 :             :                 }
    3668                 :             :         ;
    3669                 :             : 
    3670                 :             : copy_generic_opt_arg:
    3671                 :         880 :             opt_boolean_or_string           { $$ = (Node *) makeString($1); }
    3672                 :          52 :             | NumericOnly                   { $$ = (Node *) $1; }
    3673                 :          72 :             | '*'                           { $$ = (Node *) makeNode(A_Star); }
    3674                 :           4 :             | DEFAULT                       { $$ = (Node *) makeString("default"); }
    3675                 :         100 :             | '(' copy_generic_opt_arg_list ')'     { $$ = (Node *) $2; }
    3676                 :          48 :             | /* EMPTY */                   { $$ = NULL; }
    3677                 :             :         ;
    3678                 :             : 
    3679                 :             : copy_generic_opt_arg_list:
    3680                 :             :               copy_generic_opt_arg_list_item
    3681                 :             :                 {
    3682                 :         100 :                     $$ = list_make1($1);
    3683                 :             :                 }
    3684                 :             :             | copy_generic_opt_arg_list ',' copy_generic_opt_arg_list_item
    3685                 :             :                 {
    3686                 :           8 :                     $$ = lappend($1, $3);
    3687                 :             :                 }
    3688                 :             :         ;
    3689                 :             : 
    3690                 :             : /* beware of emitting non-string list elements here; see commands/define.c */
    3691                 :             : copy_generic_opt_arg_list_item:
    3692                 :         108 :             opt_boolean_or_string   { $$ = (Node *) makeString($1); }
    3693                 :             :         ;
    3694                 :             : 
    3695                 :             : 
    3696                 :             : /*****************************************************************************
    3697                 :             :  *
    3698                 :             :  *      QUERY :
    3699                 :             :  *              CREATE TABLE relname
    3700                 :             :  *
    3701                 :             :  *****************************************************************************/
    3702                 :             : 
    3703                 :             : CreateStmt: CREATE OptTemp TABLE qualified_name '(' OptTableElementList ')'
    3704                 :             :             OptInherit OptPartitionSpec table_access_method_clause OptWith
    3705                 :             :             OnCommitOption OptTableSpace
    3706                 :             :                 {
    3707                 :       19582 :                     CreateStmt *n = makeNode(CreateStmt);
    3708                 :             : 
    3709                 :       19582 :                     $4->relpersistence = $2;
    3710                 :       19582 :                     n->relation = $4;
    3711                 :       19582 :                     n->tableElts = $6;
    3712                 :       19582 :                     n->inhRelations = $8;
    3713                 :       19582 :                     n->partspec = $9;
    3714                 :       19582 :                     n->ofTypename = NULL;
    3715                 :       19582 :                     n->constraints = NIL;
    3716                 :       19582 :                     n->accessMethod = $10;
    3717                 :       19582 :                     n->options = $11;
    3718                 :       19582 :                     n->oncommit = $12;
    3719                 :       19582 :                     n->tablespacename = $13;
    3720                 :       19582 :                     n->if_not_exists = false;
    3721                 :       19582 :                     $$ = (Node *) n;
    3722                 :             :                 }
    3723                 :             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name '('
    3724                 :             :             OptTableElementList ')' OptInherit OptPartitionSpec table_access_method_clause
    3725                 :             :             OptWith OnCommitOption OptTableSpace
    3726                 :             :                 {
    3727                 :          16 :                     CreateStmt *n = makeNode(CreateStmt);
    3728                 :             : 
    3729                 :          16 :                     $7->relpersistence = $2;
    3730                 :          16 :                     n->relation = $7;
    3731                 :          16 :                     n->tableElts = $9;
    3732                 :          16 :                     n->inhRelations = $11;
    3733                 :          16 :                     n->partspec = $12;
    3734                 :          16 :                     n->ofTypename = NULL;
    3735                 :          16 :                     n->constraints = NIL;
    3736                 :          16 :                     n->accessMethod = $13;
    3737                 :          16 :                     n->options = $14;
    3738                 :          16 :                     n->oncommit = $15;
    3739                 :          16 :                     n->tablespacename = $16;
    3740                 :          16 :                     n->if_not_exists = true;
    3741                 :          16 :                     $$ = (Node *) n;
    3742                 :             :                 }
    3743                 :             :         | CREATE OptTemp TABLE qualified_name OF any_name
    3744                 :             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3745                 :             :             OptWith OnCommitOption OptTableSpace
    3746                 :             :                 {
    3747                 :          81 :                     CreateStmt *n = makeNode(CreateStmt);
    3748                 :             : 
    3749                 :          81 :                     $4->relpersistence = $2;
    3750                 :          81 :                     n->relation = $4;
    3751                 :          81 :                     n->tableElts = $7;
    3752                 :          81 :                     n->inhRelations = NIL;
    3753                 :          81 :                     n->partspec = $8;
    3754                 :          81 :                     n->ofTypename = makeTypeNameFromNameList($6);
    3755                 :          81 :                     n->ofTypename->location = @6;
    3756                 :          81 :                     n->constraints = NIL;
    3757                 :          81 :                     n->accessMethod = $9;
    3758                 :          81 :                     n->options = $10;
    3759                 :          81 :                     n->oncommit = $11;
    3760                 :          81 :                     n->tablespacename = $12;
    3761                 :          81 :                     n->if_not_exists = false;
    3762                 :          81 :                     $$ = (Node *) n;
    3763                 :             :                 }
    3764                 :             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name OF any_name
    3765                 :             :             OptTypedTableElementList OptPartitionSpec table_access_method_clause
    3766                 :             :             OptWith OnCommitOption OptTableSpace
    3767                 :             :                 {
    3768                 :           4 :                     CreateStmt *n = makeNode(CreateStmt);
    3769                 :             : 
    3770                 :           4 :                     $7->relpersistence = $2;
    3771                 :           4 :                     n->relation = $7;
    3772                 :           4 :                     n->tableElts = $10;
    3773                 :           4 :                     n->inhRelations = NIL;
    3774                 :           4 :                     n->partspec = $11;
    3775                 :           4 :                     n->ofTypename = makeTypeNameFromNameList($9);
    3776                 :           4 :                     n->ofTypename->location = @9;
    3777                 :           4 :                     n->constraints = NIL;
    3778                 :           4 :                     n->accessMethod = $12;
    3779                 :           4 :                     n->options = $13;
    3780                 :           4 :                     n->oncommit = $14;
    3781                 :           4 :                     n->tablespacename = $15;
    3782                 :           4 :                     n->if_not_exists = true;
    3783                 :           4 :                     $$ = (Node *) n;
    3784                 :             :                 }
    3785                 :             :         | CREATE OptTemp TABLE qualified_name PARTITION OF qualified_name
    3786                 :             :             OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3787                 :             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3788                 :             :                 {
    3789                 :        5942 :                     CreateStmt *n = makeNode(CreateStmt);
    3790                 :             : 
    3791                 :        5942 :                     $4->relpersistence = $2;
    3792                 :        5942 :                     n->relation = $4;
    3793                 :        5942 :                     n->tableElts = $8;
    3794                 :        5942 :                     n->inhRelations = list_make1($7);
    3795                 :        5942 :                     n->partbound = $9;
    3796                 :        5942 :                     n->partspec = $10;
    3797                 :        5942 :                     n->ofTypename = NULL;
    3798                 :        5942 :                     n->constraints = NIL;
    3799                 :        5942 :                     n->accessMethod = $11;
    3800                 :        5942 :                     n->options = $12;
    3801                 :        5942 :                     n->oncommit = $13;
    3802                 :        5942 :                     n->tablespacename = $14;
    3803                 :        5942 :                     n->if_not_exists = false;
    3804                 :        5942 :                     $$ = (Node *) n;
    3805                 :             :                 }
    3806                 :             :         | CREATE OptTemp TABLE IF_P NOT EXISTS qualified_name PARTITION OF
    3807                 :             :             qualified_name OptTypedTableElementList PartitionBoundSpec OptPartitionSpec
    3808                 :             :             table_access_method_clause OptWith OnCommitOption OptTableSpace
    3809                 :             :                 {
    3810                 :           0 :                     CreateStmt *n = makeNode(CreateStmt);
    3811                 :             : 
    3812                 :           0 :                     $7->relpersistence = $2;
    3813                 :           0 :                     n->relation = $7;
    3814                 :           0 :                     n->tableElts = $11;
    3815                 :           0 :                     n->inhRelations = list_make1($10);
    3816                 :           0 :                     n->partbound = $12;
    3817                 :           0 :                     n->partspec = $13;
    3818                 :           0 :                     n->ofTypename = NULL;
    3819                 :           0 :                     n->constraints = NIL;
    3820                 :           0 :                     n->accessMethod = $14;
    3821                 :           0 :                     n->options = $15;
    3822                 :           0 :                     n->oncommit = $16;
    3823                 :           0 :                     n->tablespacename = $17;
    3824                 :           0 :                     n->if_not_exists = true;
    3825                 :           0 :                     $$ = (Node *) n;
    3826                 :             :                 }
    3827                 :             :         ;
    3828                 :             : 
    3829                 :             : /*
    3830                 :             :  * Redundancy here is needed to avoid shift/reduce conflicts,
    3831                 :             :  * since TEMP is not a reserved word.  See also OptTempTableName.
    3832                 :             :  *
    3833                 :             :  * NOTE: we accept both GLOBAL and LOCAL options.  They currently do nothing,
    3834                 :             :  * but future versions might consider GLOBAL to request SQL-spec-compliant
    3835                 :             :  * temp table behavior, so warn about that.  Since we have no modules the
    3836                 :             :  * LOCAL keyword is really meaningless; furthermore, some other products
    3837                 :             :  * implement LOCAL as meaning the same as our default temp table behavior,
    3838                 :             :  * so we'll probably continue to treat LOCAL as a noise word.
    3839                 :             :  */
    3840                 :         229 : OptTemp:    TEMPORARY                   { $$ = RELPERSISTENCE_TEMP; }
    3841                 :        2042 :             | TEMP                      { $$ = RELPERSISTENCE_TEMP; }
    3842                 :           0 :             | LOCAL TEMPORARY           { $$ = RELPERSISTENCE_TEMP; }
    3843                 :           0 :             | LOCAL TEMP                { $$ = RELPERSISTENCE_TEMP; }
    3844                 :             :             | GLOBAL TEMPORARY
    3845                 :             :                 {
    3846         [ #  # ]:           0 :                     ereport(WARNING,
    3847                 :             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3848                 :             :                              parser_errposition(@1)));
    3849                 :           0 :                     $$ = RELPERSISTENCE_TEMP;
    3850                 :             :                 }
    3851                 :             :             | GLOBAL TEMP
    3852                 :             :                 {
    3853         [ #  # ]:           0 :                     ereport(WARNING,
    3854                 :             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
    3855                 :             :                              parser_errposition(@1)));
    3856                 :           0 :                     $$ = RELPERSISTENCE_TEMP;
    3857                 :             :                 }
    3858                 :         105 :             | UNLOGGED                  { $$ = RELPERSISTENCE_UNLOGGED; }
    3859                 :       35429 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    3860                 :             :         ;
    3861                 :             : 
    3862                 :             : OptTableElementList:
    3863                 :       18805 :             TableElementList                    { $$ = $1; }
    3864                 :        1072 :             | /*EMPTY*/                         { $$ = NIL; }
    3865                 :             :         ;
    3866                 :             : 
    3867                 :             : OptTypedTableElementList:
    3868                 :         217 :             '(' TypedTableElementList ')'       { $$ = $2; }
    3869                 :        5868 :             | /*EMPTY*/                         { $$ = NIL; }
    3870                 :             :         ;
    3871                 :             : 
    3872                 :             : TableElementList:
    3873                 :             :             TableElement
    3874                 :             :                 {
    3875                 :       18841 :                     $$ = list_make1($1);
    3876                 :             :                 }
    3877                 :             :             | TableElementList ',' TableElement
    3878                 :             :                 {
    3879                 :       26008 :                     $$ = lappend($1, $3);
    3880                 :             :                 }
    3881                 :             :         ;
    3882                 :             : 
    3883                 :             : TypedTableElementList:
    3884                 :             :             TypedTableElement
    3885                 :             :                 {
    3886                 :         217 :                     $$ = list_make1($1);
    3887                 :             :                 }
    3888                 :             :             | TypedTableElementList ',' TypedTableElement
    3889                 :             :                 {
    3890                 :          45 :                     $$ = lappend($1, $3);
    3891                 :             :                 }
    3892                 :             :         ;
    3893                 :             : 
    3894                 :             : TableElement:
    3895                 :       42449 :             columnDef                           { $$ = $1; }
    3896                 :         525 :             | TableLikeClause                   { $$ = $1; }
    3897                 :        1875 :             | TableConstraint                   { $$ = $1; }
    3898                 :             :         ;
    3899                 :             : 
    3900                 :             : TypedTableElement:
    3901                 :         220 :             columnOptions                       { $$ = $1; }
    3902                 :          42 :             | TableConstraint                   { $$ = $1; }
    3903                 :             :         ;
    3904                 :             : 
    3905                 :             : columnDef:  ColId Typename opt_column_storage opt_column_compression create_generic_options ColQualList
    3906                 :             :                 {
    3907                 :       44017 :                     ColumnDef *n = makeNode(ColumnDef);
    3908                 :             : 
    3909                 :       44017 :                     n->colname = $1;
    3910                 :       44017 :                     n->typeName = $2;
    3911                 :       44017 :                     n->storage_name = $3;
    3912                 :       44017 :                     n->compression = $4;
    3913                 :       44017 :                     n->inhcount = 0;
    3914                 :       44017 :                     n->is_local = true;
    3915                 :       44017 :                     n->is_not_null = false;
    3916                 :       44017 :                     n->is_from_type = false;
    3917                 :       44017 :                     n->storage = 0;
    3918                 :       44017 :                     n->raw_default = NULL;
    3919                 :       44017 :                     n->cooked_default = NULL;
    3920                 :       44017 :                     n->collOid = InvalidOid;
    3921                 :       44017 :                     n->fdwoptions = $5;
    3922                 :       44017 :                     SplitColQualList($6, &n->constraints, &n->collClause,
    3923                 :             :                                      yyscanner);
    3924                 :       44017 :                     n->location = @1;
    3925                 :       44017 :                     $$ = (Node *) n;
    3926                 :             :                 }
    3927                 :             :         ;
    3928                 :             : 
    3929                 :             : columnOptions:  ColId ColQualList
    3930                 :             :                 {
    3931                 :          91 :                     ColumnDef *n = makeNode(ColumnDef);
    3932                 :             : 
    3933                 :          91 :                     n->colname = $1;
    3934                 :          91 :                     n->typeName = NULL;
    3935                 :          91 :                     n->inhcount = 0;
    3936                 :          91 :                     n->is_local = true;
    3937                 :          91 :                     n->is_not_null = false;
    3938                 :          91 :                     n->is_from_type = false;
    3939                 :          91 :                     n->storage = 0;
    3940                 :          91 :                     n->raw_default = NULL;
    3941                 :          91 :                     n->cooked_default = NULL;
    3942                 :          91 :                     n->collOid = InvalidOid;
    3943                 :          91 :                     SplitColQualList($2, &n->constraints, &n->collClause,
    3944                 :             :                                      yyscanner);
    3945                 :          91 :                     n->location = @1;
    3946                 :          91 :                     $$ = (Node *) n;
    3947                 :             :                 }
    3948                 :             :                 | ColId WITH OPTIONS ColQualList
    3949                 :             :                 {
    3950                 :         129 :                     ColumnDef *n = makeNode(ColumnDef);
    3951                 :             : 
    3952                 :         129 :                     n->colname = $1;
    3953                 :         129 :                     n->typeName = NULL;
    3954                 :         129 :                     n->inhcount = 0;
    3955                 :         129 :                     n->is_local = true;
    3956                 :         129 :                     n->is_not_null = false;
    3957                 :         129 :                     n->is_from_type = false;
    3958                 :         129 :                     n->storage = 0;
    3959                 :         129 :                     n->raw_default = NULL;
    3960                 :         129 :                     n->cooked_default = NULL;
    3961                 :         129 :                     n->collOid = InvalidOid;
    3962                 :         129 :                     SplitColQualList($4, &n->constraints, &n->collClause,
    3963                 :             :                                      yyscanner);
    3964                 :         129 :                     n->location = @1;
    3965                 :         129 :                     $$ = (Node *) n;
    3966                 :             :                 }
    3967                 :             :         ;
    3968                 :             : 
    3969                 :             : column_compression:
    3970                 :         107 :             COMPRESSION ColId                       { $$ = $2; }
    3971                 :           5 :             | COMPRESSION DEFAULT                   { $$ = pstrdup("default"); }
    3972                 :             :         ;
    3973                 :             : 
    3974                 :             : opt_column_compression:
    3975                 :          64 :             column_compression                      { $$ = $1; }
    3976                 :       43997 :             | /*EMPTY*/                             { $$ = NULL; }
    3977                 :             :         ;
    3978                 :             : 
    3979                 :             : column_storage:
    3980                 :         239 :             STORAGE ColId                           { $$ = $2; }
    3981                 :           4 :             | STORAGE DEFAULT                       { $$ = pstrdup("default"); }
    3982                 :             :         ;
    3983                 :             : 
    3984                 :             : opt_column_storage:
    3985                 :          24 :             column_storage                          { $$ = $1; }
    3986                 :       44037 :             | /*EMPTY*/                             { $$ = NULL; }
    3987                 :             :         ;
    3988                 :             : 
    3989                 :             : ColQualList:
    3990                 :       13105 :             ColQualList ColConstraint               { $$ = lappend($1, $2); }
    3991                 :       45297 :             | /*EMPTY*/                             { $$ = NIL; }
    3992                 :             :         ;
    3993                 :             : 
    3994                 :             : ColConstraint:
    3995                 :             :             CONSTRAINT name ColConstraintElem
    3996                 :             :                 {
    3997                 :         523 :                     Constraint *n = castNode(Constraint, $3);
    3998                 :             : 
    3999                 :         523 :                     n->conname = $2;
    4000                 :         523 :                     n->location = @1;
    4001                 :         523 :                     $$ = (Node *) n;
    4002                 :             :                 }
    4003                 :       11743 :             | ColConstraintElem                     { $$ = $1; }
    4004                 :         307 :             | ConstraintAttr                        { $$ = $1; }
    4005                 :             :             | COLLATE any_name
    4006                 :             :                 {
    4007                 :             :                     /*
    4008                 :             :                      * Note: the CollateClause is momentarily included in
    4009                 :             :                      * the list built by ColQualList, but we split it out
    4010                 :             :                      * again in SplitColQualList.
    4011                 :             :                      */
    4012                 :         532 :                     CollateClause *n = makeNode(CollateClause);
    4013                 :             : 
    4014                 :         532 :                     n->arg = NULL;
    4015                 :         532 :                     n->collname = $2;
    4016                 :         532 :                     n->location = @1;
    4017                 :         532 :                     $$ = (Node *) n;
    4018                 :             :                 }
    4019                 :             :         ;
    4020                 :             : 
    4021                 :             : /* DEFAULT NULL is already the default for Postgres.
    4022                 :             :  * But define it here and carry it forward into the system
    4023                 :             :  * to make it explicit.
    4024                 :             :  * - thomas 1998-09-13
    4025                 :             :  *
    4026                 :             :  * WITH NULL and NULL are not SQL-standard syntax elements,
    4027                 :             :  * so leave them out. Use DEFAULT NULL to explicitly indicate
    4028                 :             :  * that a column may have that value. WITH NULL leads to
    4029                 :             :  * shift/reduce conflicts with WITH TIME ZONE anyway.
    4030                 :             :  * - thomas 1999-01-08
    4031                 :             :  *
    4032                 :             :  * DEFAULT expression must be b_expr not a_expr to prevent shift/reduce
    4033                 :             :  * conflict on NOT (since NOT might start a subsequent NOT NULL constraint,
    4034                 :             :  * or be part of a_expr NOT LIKE or similar constructs).
    4035                 :             :  */
    4036                 :             : ColConstraintElem:
    4037                 :             :             NOT NULL_P opt_no_inherit
    4038                 :             :                 {
    4039                 :        4060 :                     Constraint *n = makeNode(Constraint);
    4040                 :             : 
    4041                 :        4060 :                     n->contype = CONSTR_NOTNULL;
    4042                 :        4060 :                     n->location = @1;
    4043                 :        4060 :                     n->is_no_inherit = $3;
    4044                 :        4060 :                     n->is_enforced = true;
    4045                 :        4060 :                     n->skip_validation = false;
    4046                 :        4060 :                     n->initially_valid = true;
    4047                 :        4060 :                     $$ = (Node *) n;
    4048                 :             :                 }
    4049                 :             :             | NULL_P
    4050                 :             :                 {
    4051                 :          19 :                     Constraint *n = makeNode(Constraint);
    4052                 :             : 
    4053                 :          19 :                     n->contype = CONSTR_NULL;
    4054                 :          19 :                     n->location = @1;
    4055                 :          19 :                     $$ = (Node *) n;
    4056                 :             :                 }
    4057                 :             :             | UNIQUE opt_unique_null_treatment opt_definition OptConsTableSpace
    4058                 :             :                 {
    4059                 :         305 :                     Constraint *n = makeNode(Constraint);
    4060                 :             : 
    4061                 :         305 :                     n->contype = CONSTR_UNIQUE;
    4062                 :         305 :                     n->location = @1;
    4063                 :         305 :                     n->nulls_not_distinct = !$2;
    4064                 :         305 :                     n->keys = NULL;
    4065                 :         305 :                     n->options = $3;
    4066                 :         305 :                     n->indexname = NULL;
    4067                 :         305 :                     n->indexspace = $4;
    4068                 :         305 :                     $$ = (Node *) n;
    4069                 :             :                 }
    4070                 :             :             | PRIMARY KEY opt_definition OptConsTableSpace
    4071                 :             :                 {
    4072                 :        3684 :                     Constraint *n = makeNode(Constraint);
    4073                 :             : 
    4074                 :        3684 :                     n->contype = CONSTR_PRIMARY;
    4075                 :        3684 :                     n->location = @1;
    4076                 :        3684 :                     n->keys = NULL;
    4077                 :        3684 :                     n->options = $3;
    4078                 :        3684 :                     n->indexname = NULL;
    4079                 :        3684 :                     n->indexspace = $4;
    4080                 :        3684 :                     $$ = (Node *) n;
    4081                 :             :                 }
    4082                 :             :             | CHECK '(' a_expr ')' opt_no_inherit
    4083                 :             :                 {
    4084                 :         793 :                     Constraint *n = makeNode(Constraint);
    4085                 :             : 
    4086                 :         793 :                     n->contype = CONSTR_CHECK;
    4087                 :         793 :                     n->location = @1;
    4088                 :         793 :                     n->is_no_inherit = $5;
    4089                 :         793 :                     n->raw_expr = $3;
    4090                 :         793 :                     n->cooked_expr = NULL;
    4091                 :         793 :                     n->is_enforced = true;
    4092                 :         793 :                     n->skip_validation = false;
    4093                 :         793 :                     n->initially_valid = true;
    4094                 :         793 :                     $$ = (Node *) n;
    4095                 :             :                 }
    4096                 :             :             | DEFAULT b_expr
    4097                 :             :                 {
    4098                 :        1208 :                     Constraint *n = makeNode(Constraint);
    4099                 :             : 
    4100                 :        1208 :                     n->contype = CONSTR_DEFAULT;
    4101                 :        1208 :                     n->location = @1;
    4102                 :        1208 :                     n->raw_expr = $2;
    4103                 :        1208 :                     n->cooked_expr = NULL;
    4104                 :        1208 :                     $$ = (Node *) n;
    4105                 :             :                 }
    4106                 :             :             | GENERATED generated_when AS IDENTITY_P OptParenthesizedSeqOptList
    4107                 :             :                 {
    4108                 :         236 :                     Constraint *n = makeNode(Constraint);
    4109                 :             : 
    4110                 :         236 :                     n->contype = CONSTR_IDENTITY;
    4111                 :         236 :                     n->generated_when = $2;
    4112                 :         236 :                     n->options = $5;
    4113                 :         236 :                     n->location = @1;
    4114                 :         236 :                     $$ = (Node *) n;
    4115                 :             :                 }
    4116                 :             :             | GENERATED generated_when AS '(' a_expr ')' opt_virtual_or_stored
    4117                 :             :                 {
    4118                 :        1286 :                     Constraint *n = makeNode(Constraint);
    4119                 :             : 
    4120                 :        1286 :                     n->contype = CONSTR_GENERATED;
    4121                 :        1286 :                     n->generated_when = $2;
    4122                 :        1286 :                     n->raw_expr = $5;
    4123                 :        1286 :                     n->cooked_expr = NULL;
    4124                 :        1286 :                     n->generated_kind = $7;
    4125                 :        1286 :                     n->location = @1;
    4126                 :             : 
    4127                 :             :                     /*
    4128                 :             :                      * Can't do this in the grammar because of shift/reduce
    4129                 :             :                      * conflicts.  (IDENTITY allows both ALWAYS and BY
    4130                 :             :                      * DEFAULT, but generated columns only allow ALWAYS.)  We
    4131                 :             :                      * can also give a more useful error message and location.
    4132                 :             :                      */
    4133         [ +  + ]:        1286 :                     if ($2 != ATTRIBUTE_IDENTITY_ALWAYS)
    4134         [ +  - ]:           8 :                         ereport(ERROR,
    4135                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    4136                 :             :                                  errmsg("for a generated column, GENERATED ALWAYS must be specified"),
    4137                 :             :                                  parser_errposition(@2)));
    4138                 :             : 
    4139                 :        1278 :                     $$ = (Node *) n;
    4140                 :             :                 }
    4141                 :             :             | REFERENCES qualified_name opt_column_list key_match key_actions
    4142                 :             :                 {
    4143                 :         683 :                     Constraint *n = makeNode(Constraint);
    4144                 :             : 
    4145                 :         683 :                     n->contype = CONSTR_FOREIGN;
    4146                 :         683 :                     n->location = @1;
    4147                 :         683 :                     n->pktable = $2;
    4148                 :         683 :                     n->fk_attrs = NIL;
    4149                 :         683 :                     n->pk_attrs = $3;
    4150                 :         683 :                     n->fk_matchtype = $4;
    4151                 :         683 :                     n->fk_upd_action = ($5)->updateAction->action;
    4152                 :         683 :                     n->fk_del_action = ($5)->deleteAction->action;
    4153                 :         683 :                     n->fk_del_set_cols = ($5)->deleteAction->cols;
    4154                 :         683 :                     n->is_enforced = true;
    4155                 :         683 :                     n->skip_validation = false;
    4156                 :         683 :                     n->initially_valid = true;
    4157                 :         683 :                     $$ = (Node *) n;
    4158                 :             :                 }
    4159                 :             :         ;
    4160                 :             : 
    4161                 :             : opt_unique_null_treatment:
    4162                 :           8 :             NULLS_P DISTINCT        { $$ = true; }
    4163                 :          32 :             | NULLS_P NOT DISTINCT  { $$ = false; }
    4164                 :        5317 :             | /*EMPTY*/             { $$ = true; }
    4165                 :             :         ;
    4166                 :             : 
    4167                 :             : generated_when:
    4168                 :        1540 :             ALWAYS          { $$ = ATTRIBUTE_IDENTITY_ALWAYS; }
    4169                 :         118 :             | BY DEFAULT    { $$ = ATTRIBUTE_IDENTITY_BY_DEFAULT; }
    4170                 :             :         ;
    4171                 :             : 
    4172                 :             : opt_virtual_or_stored:
    4173                 :         675 :             STORED          { $$ = ATTRIBUTE_GENERATED_STORED; }
    4174                 :         460 :             | VIRTUAL       { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4175                 :         151 :             | /*EMPTY*/     { $$ = ATTRIBUTE_GENERATED_VIRTUAL; }
    4176                 :             :         ;
    4177                 :             : 
    4178                 :             : /*
    4179                 :             :  * ConstraintAttr represents constraint attributes, which we parse as if
    4180                 :             :  * they were independent constraint clauses, in order to avoid shift/reduce
    4181                 :             :  * conflicts (since NOT might start either an independent NOT NULL clause
    4182                 :             :  * or an attribute).  parse_utilcmd.c is responsible for attaching the
    4183                 :             :  * attribute information to the preceding "real" constraint node, and for
    4184                 :             :  * complaining if attribute clauses appear in the wrong place or wrong
    4185                 :             :  * combinations.
    4186                 :             :  *
    4187                 :             :  * See also ConstraintAttributeSpec, which can be used in places where
    4188                 :             :  * there is no parsing conflict.  (Note: currently, NOT VALID and NO INHERIT
    4189                 :             :  * are allowed clauses in ConstraintAttributeSpec, but not here.  Someday we
    4190                 :             :  * might need to allow them here too, but for the moment it doesn't seem
    4191                 :             :  * useful in the statements that use ConstraintAttr.)
    4192                 :             :  */
    4193                 :             : ConstraintAttr:
    4194                 :             :             DEFERRABLE
    4195                 :             :                 {
    4196                 :         104 :                     Constraint *n = makeNode(Constraint);
    4197                 :             : 
    4198                 :         104 :                     n->contype = CONSTR_ATTR_DEFERRABLE;
    4199                 :         104 :                     n->location = @1;
    4200                 :         104 :                     $$ = (Node *) n;
    4201                 :             :                 }
    4202                 :             :             | NOT DEFERRABLE
    4203                 :             :                 {
    4204                 :           4 :                     Constraint *n = makeNode(Constraint);
    4205                 :             : 
    4206                 :           4 :                     n->contype = CONSTR_ATTR_NOT_DEFERRABLE;
    4207                 :           4 :                     n->location = @1;
    4208                 :           4 :                     $$ = (Node *) n;
    4209                 :             :                 }
    4210                 :             :             | INITIALLY DEFERRED
    4211                 :             :                 {
    4212                 :          82 :                     Constraint *n = makeNode(Constraint);
    4213                 :             : 
    4214                 :          82 :                     n->contype = CONSTR_ATTR_DEFERRED;
    4215                 :          82 :                     n->location = @1;
    4216                 :          82 :                     $$ = (Node *) n;
    4217                 :             :                 }
    4218                 :             :             | INITIALLY IMMEDIATE
    4219                 :             :                 {
    4220                 :           8 :                     Constraint *n = makeNode(Constraint);
    4221                 :             : 
    4222                 :           8 :                     n->contype = CONSTR_ATTR_IMMEDIATE;
    4223                 :           8 :                     n->location = @1;
    4224                 :           8 :                     $$ = (Node *) n;
    4225                 :             :                 }
    4226                 :             :             | ENFORCED
    4227                 :             :                 {
    4228                 :          52 :                     Constraint *n = makeNode(Constraint);
    4229                 :             : 
    4230                 :          52 :                     n->contype = CONSTR_ATTR_ENFORCED;
    4231                 :          52 :                     n->location = @1;
    4232                 :          52 :                     $$ = (Node *) n;
    4233                 :             :                 }
    4234                 :             :             | NOT ENFORCED
    4235                 :             :                 {
    4236                 :          57 :                     Constraint *n = makeNode(Constraint);
    4237                 :             : 
    4238                 :          57 :                     n->contype = CONSTR_ATTR_NOT_ENFORCED;
    4239                 :          57 :                     n->location = @1;
    4240                 :          57 :                     $$ = (Node *) n;
    4241                 :             :                 }
    4242                 :             :         ;
    4243                 :             : 
    4244                 :             : 
    4245                 :             : TableLikeClause:
    4246                 :             :             LIKE qualified_name TableLikeOptionList
    4247                 :             :                 {
    4248                 :         525 :                     TableLikeClause *n = makeNode(TableLikeClause);
    4249                 :             : 
    4250                 :         525 :                     n->relation = $2;
    4251                 :         525 :                     n->options = $3;
    4252                 :         525 :                     n->relationOid = InvalidOid;
    4253                 :         525 :                     $$ = (Node *) n;
    4254                 :             :                 }
    4255                 :             :         ;
    4256                 :             : 
    4257                 :             : TableLikeOptionList:
    4258                 :         207 :                 TableLikeOptionList INCLUDING TableLikeOption   { $$ = $1 | $3; }
    4259                 :           5 :                 | TableLikeOptionList EXCLUDING TableLikeOption { $$ = $1 & ~$3; }
    4260                 :         525 :                 | /* EMPTY */                       { $$ = 0; }
    4261                 :             :         ;
    4262                 :             : 
    4263                 :             : TableLikeOption:
    4264                 :          20 :                 COMMENTS            { $$ = CREATE_TABLE_LIKE_COMMENTS; }
    4265                 :           4 :                 | COMPRESSION       { $$ = CREATE_TABLE_LIKE_COMPRESSION; }
    4266                 :          40 :                 | CONSTRAINTS       { $$ = CREATE_TABLE_LIKE_CONSTRAINTS; }
    4267                 :          17 :                 | DEFAULTS          { $$ = CREATE_TABLE_LIKE_DEFAULTS; }
    4268                 :           8 :                 | IDENTITY_P        { $$ = CREATE_TABLE_LIKE_IDENTITY; }
    4269                 :          20 :                 | GENERATED         { $$ = CREATE_TABLE_LIKE_GENERATED; }
    4270                 :          33 :                 | INDEXES           { $$ = CREATE_TABLE_LIKE_INDEXES; }
    4271                 :           8 :                 | STATISTICS        { $$ = CREATE_TABLE_LIKE_STATISTICS; }
    4272                 :          17 :                 | STORAGE           { $$ = CREATE_TABLE_LIKE_STORAGE; }
    4273                 :          45 :                 | ALL               { $$ = CREATE_TABLE_LIKE_ALL; }
    4274                 :             :         ;
    4275                 :             : 
    4276                 :             : 
    4277                 :             : /* ConstraintElem specifies constraint syntax which is not embedded into
    4278                 :             :  *  a column definition. ColConstraintElem specifies the embedded form.
    4279                 :             :  * - thomas 1997-12-03
    4280                 :             :  */
    4281                 :             : TableConstraint:
    4282                 :             :             CONSTRAINT name ConstraintElem
    4283                 :             :                 {
    4284                 :        2779 :                     Constraint *n = castNode(Constraint, $3);
    4285                 :             : 
    4286                 :        2779 :                     n->conname = $2;
    4287                 :        2779 :                     n->location = @1;
    4288                 :        2779 :                     $$ = (Node *) n;
    4289                 :             :                 }
    4290                 :        8085 :             | ConstraintElem                        { $$ = $1; }
    4291                 :             :         ;
    4292                 :             : 
    4293                 :             : ConstraintElem:
    4294                 :             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4295                 :             :                 {
    4296                 :         889 :                     Constraint *n = makeNode(Constraint);
    4297                 :             : 
    4298                 :         889 :                     n->contype = CONSTR_CHECK;
    4299                 :         889 :                     n->location = @1;
    4300                 :         889 :                     n->raw_expr = $3;
    4301                 :         889 :                     n->cooked_expr = NULL;
    4302                 :         889 :                     processCASbits($5, @5, "CHECK",
    4303                 :             :                                    NULL, NULL, &n->is_enforced, &n->skip_validation,
    4304                 :             :                                    &n->is_no_inherit, yyscanner);
    4305                 :         889 :                     n->initially_valid = !n->skip_validation;
    4306                 :         889 :                     $$ = (Node *) n;
    4307                 :             :                 }
    4308                 :             :             | NOT NULL_P ColId ConstraintAttributeSpec
    4309                 :             :                 {
    4310                 :         437 :                     Constraint *n = makeNode(Constraint);
    4311                 :             : 
    4312                 :         437 :                     n->contype = CONSTR_NOTNULL;
    4313                 :         437 :                     n->location = @1;
    4314                 :         437 :                     n->keys = list_make1(makeString($3));
    4315                 :         437 :                     processCASbits($4, @4, "NOT NULL",
    4316                 :             :                                    NULL, NULL, NULL, &n->skip_validation,
    4317                 :             :                                    &n->is_no_inherit, yyscanner);
    4318                 :         437 :                     n->initially_valid = !n->skip_validation;
    4319                 :         437 :                     $$ = (Node *) n;
    4320                 :             :                 }
    4321                 :             :             | UNIQUE opt_unique_null_treatment '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4322                 :             :                 ConstraintAttributeSpec
    4323                 :             :                 {
    4324                 :         439 :                     Constraint *n = makeNode(Constraint);
    4325                 :             : 
    4326                 :         439 :                     n->contype = CONSTR_UNIQUE;
    4327                 :         439 :                     n->location = @1;
    4328                 :         439 :                     n->nulls_not_distinct = !$2;
    4329                 :         439 :                     n->keys = $4;
    4330                 :         439 :                     n->without_overlaps = $5;
    4331                 :         439 :                     n->including = $7;
    4332                 :         439 :                     n->options = $8;
    4333                 :         439 :                     n->indexname = NULL;
    4334                 :         439 :                     n->indexspace = $9;
    4335                 :         439 :                     processCASbits($10, @10, "UNIQUE",
    4336                 :             :                                    &n->deferrable, &n->initdeferred, NULL,
    4337                 :             :                                    NULL, NULL, yyscanner);
    4338                 :         439 :                     $$ = (Node *) n;
    4339                 :             :                 }
    4340                 :             :             | UNIQUE ExistingIndex ConstraintAttributeSpec
    4341                 :             :                 {
    4342                 :        2762 :                     Constraint *n = makeNode(Constraint);
    4343                 :             : 
    4344                 :        2762 :                     n->contype = CONSTR_UNIQUE;
    4345                 :        2762 :                     n->location = @1;
    4346                 :        2762 :                     n->keys = NIL;
    4347                 :        2762 :                     n->including = NIL;
    4348                 :        2762 :                     n->options = NIL;
    4349                 :        2762 :                     n->indexname = $2;
    4350                 :        2762 :                     n->indexspace = NULL;
    4351                 :        2762 :                     processCASbits($3, @3, "UNIQUE",
    4352                 :             :                                    &n->deferrable, &n->initdeferred, NULL,
    4353                 :             :                                    NULL, NULL, yyscanner);
    4354                 :        2762 :                     $$ = (Node *) n;
    4355                 :             :                 }
    4356                 :             :             | PRIMARY KEY '(' columnList opt_without_overlaps ')' opt_c_include opt_definition OptConsTableSpace
    4357                 :             :                 ConstraintAttributeSpec
    4358                 :             :                 {
    4359                 :        1381 :                     Constraint *n = makeNode(Constraint);
    4360                 :             : 
    4361                 :        1381 :                     n->contype = CONSTR_PRIMARY;
    4362                 :        1381 :                     n->location = @1;
    4363                 :        1381 :                     n->keys = $4;
    4364                 :        1381 :                     n->without_overlaps = $5;
    4365                 :        1381 :                     n->including = $7;
    4366                 :        1381 :                     n->options = $8;
    4367                 :        1381 :                     n->indexname = NULL;
    4368                 :        1381 :                     n->indexspace = $9;
    4369                 :        1381 :                     processCASbits($10, @10, "PRIMARY KEY",
    4370                 :             :                                    &n->deferrable, &n->initdeferred, NULL,
    4371                 :             :                                    NULL, NULL, yyscanner);
    4372                 :        1381 :                     $$ = (Node *) n;
    4373                 :             :                 }
    4374                 :             :             | PRIMARY KEY ExistingIndex ConstraintAttributeSpec
    4375                 :             :                 {
    4376                 :        3578 :                     Constraint *n = makeNode(Constraint);
    4377                 :             : 
    4378                 :        3578 :                     n->contype = CONSTR_PRIMARY;
    4379                 :        3578 :                     n->location = @1;
    4380                 :        3578 :                     n->keys = NIL;
    4381                 :        3578 :                     n->including = NIL;
    4382                 :        3578 :                     n->options = NIL;
    4383                 :        3578 :                     n->indexname = $3;
    4384                 :        3578 :                     n->indexspace = NULL;
    4385                 :        3578 :                     processCASbits($4, @4, "PRIMARY KEY",
    4386                 :             :                                    &n->deferrable, &n->initdeferred, NULL,
    4387                 :             :                                    NULL, NULL, yyscanner);
    4388                 :        3578 :                     $$ = (Node *) n;
    4389                 :             :                 }
    4390                 :             :             | EXCLUDE access_method_clause '(' ExclusionConstraintList ')'
    4391                 :             :                 opt_c_include opt_definition OptConsTableSpace OptWhereClause
    4392                 :             :                 ConstraintAttributeSpec
    4393                 :             :                 {
    4394                 :         169 :                     Constraint *n = makeNode(Constraint);
    4395                 :             : 
    4396                 :         169 :                     n->contype = CONSTR_EXCLUSION;
    4397                 :         169 :                     n->location = @1;
    4398                 :         169 :                     n->access_method = $2;
    4399                 :         169 :                     n->exclusions = $4;
    4400                 :         169 :                     n->including = $6;
    4401                 :         169 :                     n->options = $7;
    4402                 :         169 :                     n->indexname = NULL;
    4403                 :         169 :                     n->indexspace = $8;
    4404                 :         169 :                     n->where_clause = $9;
    4405                 :         169 :                     processCASbits($10, @10, "EXCLUDE",
    4406                 :             :                                    &n->deferrable, &n->initdeferred, NULL,
    4407                 :             :                                    NULL, NULL, yyscanner);
    4408                 :         169 :                     $$ = (Node *) n;
    4409                 :             :                 }
    4410                 :             :             | FOREIGN KEY '(' columnList optionalPeriodName ')' REFERENCES qualified_name
    4411                 :             :                 opt_column_and_period_list key_match key_actions ConstraintAttributeSpec
    4412                 :             :                 {
    4413                 :        1209 :                     Constraint *n = makeNode(Constraint);
    4414                 :             : 
    4415                 :        1209 :                     n->contype = CONSTR_FOREIGN;
    4416                 :        1209 :                     n->location = @1;
    4417                 :        1209 :                     n->pktable = $8;
    4418                 :        1209 :                     n->fk_attrs = $4;
    4419         [ +  + ]:        1209 :                     if ($5)
    4420                 :             :                     {
    4421                 :         210 :                         n->fk_attrs = lappend(n->fk_attrs, $5);
    4422                 :         210 :                         n->fk_with_period = true;
    4423                 :             :                     }
    4424                 :        1209 :                     n->pk_attrs = linitial($9);
    4425         [ +  + ]:        1209 :                     if (lsecond($9))
    4426                 :             :                     {
    4427                 :         112 :                         n->pk_attrs = lappend(n->pk_attrs, lsecond($9));
    4428                 :         112 :                         n->pk_with_period = true;
    4429                 :             :                     }
    4430                 :        1209 :                     n->fk_matchtype = $10;
    4431                 :        1209 :                     n->fk_upd_action = ($11)->updateAction->action;
    4432                 :        1209 :                     n->fk_del_action = ($11)->deleteAction->action;
    4433                 :        1209 :                     n->fk_del_set_cols = ($11)->deleteAction->cols;
    4434                 :        1209 :                     processCASbits($12, @12, "FOREIGN KEY",
    4435                 :             :                                    &n->deferrable, &n->initdeferred,
    4436                 :             :                                    &n->is_enforced, &n->skip_validation, NULL,
    4437                 :             :                                    yyscanner);
    4438                 :        1209 :                     n->initially_valid = !n->skip_validation;
    4439                 :        1209 :                     $$ = (Node *) n;
    4440                 :             :                 }
    4441                 :             :         ;
    4442                 :             : 
    4443                 :             : /*
    4444                 :             :  * DomainConstraint is separate from TableConstraint because the syntax for
    4445                 :             :  * NOT NULL constraints is different.  For table constraints, we need to
    4446                 :             :  * accept a column name, but for domain constraints, we don't.  (We could
    4447                 :             :  * accept something like NOT NULL VALUE, but that seems weird.)  CREATE DOMAIN
    4448                 :             :  * (which uses ColQualList) has for a long time accepted NOT NULL without a
    4449                 :             :  * column name, so it makes sense that ALTER DOMAIN (which uses
    4450                 :             :  * DomainConstraint) does as well.  None of these syntaxes are per SQL
    4451                 :             :  * standard; we are just living with the bits of inconsistency that have built
    4452                 :             :  * up over time.
    4453                 :             :  */
    4454                 :             : DomainConstraint:
    4455                 :             :             CONSTRAINT name DomainConstraintElem
    4456                 :             :                 {
    4457                 :         113 :                     Constraint *n = castNode(Constraint, $3);
    4458                 :             : 
    4459                 :         113 :                     n->conname = $2;
    4460                 :         113 :                     n->location = @1;
    4461                 :         113 :                     $$ = (Node *) n;
    4462                 :             :                 }
    4463                 :          12 :             | DomainConstraintElem                  { $$ = $1; }
    4464                 :             :         ;
    4465                 :             : 
    4466                 :             : DomainConstraintElem:
    4467                 :             :             CHECK '(' a_expr ')' ConstraintAttributeSpec
    4468                 :             :                 {
    4469                 :         113 :                     Constraint *n = makeNode(Constraint);
    4470                 :             : 
    4471                 :         113 :                     n->contype = CONSTR_CHECK;
    4472                 :         113 :                     n->location = @1;
    4473                 :         113 :                     n->raw_expr = $3;
    4474                 :         113 :                     n->cooked_expr = NULL;
    4475                 :         113 :                     processCASbits($5, @5, "CHECK",
    4476                 :             :                                    NULL, NULL, NULL, &n->skip_validation,
    4477                 :             :                                    &n->is_no_inherit, yyscanner);
    4478                 :         105 :                     n->is_enforced = true;
    4479                 :         105 :                     n->initially_valid = !n->skip_validation;
    4480                 :         105 :                     $$ = (Node *) n;
    4481                 :             :                 }
    4482                 :             :             | NOT NULL_P ConstraintAttributeSpec
    4483                 :             :                 {
    4484                 :          20 :                     Constraint *n = makeNode(Constraint);
    4485                 :             : 
    4486                 :          20 :                     n->contype = CONSTR_NOTNULL;
    4487                 :          20 :                     n->location = @1;
    4488                 :          20 :                     n->keys = list_make1(makeString("value"));
    4489                 :             :                     /* no NOT VALID, NO INHERIT support */
    4490                 :          20 :                     processCASbits($3, @3, "NOT NULL",
    4491                 :             :                                    NULL, NULL, NULL,
    4492                 :             :                                    NULL, NULL, yyscanner);
    4493                 :          20 :                     n->initially_valid = true;
    4494                 :          20 :                     $$ = (Node *) n;
    4495                 :             :                 }
    4496                 :             :         ;
    4497                 :             : 
    4498                 :          97 : opt_no_inherit: NO INHERIT                          {  $$ = true; }
    4499                 :        4756 :             | /* EMPTY */                           {  $$ = false; }
    4500                 :             :         ;
    4501                 :             : 
    4502                 :             : opt_without_overlaps:
    4503                 :         388 :             WITHOUT OVERLAPS                        { $$ = true; }
    4504                 :        1432 :             | /*EMPTY*/                             { $$ = false; }
    4505                 :             :     ;
    4506                 :             : 
    4507                 :             : opt_column_list:
    4508                 :        5832 :             '(' columnList ')'                      { $$ = $2; }
    4509                 :       22111 :             | /*EMPTY*/                             { $$ = NIL; }
    4510                 :             :         ;
    4511                 :             : 
    4512                 :             : columnList:
    4513                 :        9936 :             columnElem                              { $$ = list_make1($1); }
    4514                 :       15739 :             | columnList ',' columnElem             { $$ = lappend($1, $3); }
    4515                 :             :         ;
    4516                 :             : 
    4517                 :             : optionalPeriodName:
    4518                 :         322 :             ',' PERIOD columnElem { $$ = $3; }
    4519                 :        1600 :             | /*EMPTY*/               { $$ = NULL; }
    4520                 :             :     ;
    4521                 :             : 
    4522                 :             : opt_column_and_period_list:
    4523                 :         709 :             '(' columnList optionalPeriodName ')'           { $$ = list_make2($2, $3); }
    4524                 :         504 :             | /*EMPTY*/                             { $$ = list_make2(NIL, NULL); }
    4525                 :             :         ;
    4526                 :             : 
    4527                 :             : columnElem: ColId
    4528                 :             :                 {
    4529                 :       25997 :                     $$ = (Node *) makeString($1);
    4530                 :             :                 }
    4531                 :             :         ;
    4532                 :             : 
    4533                 :         100 : opt_c_include:  INCLUDE '(' columnList ')'          { $$ = $3; }
    4534                 :        1889 :              |      /* EMPTY */                     { $$ = NIL; }
    4535                 :             :         ;
    4536                 :             : 
    4537                 :             : key_match:  MATCH FULL
    4538                 :             :             {
    4539                 :          65 :                 $$ = FKCONSTR_MATCH_FULL;
    4540                 :             :             }
    4541                 :             :         | MATCH PARTIAL
    4542                 :             :             {
    4543         [ #  # ]:           0 :                 ereport(ERROR,
    4544                 :             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4545                 :             :                          errmsg("MATCH PARTIAL not yet implemented"),
    4546                 :             :                          parser_errposition(@1)));
    4547                 :             :                 $$ = FKCONSTR_MATCH_PARTIAL;
    4548                 :             :             }
    4549                 :             :         | MATCH SIMPLE
    4550                 :             :             {
    4551                 :           4 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4552                 :             :             }
    4553                 :             :         | /*EMPTY*/
    4554                 :             :             {
    4555                 :        1827 :                 $$ = FKCONSTR_MATCH_SIMPLE;
    4556                 :             :             }
    4557                 :             :         ;
    4558                 :             : 
    4559                 :             : ExclusionConstraintList:
    4560                 :         169 :             ExclusionConstraintElem                 { $$ = list_make1($1); }
    4561                 :             :             | ExclusionConstraintList ',' ExclusionConstraintElem
    4562                 :          83 :                                                     { $$ = lappend($1, $3); }
    4563                 :             :         ;
    4564                 :             : 
    4565                 :             : ExclusionConstraintElem: index_elem WITH any_operator
    4566                 :             :             {
    4567                 :         252 :                 $$ = list_make2($1, $3);
    4568                 :             :             }
    4569                 :             :             /* allow OPERATOR() decoration for the benefit of ruleutils.c */
    4570                 :             :             | index_elem WITH OPERATOR '(' any_operator ')'
    4571                 :             :             {
    4572                 :           0 :                 $$ = list_make2($1, $5);
    4573                 :             :             }
    4574                 :             :         ;
    4575                 :             : 
    4576                 :             : OptWhereClause:
    4577                 :         308 :             WHERE '(' a_expr ')'                    { $$ = $3; }
    4578                 :         842 :             | /*EMPTY*/                             { $$ = NULL; }
    4579                 :             :         ;
    4580                 :             : 
    4581                 :             : key_actions:
    4582                 :             :             key_update
    4583                 :             :                 {
    4584                 :          49 :                     KeyActions *n = palloc_object(KeyActions);
    4585                 :             : 
    4586                 :          49 :                     n->updateAction = $1;
    4587                 :          49 :                     n->deleteAction = palloc_object(KeyAction);
    4588                 :          49 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4589                 :          49 :                     n->deleteAction->cols = NIL;
    4590                 :          49 :                     $$ = n;
    4591                 :             :                 }
    4592                 :             :             | key_delete
    4593                 :             :                 {
    4594                 :          93 :                     KeyActions *n = palloc_object(KeyActions);
    4595                 :             : 
    4596                 :          93 :                     n->updateAction = palloc_object(KeyAction);
    4597                 :          93 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4598                 :          93 :                     n->updateAction->cols = NIL;
    4599                 :          93 :                     n->deleteAction = $1;
    4600                 :          93 :                     $$ = n;
    4601                 :             :                 }
    4602                 :             :             | key_update key_delete
    4603                 :             :                 {
    4604                 :         111 :                     KeyActions *n = palloc_object(KeyActions);
    4605                 :             : 
    4606                 :         111 :                     n->updateAction = $1;
    4607                 :         111 :                     n->deleteAction = $2;
    4608                 :         111 :                     $$ = n;
    4609                 :             :                 }
    4610                 :             :             | key_delete key_update
    4611                 :             :                 {
    4612                 :         100 :                     KeyActions *n = palloc_object(KeyActions);
    4613                 :             : 
    4614                 :         100 :                     n->updateAction = $2;
    4615                 :         100 :                     n->deleteAction = $1;
    4616                 :         100 :                     $$ = n;
    4617                 :             :                 }
    4618                 :             :             | /*EMPTY*/
    4619                 :             :                 {
    4620                 :        1539 :                     KeyActions *n = palloc_object(KeyActions);
    4621                 :             : 
    4622                 :        1539 :                     n->updateAction = palloc_object(KeyAction);
    4623                 :        1539 :                     n->updateAction->action = FKCONSTR_ACTION_NOACTION;
    4624                 :        1539 :                     n->updateAction->cols = NIL;
    4625                 :        1539 :                     n->deleteAction = palloc_object(KeyAction);
    4626                 :        1539 :                     n->deleteAction->action = FKCONSTR_ACTION_NOACTION;
    4627                 :        1539 :                     n->deleteAction->cols = NIL;
    4628                 :        1539 :                     $$ = n;
    4629                 :             :                 }
    4630                 :             :         ;
    4631                 :             : 
    4632                 :             : key_update: ON UPDATE key_action
    4633                 :             :                 {
    4634         [ +  + ]:         264 :                     if (($3)->cols)
    4635   [ +  -  +  - ]:           4 :                         ereport(ERROR,
    4636                 :             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    4637                 :             :                                  errmsg("a column list with %s is only supported for ON DELETE actions",
    4638                 :             :                                         ($3)->action == FKCONSTR_ACTION_SETNULL ? "SET NULL" : "SET DEFAULT"),
    4639                 :             :                                  parser_errposition(@1)));
    4640                 :         260 :                     $$ = $3;
    4641                 :             :                 }
    4642                 :             :         ;
    4643                 :             : 
    4644                 :             : key_delete: ON DELETE_P key_action
    4645                 :             :                 {
    4646                 :         304 :                     $$ = $3;
    4647                 :             :                 }
    4648                 :             :         ;
    4649                 :             : 
    4650                 :             : key_action:
    4651                 :             :             NO ACTION
    4652                 :             :                 {
    4653                 :          51 :                     KeyAction *n = palloc_object(KeyAction);
    4654                 :             : 
    4655                 :          51 :                     n->action = FKCONSTR_ACTION_NOACTION;
    4656                 :          51 :                     n->cols = NIL;
    4657                 :          51 :                     $$ = n;
    4658                 :             :                 }
    4659                 :             :             | RESTRICT
    4660                 :             :                 {
    4661                 :          32 :                     KeyAction *n = palloc_object(KeyAction);
    4662                 :             : 
    4663                 :          32 :                     n->action = FKCONSTR_ACTION_RESTRICT;
    4664                 :          32 :                     n->cols = NIL;
    4665                 :          32 :                     $$ = n;
    4666                 :             :                 }
    4667                 :             :             | CASCADE
    4668                 :             :                 {
    4669                 :         293 :                     KeyAction *n = palloc_object(KeyAction);
    4670                 :             : 
    4671                 :         293 :                     n->action = FKCONSTR_ACTION_CASCADE;
    4672                 :         293 :                     n->cols = NIL;
    4673                 :         293 :                     $$ = n;
    4674                 :             :                 }
    4675                 :             :             | SET NULL_P opt_column_list
    4676                 :             :                 {
    4677                 :         124 :                     KeyAction *n = palloc_object(KeyAction);
    4678                 :             : 
    4679                 :         124 :                     n->action = FKCONSTR_ACTION_SETNULL;
    4680                 :         124 :                     n->cols = $3;
    4681                 :         124 :                     $$ = n;
    4682                 :             :                 }
    4683                 :             :             | SET DEFAULT opt_column_list
    4684                 :             :                 {
    4685                 :          68 :                     KeyAction *n = palloc_object(KeyAction);
    4686                 :             : 
    4687                 :          68 :                     n->action = FKCONSTR_ACTION_SETDEFAULT;
    4688                 :          68 :                     n->cols = $3;
    4689                 :          68 :                     $$ = n;
    4690                 :             :                 }
    4691                 :             :         ;
    4692                 :             : 
    4693                 :        1408 : OptInherit: INHERITS '(' qualified_name_list ')'    { $$ = $3; }
    4694                 :       18457 :             | /*EMPTY*/                             { $$ = NIL; }
    4695                 :             :         ;
    4696                 :             : 
    4697                 :             : /* Optional partition key specification */
    4698                 :        3413 : OptPartitionSpec: PartitionSpec { $$ = $1; }
    4699                 :       22220 :             | /*EMPTY*/         { $$ = NULL; }
    4700                 :             :         ;
    4701                 :             : 
    4702                 :             : PartitionSpec: PARTITION BY ColId '(' part_params ')'
    4703                 :             :                 {
    4704                 :        3417 :                     PartitionSpec *n = makeNode(PartitionSpec);
    4705                 :             : 
    4706                 :        3417 :                     n->strategy = parsePartitionStrategy($3, @3, yyscanner);
    4707                 :        3413 :                     n->partParams = $5;
    4708                 :        3413 :                     n->location = @1;
    4709                 :             : 
    4710                 :        3413 :                     $$ = n;
    4711                 :             :                 }
    4712                 :             :         ;
    4713                 :             : 
    4714                 :        3417 : part_params:    part_elem                       { $$ = list_make1($1); }
    4715                 :         322 :             | part_params ',' part_elem         { $$ = lappend($1, $3); }
    4716                 :             :         ;
    4717                 :             : 
    4718                 :             : part_elem: ColId opt_collate opt_qualified_name
    4719                 :             :                 {
    4720                 :        3507 :                     PartitionElem *n = makeNode(PartitionElem);
    4721                 :             : 
    4722                 :        3507 :                     n->name = $1;
    4723                 :        3507 :                     n->expr = NULL;
    4724                 :        3507 :                     n->collation = $2;
    4725                 :        3507 :                     n->opclass = $3;
    4726                 :        3507 :                     n->location = @1;
    4727                 :        3507 :                     $$ = n;
    4728                 :             :                 }
    4729                 :             :             | func_expr_windowless opt_collate opt_qualified_name
    4730                 :             :                 {
    4731                 :          86 :                     PartitionElem *n = makeNode(PartitionElem);
    4732                 :             : 
    4733                 :          86 :                     n->name = NULL;
    4734                 :          86 :                     n->expr = $1;
    4735                 :          86 :                     n->collation = $2;
    4736                 :          86 :                     n->opclass = $3;
    4737                 :          86 :                     n->location = @1;
    4738                 :          86 :                     $$ = n;
    4739                 :             :                 }
    4740                 :             :             | '(' a_expr ')' opt_collate opt_qualified_name
    4741                 :             :                 {
    4742                 :         146 :                     PartitionElem *n = makeNode(PartitionElem);
    4743                 :             : 
    4744                 :         146 :                     n->name = NULL;
    4745                 :         146 :                     n->expr = $2;
    4746                 :         146 :                     n->collation = $4;
    4747                 :         146 :                     n->opclass = $5;
    4748                 :         146 :                     n->location = @1;
    4749                 :         146 :                     $$ = n;
    4750                 :             :                 }
    4751                 :             :         ;
    4752                 :             : 
    4753                 :             : table_access_method_clause:
    4754                 :          79 :             USING name                          { $$ = $2; }
    4755                 :       26838 :             | /*EMPTY*/                         { $$ = NULL; }
    4756                 :             :         ;
    4757                 :             : 
    4758                 :             : /* WITHOUT OIDS is legacy only */
    4759                 :             : OptWith:
    4760                 :         661 :             WITH reloptions             { $$ = $2; }
    4761                 :          16 :             | WITHOUT OIDS              { $$ = NIL; }
    4762                 :       25866 :             | /*EMPTY*/                 { $$ = NIL; }
    4763                 :             :         ;
    4764                 :             : 
    4765                 :          39 : OnCommitOption:  ON COMMIT DROP             { $$ = ONCOMMIT_DROP; }
    4766                 :          69 :             | ON COMMIT DELETE_P ROWS       { $$ = ONCOMMIT_DELETE_ROWS; }
    4767                 :          16 :             | ON COMMIT PRESERVE ROWS       { $$ = ONCOMMIT_PRESERVE_ROWS; }
    4768                 :       26419 :             | /*EMPTY*/                     { $$ = ONCOMMIT_NOOP; }
    4769                 :             :         ;
    4770                 :             : 
    4771                 :         139 : OptTableSpace:   TABLESPACE name                    { $$ = $2; }
    4772                 :       31387 :             | /*EMPTY*/                             { $$ = NULL; }
    4773                 :             :         ;
    4774                 :             : 
    4775                 :          42 : OptConsTableSpace:   USING INDEX TABLESPACE name    { $$ = $4; }
    4776                 :        5936 :             | /*EMPTY*/                             { $$ = NULL; }
    4777                 :             :         ;
    4778                 :             : 
    4779                 :        6340 : ExistingIndex:   USING INDEX name                   { $$ = $3; }
    4780                 :             :         ;
    4781                 :             : 
    4782                 :             : /*****************************************************************************
    4783                 :             :  *
    4784                 :             :  *      QUERY :
    4785                 :             :  *              CREATE STATISTICS [[IF NOT EXISTS] stats_name] [(stat types)]
    4786                 :             :  *                  ON expression-list FROM from_list
    4787                 :             :  *
    4788                 :             :  * Note: the expectation here is that the clauses after ON are a subset of
    4789                 :             :  * SELECT syntax, allowing for expressions and joined tables, and probably
    4790                 :             :  * someday a WHERE clause.  Much less than that is currently implemented,
    4791                 :             :  * but the grammar accepts it and then we'll throw FEATURE_NOT_SUPPORTED
    4792                 :             :  * errors as necessary at execution.
    4793                 :             :  *
    4794                 :             :  * Statistics name is optional unless IF NOT EXISTS is specified.
    4795                 :             :  *
    4796                 :             :  *****************************************************************************/
    4797                 :             : 
    4798                 :             : CreateStatsStmt:
    4799                 :             :             CREATE STATISTICS opt_qualified_name
    4800                 :             :             opt_name_list ON stats_params FROM from_list
    4801                 :             :                 {
    4802                 :         649 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4803                 :             : 
    4804                 :         649 :                     n->defnames = $3;
    4805                 :         649 :                     n->stat_types = $4;
    4806                 :         649 :                     n->exprs = $6;
    4807                 :         649 :                     n->relations = $8;
    4808                 :         649 :                     n->stxcomment = NULL;
    4809                 :         649 :                     n->if_not_exists = false;
    4810                 :         649 :                     $$ = (Node *) n;
    4811                 :             :                 }
    4812                 :             :             | CREATE STATISTICS IF_P NOT EXISTS any_name
    4813                 :             :             opt_name_list ON stats_params FROM from_list
    4814                 :             :                 {
    4815                 :           8 :                     CreateStatsStmt *n = makeNode(CreateStatsStmt);
    4816                 :             : 
    4817                 :           8 :                     n->defnames = $6;
    4818                 :           8 :                     n->stat_types = $7;
    4819                 :           8 :                     n->exprs = $9;
    4820                 :           8 :                     n->relations = $11;
    4821                 :           8 :                     n->stxcomment = NULL;
    4822                 :           8 :                     n->if_not_exists = true;
    4823                 :           8 :                     $$ = (Node *) n;
    4824                 :             :                 }
    4825                 :             :             ;
    4826                 :             : 
    4827                 :             : /*
    4828                 :             :  * Statistics attributes can be either simple column references, or arbitrary
    4829                 :             :  * expressions in parens.  For compatibility with index attributes permitted
    4830                 :             :  * in CREATE INDEX, we allow an expression that's just a function call to be
    4831                 :             :  * written without parens.
    4832                 :             :  */
    4833                 :             : 
    4834                 :         665 : stats_params:   stats_param                         { $$ = list_make1($1); }
    4835                 :         909 :             | stats_params ',' stats_param          { $$ = lappend($1, $3); }
    4836                 :             :         ;
    4837                 :             : 
    4838                 :             : stats_param:    ColId
    4839                 :             :                 {
    4840                 :        1151 :                     $$ = makeNode(StatsElem);
    4841                 :        1151 :                     $$->name = $1;
    4842                 :        1151 :                     $$->expr = NULL;
    4843                 :             :                 }
    4844                 :             :             | func_expr_windowless
    4845                 :             :                 {
    4846                 :          67 :                     $$ = makeNode(StatsElem);
    4847                 :          67 :                     $$->name = NULL;
    4848                 :          67 :                     $$->expr = $1;
    4849                 :             :                 }
    4850                 :             :             | '(' a_expr ')'
    4851                 :             :                 {
    4852                 :         356 :                     $$ = makeNode(StatsElem);
    4853                 :         356 :                     $$->name = NULL;
    4854                 :         356 :                     $$->expr = $2;
    4855                 :             :                 }
    4856                 :             :         ;
    4857                 :             : 
    4858                 :             : /*****************************************************************************
    4859                 :             :  *
    4860                 :             :  *      QUERY :
    4861                 :             :  *              ALTER STATISTICS [IF EXISTS] stats_name
    4862                 :             :  *                  SET STATISTICS  <SignedIconst>
    4863                 :             :  *
    4864                 :             :  *****************************************************************************/
    4865                 :             : 
    4866                 :             : AlterStatsStmt:
    4867                 :             :             ALTER STATISTICS any_name SET STATISTICS set_statistics_value
    4868                 :             :                 {
    4869                 :          13 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4870                 :             : 
    4871                 :          13 :                     n->defnames = $3;
    4872                 :          13 :                     n->missing_ok = false;
    4873                 :          13 :                     n->stxstattarget = $6;
    4874                 :          13 :                     $$ = (Node *) n;
    4875                 :             :                 }
    4876                 :             :             | ALTER STATISTICS IF_P EXISTS any_name SET STATISTICS set_statistics_value
    4877                 :             :                 {
    4878                 :           4 :                     AlterStatsStmt *n = makeNode(AlterStatsStmt);
    4879                 :             : 
    4880                 :           4 :                     n->defnames = $5;
    4881                 :           4 :                     n->missing_ok = true;
    4882                 :           4 :                     n->stxstattarget = $8;
    4883                 :           4 :                     $$ = (Node *) n;
    4884                 :             :                 }
    4885                 :             :             ;
    4886                 :             : 
    4887                 :             : /*****************************************************************************
    4888                 :             :  *
    4889                 :             :  *      QUERY :
    4890                 :             :  *              CREATE TABLE relname AS SelectStmt [ WITH [NO] DATA ]
    4891                 :             :  *
    4892                 :             :  *
    4893                 :             :  * Note: SELECT ... INTO is a now-deprecated alternative for this.
    4894                 :             :  *
    4895                 :             :  *****************************************************************************/
    4896                 :             : 
    4897                 :             : CreateAsStmt:
    4898                 :             :         CREATE OptTemp TABLE create_as_target AS SelectStmt opt_with_data
    4899                 :             :                 {
    4900                 :         829 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4901                 :             : 
    4902                 :         829 :                     ctas->query = $6;
    4903                 :         829 :                     ctas->into = $4;
    4904                 :         829 :                     ctas->objtype = OBJECT_TABLE;
    4905                 :         829 :                     ctas->is_select_into = false;
    4906                 :         829 :                     ctas->if_not_exists = false;
    4907                 :             :                     /* cram additional flags into the IntoClause */
    4908                 :         829 :                     $4->rel->relpersistence = $2;
    4909                 :         829 :                     $4->skipData = !($7);
    4910                 :         829 :                     $$ = (Node *) ctas;
    4911                 :             :                 }
    4912                 :             :         | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS SelectStmt opt_with_data
    4913                 :             :                 {
    4914                 :          31 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4915                 :             : 
    4916                 :          31 :                     ctas->query = $9;
    4917                 :          31 :                     ctas->into = $7;
    4918                 :          31 :                     ctas->objtype = OBJECT_TABLE;
    4919                 :          31 :                     ctas->is_select_into = false;
    4920                 :          31 :                     ctas->if_not_exists = true;
    4921                 :             :                     /* cram additional flags into the IntoClause */
    4922                 :          31 :                     $7->rel->relpersistence = $2;
    4923                 :          31 :                     $7->skipData = !($10);
    4924                 :          31 :                     $$ = (Node *) ctas;
    4925                 :             :                 }
    4926                 :             :         ;
    4927                 :             : 
    4928                 :             : create_as_target:
    4929                 :             :             qualified_name opt_column_list table_access_method_clause
    4930                 :             :             OptWith OnCommitOption OptTableSpace
    4931                 :             :                 {
    4932                 :         918 :                     $$ = makeNode(IntoClause);
    4933                 :         918 :                     $$->rel = $1;
    4934                 :         918 :                     $$->colNames = $2;
    4935                 :         918 :                     $$->accessMethod = $3;
    4936                 :         918 :                     $$->options = $4;
    4937                 :         918 :                     $$->onCommit = $5;
    4938                 :         918 :                     $$->tableSpaceName = $6;
    4939                 :         918 :                     $$->viewQuery = NULL;
    4940                 :         918 :                     $$->skipData = false;        /* might get changed later */
    4941                 :             :                 }
    4942                 :             :         ;
    4943                 :             : 
    4944                 :             : opt_with_data:
    4945                 :          24 :             WITH DATA_P                             { $$ = true; }
    4946                 :         145 :             | WITH NO DATA_P                        { $$ = false; }
    4947                 :        1293 :             | /*EMPTY*/                             { $$ = true; }
    4948                 :             :         ;
    4949                 :             : 
    4950                 :             : 
    4951                 :             : /*****************************************************************************
    4952                 :             :  *
    4953                 :             :  *      QUERY :
    4954                 :             :  *              CREATE MATERIALIZED VIEW relname AS SelectStmt
    4955                 :             :  *
    4956                 :             :  *****************************************************************************/
    4957                 :             : 
    4958                 :             : CreateMatViewStmt:
    4959                 :             :         CREATE OptNoLog MATERIALIZED VIEW create_mv_target AS SelectStmt opt_with_data
    4960                 :             :                 {
    4961                 :         341 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4962                 :             : 
    4963                 :         341 :                     ctas->query = $7;
    4964                 :         341 :                     ctas->into = $5;
    4965                 :         341 :                     ctas->objtype = OBJECT_MATVIEW;
    4966                 :         341 :                     ctas->is_select_into = false;
    4967                 :         341 :                     ctas->if_not_exists = false;
    4968                 :             :                     /* cram additional flags into the IntoClause */
    4969                 :         341 :                     $5->rel->relpersistence = $2;
    4970                 :         341 :                     $5->skipData = !($8);
    4971                 :         341 :                     $$ = (Node *) ctas;
    4972                 :             :                 }
    4973                 :             :         | CREATE OptNoLog MATERIALIZED VIEW IF_P NOT EXISTS create_mv_target AS SelectStmt opt_with_data
    4974                 :             :                 {
    4975                 :          29 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
    4976                 :             : 
    4977                 :          29 :                     ctas->query = $10;
    4978                 :          29 :                     ctas->into = $8;
    4979                 :          29 :                     ctas->objtype = OBJECT_MATVIEW;
    4980                 :          29 :                     ctas->is_select_into = false;
    4981                 :          29 :                     ctas->if_not_exists = true;
    4982                 :             :                     /* cram additional flags into the IntoClause */
    4983                 :          29 :                     $8->rel->relpersistence = $2;
    4984                 :          29 :                     $8->skipData = !($11);
    4985                 :          29 :                     $$ = (Node *) ctas;
    4986                 :             :                 }
    4987                 :             :         ;
    4988                 :             : 
    4989                 :             : create_mv_target:
    4990                 :             :             qualified_name opt_column_list table_access_method_clause opt_reloptions OptTableSpace
    4991                 :             :                 {
    4992                 :         370 :                     $$ = makeNode(IntoClause);
    4993                 :         370 :                     $$->rel = $1;
    4994                 :         370 :                     $$->colNames = $2;
    4995                 :         370 :                     $$->accessMethod = $3;
    4996                 :         370 :                     $$->options = $4;
    4997                 :         370 :                     $$->onCommit = ONCOMMIT_NOOP;
    4998                 :         370 :                     $$->tableSpaceName = $5;
    4999                 :         370 :                     $$->viewQuery = NULL;        /* filled at analysis time */
    5000                 :         370 :                     $$->skipData = false;        /* might get changed later */
    5001                 :             :                 }
    5002                 :             :         ;
    5003                 :             : 
    5004                 :           0 : OptNoLog:   UNLOGGED                    { $$ = RELPERSISTENCE_UNLOGGED; }
    5005                 :         370 :             | /*EMPTY*/                 { $$ = RELPERSISTENCE_PERMANENT; }
    5006                 :             :         ;
    5007                 :             : 
    5008                 :             : 
    5009                 :             : /*****************************************************************************
    5010                 :             :  *
    5011                 :             :  *      QUERY :
    5012                 :             :  *              REFRESH MATERIALIZED VIEW qualified_name
    5013                 :             :  *
    5014                 :             :  *****************************************************************************/
    5015                 :             : 
    5016                 :             : RefreshMatViewStmt:
    5017                 :             :             REFRESH MATERIALIZED VIEW opt_concurrently qualified_name opt_with_data
    5018                 :             :                 {
    5019                 :         174 :                     RefreshMatViewStmt *n = makeNode(RefreshMatViewStmt);
    5020                 :             : 
    5021                 :         174 :                     n->concurrent = $4;
    5022                 :         174 :                     n->relation = $5;
    5023                 :         174 :                     n->skipData = !($6);
    5024                 :         174 :                     $$ = (Node *) n;
    5025                 :             :                 }
    5026                 :             :         ;
    5027                 :             : 
    5028                 :             : 
    5029                 :             : /*****************************************************************************
    5030                 :             :  *
    5031                 :             :  *      QUERY :
    5032                 :             :  *              CREATE SEQUENCE seqname
    5033                 :             :  *              ALTER SEQUENCE seqname
    5034                 :             :  *
    5035                 :             :  *****************************************************************************/
    5036                 :             : 
    5037                 :             : CreateSeqStmt:
    5038                 :             :             CREATE OptTemp SEQUENCE qualified_name OptSeqOptList
    5039                 :             :                 {
    5040                 :         442 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    5041                 :             : 
    5042                 :         442 :                     $4->relpersistence = $2;
    5043                 :         442 :                     n->sequence = $4;
    5044                 :         442 :                     n->options = $5;
    5045                 :         442 :                     n->ownerId = InvalidOid;
    5046                 :         442 :                     n->if_not_exists = false;
    5047                 :         442 :                     $$ = (Node *) n;
    5048                 :             :                 }
    5049                 :             :             | CREATE OptTemp SEQUENCE IF_P NOT EXISTS qualified_name OptSeqOptList
    5050                 :             :                 {
    5051                 :          13 :                     CreateSeqStmt *n = makeNode(CreateSeqStmt);
    5052                 :             : 
    5053                 :          13 :                     $7->relpersistence = $2;
    5054                 :          13 :                     n->sequence = $7;
    5055                 :          13 :                     n->options = $8;
    5056                 :          13 :                     n->ownerId = InvalidOid;
    5057                 :          13 :                     n->if_not_exists = true;
    5058                 :          13 :                     $$ = (Node *) n;
    5059                 :             :                 }
    5060                 :             :         ;
    5061                 :             : 
    5062                 :             : AlterSeqStmt:
    5063                 :             :             ALTER SEQUENCE qualified_name SeqOptList
    5064                 :             :                 {
    5065                 :         125 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    5066                 :             : 
    5067                 :         125 :                     n->sequence = $3;
    5068                 :         125 :                     n->options = $4;
    5069                 :         125 :                     n->missing_ok = false;
    5070                 :         125 :                     $$ = (Node *) n;
    5071                 :             :                 }
    5072                 :             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SeqOptList
    5073                 :             :                 {
    5074                 :           8 :                     AlterSeqStmt *n = makeNode(AlterSeqStmt);
    5075                 :             : 
    5076                 :           8 :                     n->sequence = $5;
    5077                 :           8 :                     n->options = $6;
    5078                 :           8 :                     n->missing_ok = true;
    5079                 :           8 :                     $$ = (Node *) n;
    5080                 :             :                 }
    5081                 :             : 
    5082                 :             :         ;
    5083                 :             : 
    5084                 :         164 : OptSeqOptList: SeqOptList                           { $$ = $1; }
    5085                 :         291 :             | /*EMPTY*/                             { $$ = NIL; }
    5086                 :             :         ;
    5087                 :             : 
    5088                 :          42 : OptParenthesizedSeqOptList: '(' SeqOptList ')'      { $$ = $2; }
    5089                 :         301 :             | /*EMPTY*/                             { $$ = NIL; }
    5090                 :             :         ;
    5091                 :             : 
    5092                 :         339 : SeqOptList: SeqOptElem                              { $$ = list_make1($1); }
    5093                 :         441 :             | SeqOptList SeqOptElem                 { $$ = lappend($1, $2); }
    5094                 :             :         ;
    5095                 :             : 
    5096                 :             : SeqOptElem: AS SimpleTypename
    5097                 :             :                 {
    5098                 :         119 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    5099                 :             :                 }
    5100                 :             :             | CACHE NumericOnly
    5101                 :             :                 {
    5102                 :          67 :                     $$ = makeDefElem("cache", (Node *) $2, @1);
    5103                 :             :                 }
    5104                 :             :             | CYCLE
    5105                 :             :                 {
    5106                 :          22 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(true), @1);
    5107                 :             :                 }
    5108                 :             :             | NO CYCLE
    5109                 :             :                 {
    5110                 :           9 :                     $$ = makeDefElem("cycle", (Node *) makeBoolean(false), @1);
    5111                 :             :                 }
    5112                 :             :             | INCREMENT opt_by NumericOnly
    5113                 :             :                 {
    5114                 :         150 :                     $$ = makeDefElem("increment", (Node *) $3, @1);
    5115                 :             :                 }
    5116                 :             :             | LOGGED
    5117                 :             :                 {
    5118                 :           1 :                     $$ = makeDefElem("logged", NULL, @1);
    5119                 :             :                 }
    5120                 :             :             | MAXVALUE NumericOnly
    5121                 :             :                 {
    5122                 :          43 :                     $$ = makeDefElem("maxvalue", (Node *) $2, @1);
    5123                 :             :                 }
    5124                 :             :             | MINVALUE NumericOnly
    5125                 :             :                 {
    5126                 :          43 :                     $$ = makeDefElem("minvalue", (Node *) $2, @1);
    5127                 :             :                 }
    5128                 :             :             | NO MAXVALUE
    5129                 :             :                 {
    5130                 :          54 :                     $$ = makeDefElem("maxvalue", NULL, @1);
    5131                 :             :                 }
    5132                 :             :             | NO MINVALUE
    5133                 :             :                 {
    5134                 :          54 :                     $$ = makeDefElem("minvalue", NULL, @1);
    5135                 :             :                 }
    5136                 :             :             | OWNED BY any_name
    5137                 :             :                 {
    5138                 :          43 :                     $$ = makeDefElem("owned_by", (Node *) $3, @1);
    5139                 :             :                 }
    5140                 :             :             | SEQUENCE NAME_P any_name
    5141                 :             :                 {
    5142                 :          22 :                     $$ = makeDefElem("sequence_name", (Node *) $3, @1);
    5143                 :             :                 }
    5144                 :             :             | START opt_with NumericOnly
    5145                 :             :                 {
    5146                 :         137 :                     $$ = makeDefElem("start", (Node *) $3, @1);
    5147                 :             :                 }
    5148                 :             :             | RESTART
    5149                 :             :                 {
    5150                 :           4 :                     $$ = makeDefElem("restart", NULL, @1);
    5151                 :             :                 }
    5152                 :             :             | RESTART opt_with NumericOnly
    5153                 :             :                 {
    5154                 :          47 :                     $$ = makeDefElem("restart", (Node *) $3, @1);
    5155                 :             :                 }
    5156                 :             :             | UNLOGGED
    5157                 :             :                 {
    5158                 :           1 :                     $$ = makeDefElem("unlogged", NULL, @1);
    5159                 :             :                 }
    5160                 :             :         ;
    5161                 :             : 
    5162                 :             : opt_by:     BY
    5163                 :             :             | /* EMPTY */
    5164                 :             :       ;
    5165                 :             : 
    5166                 :             : NumericOnly:
    5167                 :         207 :             FCONST                              { $$ = (Node *) makeFloat($1); }
    5168                 :           0 :             | '+' FCONST                        { $$ = (Node *) makeFloat($2); }
    5169                 :             :             | '-' FCONST
    5170                 :             :                 {
    5171                 :          13 :                     Float      *f = makeFloat($2);
    5172                 :             : 
    5173                 :          13 :                     doNegateFloat(f);
    5174                 :          13 :                     $$ = (Node *) f;
    5175                 :             :                 }
    5176                 :        7198 :             | SignedIconst                      { $$ = (Node *) makeInteger($1); }
    5177                 :             :         ;
    5178                 :             : 
    5179                 :          62 : NumericOnly_list:   NumericOnly                     { $$ = list_make1($1); }
    5180                 :           4 :                 | NumericOnly_list ',' NumericOnly  { $$ = lappend($1, $3); }
    5181                 :             :         ;
    5182                 :             : 
    5183                 :             : /*****************************************************************************
    5184                 :             :  *
    5185                 :             :  *      QUERIES :
    5186                 :             :  *              CREATE [OR REPLACE] [TRUSTED] [PROCEDURAL] LANGUAGE ...
    5187                 :             :  *              DROP [PROCEDURAL] LANGUAGE ...
    5188                 :             :  *
    5189                 :             :  *****************************************************************************/
    5190                 :             : 
    5191                 :             : CreatePLangStmt:
    5192                 :             :             CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5193                 :             :             {
    5194                 :             :                 /*
    5195                 :             :                  * We now interpret parameterless CREATE LANGUAGE as
    5196                 :             :                  * CREATE EXTENSION.  "OR REPLACE" is silently translated
    5197                 :             :                  * to "IF NOT EXISTS", which isn't quite the same, but
    5198                 :             :                  * seems more useful than throwing an error.  We just
    5199                 :             :                  * ignore TRUSTED, as the previous code would have too.
    5200                 :             :                  */
    5201                 :           0 :                 CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5202                 :             : 
    5203                 :           0 :                 n->if_not_exists = $2;
    5204                 :           0 :                 n->extname = $6;
    5205                 :           0 :                 n->options = NIL;
    5206                 :           0 :                 $$ = (Node *) n;
    5207                 :             :             }
    5208                 :             :             | CREATE opt_or_replace opt_trusted opt_procedural LANGUAGE name
    5209                 :             :               HANDLER handler_name opt_inline_handler opt_validator
    5210                 :             :             {
    5211                 :          82 :                 CreatePLangStmt *n = makeNode(CreatePLangStmt);
    5212                 :             : 
    5213                 :          82 :                 n->replace = $2;
    5214                 :          82 :                 n->plname = $6;
    5215                 :          82 :                 n->plhandler = $8;
    5216                 :          82 :                 n->plinline = $9;
    5217                 :          82 :                 n->plvalidator = $10;
    5218                 :          82 :                 n->pltrusted = $3;
    5219                 :          82 :                 $$ = (Node *) n;
    5220                 :             :             }
    5221                 :             :         ;
    5222                 :             : 
    5223                 :             : opt_trusted:
    5224                 :          65 :             TRUSTED                                 { $$ = true; }
    5225                 :          22 :             | /*EMPTY*/                             { $$ = false; }
    5226                 :             :         ;
    5227                 :             : 
    5228                 :             : /* This ought to be just func_name, but that causes reduce/reduce conflicts
    5229                 :             :  * (CREATE LANGUAGE is the only place where func_name isn't followed by '(').
    5230                 :             :  * Work around by using simple names, instead.
    5231                 :             :  */
    5232                 :             : handler_name:
    5233                 :         353 :             name                        { $$ = list_make1(makeString($1)); }
    5234                 :           1 :             | name attrs                { $$ = lcons(makeString($1), $2); }
    5235                 :             :         ;
    5236                 :             : 
    5237                 :             : opt_inline_handler:
    5238                 :          71 :             INLINE_P handler_name                   { $$ = $2; }
    5239                 :          11 :             | /*EMPTY*/                             { $$ = NIL; }
    5240                 :             :         ;
    5241                 :             : 
    5242                 :             : validator_clause:
    5243                 :          71 :             VALIDATOR handler_name                  { $$ = $2; }
    5244                 :           0 :             | NO VALIDATOR                          { $$ = NIL; }
    5245                 :             :         ;
    5246                 :             : 
    5247                 :             : opt_validator:
    5248                 :          71 :             validator_clause                        { $$ = $1; }
    5249                 :          11 :             | /*EMPTY*/                             { $$ = NIL; }
    5250                 :             :         ;
    5251                 :             : 
    5252                 :             : opt_procedural:
    5253                 :             :             PROCEDURAL
    5254                 :             :             | /*EMPTY*/
    5255                 :             :         ;
    5256                 :             : 
    5257                 :             : /*****************************************************************************
    5258                 :             :  *
    5259                 :             :  *      QUERY:
    5260                 :             :  *             CREATE TABLESPACE tablespace LOCATION '/path/to/tablespace/'
    5261                 :             :  *
    5262                 :             :  *****************************************************************************/
    5263                 :             : 
    5264                 :             : CreateTableSpaceStmt: CREATE TABLESPACE name OptTableSpaceOwner LOCATION Sconst opt_reloptions
    5265                 :             :                 {
    5266                 :          82 :                     CreateTableSpaceStmt *n = makeNode(CreateTableSpaceStmt);
    5267                 :             : 
    5268                 :          82 :                     n->tablespacename = $3;
    5269                 :          82 :                     n->owner = $4;
    5270                 :          82 :                     n->location = $6;
    5271                 :          82 :                     n->options = $7;
    5272                 :          82 :                     $$ = (Node *) n;
    5273                 :             :                 }
    5274                 :             :         ;
    5275                 :             : 
    5276                 :          12 : OptTableSpaceOwner: OWNER RoleSpec      { $$ = $2; }
    5277                 :          70 :             | /*EMPTY */                { $$ = NULL; }
    5278                 :             :         ;
    5279                 :             : 
    5280                 :             : /*****************************************************************************
    5281                 :             :  *
    5282                 :             :  *      QUERY :
    5283                 :             :  *              DROP TABLESPACE <tablespace>
    5284                 :             :  *
    5285                 :             :  *      No need for drop behaviour as we cannot implement dependencies for
    5286                 :             :  *      objects in other databases; we can only support RESTRICT.
    5287                 :             :  *
    5288                 :             :  ****************************************************************************/
    5289                 :             : 
    5290                 :             : DropTableSpaceStmt: DROP TABLESPACE name
    5291                 :             :                 {
    5292                 :          43 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5293                 :             : 
    5294                 :          43 :                     n->tablespacename = $3;
    5295                 :          43 :                     n->missing_ok = false;
    5296                 :          43 :                     $$ = (Node *) n;
    5297                 :             :                 }
    5298                 :             :                 |  DROP TABLESPACE IF_P EXISTS name
    5299                 :             :                 {
    5300                 :           6 :                     DropTableSpaceStmt *n = makeNode(DropTableSpaceStmt);
    5301                 :             : 
    5302                 :           6 :                     n->tablespacename = $5;
    5303                 :           6 :                     n->missing_ok = true;
    5304                 :           6 :                     $$ = (Node *) n;
    5305                 :             :                 }
    5306                 :             :         ;
    5307                 :             : 
    5308                 :             : /*****************************************************************************
    5309                 :             :  *
    5310                 :             :  *      QUERY:
    5311                 :             :  *             CREATE EXTENSION extension
    5312                 :             :  *             [ WITH ] [ SCHEMA schema ] [ VERSION version ]
    5313                 :             :  *
    5314                 :             :  *****************************************************************************/
    5315                 :             : 
    5316                 :             : CreateExtensionStmt: CREATE EXTENSION name opt_with create_extension_opt_list
    5317                 :             :                 {
    5318                 :         338 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5319                 :             : 
    5320                 :         338 :                     n->extname = $3;
    5321                 :         338 :                     n->if_not_exists = false;
    5322                 :         338 :                     n->options = $5;
    5323                 :         338 :                     $$ = (Node *) n;
    5324                 :             :                 }
    5325                 :             :                 | CREATE EXTENSION IF_P NOT EXISTS name opt_with create_extension_opt_list
    5326                 :             :                 {
    5327                 :          18 :                     CreateExtensionStmt *n = makeNode(CreateExtensionStmt);
    5328                 :             : 
    5329                 :          18 :                     n->extname = $6;
    5330                 :          18 :                     n->if_not_exists = true;
    5331                 :          18 :                     n->options = $8;
    5332                 :          18 :                     $$ = (Node *) n;
    5333                 :             :                 }
    5334                 :             :         ;
    5335                 :             : 
    5336                 :             : create_extension_opt_list:
    5337                 :             :             create_extension_opt_list create_extension_opt_item
    5338                 :          49 :                 { $$ = lappend($1, $2); }
    5339                 :             :             | /* EMPTY */
    5340                 :         356 :                 { $$ = NIL; }
    5341                 :             :         ;
    5342                 :             : 
    5343                 :             : create_extension_opt_item:
    5344                 :             :             SCHEMA name
    5345                 :             :                 {
    5346                 :          23 :                     $$ = makeDefElem("schema", (Node *) makeString($2), @1);
    5347                 :             :                 }
    5348                 :             :             | VERSION_P NonReservedWord_or_Sconst
    5349                 :             :                 {
    5350                 :           6 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5351                 :             :                 }
    5352                 :             :             | FROM NonReservedWord_or_Sconst
    5353                 :             :                 {
    5354         [ #  # ]:           0 :                     ereport(ERROR,
    5355                 :             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    5356                 :             :                              errmsg("CREATE EXTENSION ... FROM is no longer supported"),
    5357                 :             :                              parser_errposition(@1)));
    5358                 :             :                 }
    5359                 :             :             | CASCADE
    5360                 :             :                 {
    5361                 :          20 :                     $$ = makeDefElem("cascade", (Node *) makeBoolean(true), @1);
    5362                 :             :                 }
    5363                 :             :         ;
    5364                 :             : 
    5365                 :             : /*****************************************************************************
    5366                 :             :  *
    5367                 :             :  * ALTER EXTENSION name UPDATE [ TO version ]
    5368                 :             :  *
    5369                 :             :  *****************************************************************************/
    5370                 :             : 
    5371                 :             : AlterExtensionStmt: ALTER EXTENSION name UPDATE alter_extension_opt_list
    5372                 :             :                 {
    5373                 :          20 :                     AlterExtensionStmt *n = makeNode(AlterExtensionStmt);
    5374                 :             : 
    5375                 :          20 :                     n->extname = $3;
    5376                 :          20 :                     n->options = $5;
    5377                 :          20 :                     $$ = (Node *) n;
    5378                 :             :                 }
    5379                 :             :         ;
    5380                 :             : 
    5381                 :             : alter_extension_opt_list:
    5382                 :             :             alter_extension_opt_list alter_extension_opt_item
    5383                 :          20 :                 { $$ = lappend($1, $2); }
    5384                 :             :             | /* EMPTY */
    5385                 :          20 :                 { $$ = NIL; }
    5386                 :             :         ;
    5387                 :             : 
    5388                 :             : alter_extension_opt_item:
    5389                 :             :             TO NonReservedWord_or_Sconst
    5390                 :             :                 {
    5391                 :          20 :                     $$ = makeDefElem("new_version", (Node *) makeString($2), @1);
    5392                 :             :                 }
    5393                 :             :         ;
    5394                 :             : 
    5395                 :             : /*****************************************************************************
    5396                 :             :  *
    5397                 :             :  * ALTER EXTENSION name ADD/DROP object-identifier
    5398                 :             :  *
    5399                 :             :  *****************************************************************************/
    5400                 :             : 
    5401                 :             : AlterExtensionContentsStmt:
    5402                 :             :             ALTER EXTENSION name add_drop object_type_name name
    5403                 :             :                 {
    5404                 :           9 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5405                 :             : 
    5406                 :           9 :                     n->extname = $3;
    5407                 :           9 :                     n->action = $4;
    5408                 :           9 :                     n->objtype = $5;
    5409                 :           9 :                     n->object = (Node *) makeString($6);
    5410                 :           9 :                     $$ = (Node *) n;
    5411                 :             :                 }
    5412                 :             :             | ALTER EXTENSION name add_drop object_type_any_name any_name
    5413                 :             :                 {
    5414                 :          39 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5415                 :             : 
    5416                 :          39 :                     n->extname = $3;
    5417                 :          39 :                     n->action = $4;
    5418                 :          39 :                     n->objtype = $5;
    5419                 :          39 :                     n->object = (Node *) $6;
    5420                 :          39 :                     $$ = (Node *) n;
    5421                 :             :                 }
    5422                 :             :             | ALTER EXTENSION name add_drop AGGREGATE aggregate_with_argtypes
    5423                 :             :                 {
    5424                 :           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5425                 :             : 
    5426                 :           4 :                     n->extname = $3;
    5427                 :           4 :                     n->action = $4;
    5428                 :           4 :                     n->objtype = OBJECT_AGGREGATE;
    5429                 :           4 :                     n->object = (Node *) $6;
    5430                 :           4 :                     $$ = (Node *) n;
    5431                 :             :                 }
    5432                 :             :             | ALTER EXTENSION name add_drop CAST '(' Typename AS Typename ')'
    5433                 :             :                 {
    5434                 :           2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5435                 :             : 
    5436                 :           2 :                     n->extname = $3;
    5437                 :           2 :                     n->action = $4;
    5438                 :           2 :                     n->objtype = OBJECT_CAST;
    5439                 :           2 :                     n->object = (Node *) list_make2($7, $9);
    5440                 :           2 :                     $$ = (Node *) n;
    5441                 :             :                 }
    5442                 :             :             | ALTER EXTENSION name add_drop DOMAIN_P Typename
    5443                 :             :                 {
    5444                 :           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5445                 :             : 
    5446                 :           0 :                     n->extname = $3;
    5447                 :           0 :                     n->action = $4;
    5448                 :           0 :                     n->objtype = OBJECT_DOMAIN;
    5449                 :           0 :                     n->object = (Node *) $6;
    5450                 :           0 :                     $$ = (Node *) n;
    5451                 :             :                 }
    5452                 :             :             | ALTER EXTENSION name add_drop FUNCTION function_with_argtypes
    5453                 :             :                 {
    5454                 :          62 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5455                 :             : 
    5456                 :          62 :                     n->extname = $3;
    5457                 :          62 :                     n->action = $4;
    5458                 :          62 :                     n->objtype = OBJECT_FUNCTION;
    5459                 :          62 :                     n->object = (Node *) $6;
    5460                 :          62 :                     $$ = (Node *) n;
    5461                 :             :                 }
    5462                 :             :             | ALTER EXTENSION name add_drop OPERATOR operator_with_argtypes
    5463                 :             :                 {
    5464                 :           9 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5465                 :             : 
    5466                 :           9 :                     n->extname = $3;
    5467                 :           9 :                     n->action = $4;
    5468                 :           9 :                     n->objtype = OBJECT_OPERATOR;
    5469                 :           9 :                     n->object = (Node *) $6;
    5470                 :           9 :                     $$ = (Node *) n;
    5471                 :             :                 }
    5472                 :             :             | ALTER EXTENSION name add_drop OPERATOR CLASS any_name USING name
    5473                 :             :                 {
    5474                 :           2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5475                 :             : 
    5476                 :           2 :                     n->extname = $3;
    5477                 :           2 :                     n->action = $4;
    5478                 :           2 :                     n->objtype = OBJECT_OPCLASS;
    5479                 :           2 :                     n->object = (Node *) lcons(makeString($9), $7);
    5480                 :           2 :                     $$ = (Node *) n;
    5481                 :             :                 }
    5482                 :             :             | ALTER EXTENSION name add_drop OPERATOR FAMILY any_name USING name
    5483                 :             :                 {
    5484                 :           2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5485                 :             : 
    5486                 :           2 :                     n->extname = $3;
    5487                 :           2 :                     n->action = $4;
    5488                 :           2 :                     n->objtype = OBJECT_OPFAMILY;
    5489                 :           2 :                     n->object = (Node *) lcons(makeString($9), $7);
    5490                 :           2 :                     $$ = (Node *) n;
    5491                 :             :                 }
    5492                 :             :             | ALTER EXTENSION name add_drop PROCEDURE function_with_argtypes
    5493                 :             :                 {
    5494                 :           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5495                 :             : 
    5496                 :           0 :                     n->extname = $3;
    5497                 :           0 :                     n->action = $4;
    5498                 :           0 :                     n->objtype = OBJECT_PROCEDURE;
    5499                 :           0 :                     n->object = (Node *) $6;
    5500                 :           0 :                     $$ = (Node *) n;
    5501                 :             :                 }
    5502                 :             :             | ALTER EXTENSION name add_drop ROUTINE function_with_argtypes
    5503                 :             :                 {
    5504                 :           0 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5505                 :             : 
    5506                 :           0 :                     n->extname = $3;
    5507                 :           0 :                     n->action = $4;
    5508                 :           0 :                     n->objtype = OBJECT_ROUTINE;
    5509                 :           0 :                     n->object = (Node *) $6;
    5510                 :           0 :                     $$ = (Node *) n;
    5511                 :             :                 }
    5512                 :             :             | ALTER EXTENSION name add_drop TRANSFORM FOR Typename LANGUAGE name
    5513                 :             :                 {
    5514                 :           2 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5515                 :             : 
    5516                 :           2 :                     n->extname = $3;
    5517                 :           2 :                     n->action = $4;
    5518                 :           2 :                     n->objtype = OBJECT_TRANSFORM;
    5519                 :           2 :                     n->object = (Node *) list_make2($7, makeString($9));
    5520                 :           2 :                     $$ = (Node *) n;
    5521                 :             :                 }
    5522                 :             :             | ALTER EXTENSION name add_drop TYPE_P Typename
    5523                 :             :                 {
    5524                 :           4 :                     AlterExtensionContentsStmt *n = makeNode(AlterExtensionContentsStmt);
    5525                 :             : 
    5526                 :           4 :                     n->extname = $3;
    5527                 :           4 :                     n->action = $4;
    5528                 :           4 :                     n->objtype = OBJECT_TYPE;
    5529                 :           4 :                     n->object = (Node *) $6;
    5530                 :           4 :                     $$ = (Node *) n;
    5531                 :             :                 }
    5532                 :             :         ;
    5533                 :             : 
    5534                 :             : /*****************************************************************************
    5535                 :             :  *
    5536                 :             :  *      QUERY:
    5537                 :             :  *             CREATE FOREIGN DATA WRAPPER name options
    5538                 :             :  *
    5539                 :             :  *****************************************************************************/
    5540                 :             : 
    5541                 :             : CreateFdwStmt: CREATE FOREIGN DATA_P WRAPPER name opt_fdw_options create_generic_options
    5542                 :             :                 {
    5543                 :         154 :                     CreateFdwStmt *n = makeNode(CreateFdwStmt);
    5544                 :             : 
    5545                 :         154 :                     n->fdwname = $5;
    5546                 :         154 :                     n->func_options = $6;
    5547                 :         154 :                     n->options = $7;
    5548                 :         154 :                     $$ = (Node *) n;
    5549                 :             :                 }
    5550                 :             :         ;
    5551                 :             : 
    5552                 :             : fdw_option:
    5553                 :          40 :             HANDLER handler_name                { $$ = makeDefElem("handler", (Node *) $2, @1); }
    5554                 :           0 :             | NO HANDLER                        { $$ = makeDefElem("handler", NULL, @1); }
    5555                 :          38 :             | VALIDATOR handler_name            { $$ = makeDefElem("validator", (Node *) $2, @1); }
    5556                 :           4 :             | NO VALIDATOR                      { $$ = makeDefElem("validator", NULL, @1); }
    5557                 :          14 :             | CONNECTION handler_name           { $$ = makeDefElem("connection", (Node *) $2, @1); }
    5558                 :           4 :             | NO CONNECTION                     { $$ = makeDefElem("connection", NULL, @1); }
    5559                 :             :         ;
    5560                 :             : 
    5561                 :             : fdw_options:
    5562                 :          84 :             fdw_option                          { $$ = list_make1($1); }
    5563                 :          16 :             | fdw_options fdw_option            { $$ = lappend($1, $2); }
    5564                 :             :         ;
    5565                 :             : 
    5566                 :             : opt_fdw_options:
    5567                 :          38 :             fdw_options                         { $$ = $1; }
    5568                 :         177 :             | /*EMPTY*/                         { $$ = NIL; }
    5569                 :             :         ;
    5570                 :             : 
    5571                 :             : /*****************************************************************************
    5572                 :             :  *
    5573                 :             :  *      QUERY :
    5574                 :             :  *              ALTER FOREIGN DATA WRAPPER name options
    5575                 :             :  *
    5576                 :             :  ****************************************************************************/
    5577                 :             : 
    5578                 :             : AlterFdwStmt: ALTER FOREIGN DATA_P WRAPPER name opt_fdw_options alter_generic_options
    5579                 :             :                 {
    5580                 :          57 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5581                 :             : 
    5582                 :          57 :                     n->fdwname = $5;
    5583                 :          57 :                     n->func_options = $6;
    5584                 :          57 :                     n->options = $7;
    5585                 :          57 :                     $$ = (Node *) n;
    5586                 :             :                 }
    5587                 :             :             | ALTER FOREIGN DATA_P WRAPPER name fdw_options
    5588                 :             :                 {
    5589                 :          46 :                     AlterFdwStmt *n = makeNode(AlterFdwStmt);
    5590                 :             : 
    5591                 :          46 :                     n->fdwname = $5;
    5592                 :          46 :                     n->func_options = $6;
    5593                 :          46 :                     n->options = NIL;
    5594                 :          46 :                     $$ = (Node *) n;
    5595                 :             :                 }
    5596                 :             :         ;
    5597                 :             : 
    5598                 :             : /* Options definition for CREATE FDW, SERVER and USER MAPPING */
    5599                 :             : create_generic_options:
    5600                 :         457 :             OPTIONS '(' generic_option_list ')'         { $$ = $3; }
    5601                 :       44454 :             | /*EMPTY*/                                 { $$ = NIL; }
    5602                 :             :         ;
    5603                 :             : 
    5604                 :             : generic_option_list:
    5605                 :             :             generic_option_elem
    5606                 :             :                 {
    5607                 :         457 :                     $$ = list_make1($1);
    5608                 :             :                 }
    5609                 :             :             | generic_option_list ',' generic_option_elem
    5610                 :             :                 {
    5611                 :         306 :                     $$ = lappend($1, $3);
    5612                 :             :                 }
    5613                 :             :         ;
    5614                 :             : 
    5615                 :             : /* Options definition for ALTER FDW, SERVER and USER MAPPING */
    5616                 :             : alter_generic_options:
    5617                 :         302 :             OPTIONS '(' alter_generic_option_list ')'       { $$ = $3; }
    5618                 :             :         ;
    5619                 :             : 
    5620                 :             : alter_generic_option_list:
    5621                 :             :             alter_generic_option_elem
    5622                 :             :                 {
    5623                 :         302 :                     $$ = list_make1($1);
    5624                 :             :                 }
    5625                 :             :             | alter_generic_option_list ',' alter_generic_option_elem
    5626                 :             :                 {
    5627                 :         103 :                     $$ = lappend($1, $3);
    5628                 :             :                 }
    5629                 :             :         ;
    5630                 :             : 
    5631                 :             : alter_generic_option_elem:
    5632                 :             :             generic_option_elem
    5633                 :             :                 {
    5634                 :         119 :                     $$ = $1;
    5635                 :             :                 }
    5636                 :             :             | SET generic_option_elem
    5637                 :             :                 {
    5638                 :          73 :                     $$ = $2;
    5639                 :          73 :                     $$->defaction = DEFELEM_SET;
    5640                 :             :                 }
    5641                 :             :             | ADD_P generic_option_elem
    5642                 :             :                 {
    5643                 :         136 :                     $$ = $2;
    5644                 :         136 :                     $$->defaction = DEFELEM_ADD;
    5645                 :             :                 }
    5646                 :             :             | DROP generic_option_name
    5647                 :             :                 {
    5648                 :          77 :                     $$ = makeDefElemExtended(NULL, $2, NULL, DEFELEM_DROP, @2);
    5649                 :             :                 }
    5650                 :             :         ;
    5651                 :             : 
    5652                 :             : generic_option_elem:
    5653                 :             :             generic_option_name generic_option_arg
    5654                 :             :                 {
    5655                 :        1091 :                     $$ = makeDefElem($1, $2, @1);
    5656                 :             :                 }
    5657                 :             :         ;
    5658                 :             : 
    5659                 :             : generic_option_name:
    5660                 :        1168 :                 ColLabel            { $$ = $1; }
    5661                 :             :         ;
    5662                 :             : 
    5663                 :             : /* We could use def_arg here, but the spec only requires string literals */
    5664                 :             : generic_option_arg:
    5665                 :        1091 :                 Sconst              { $$ = (Node *) makeString($1); }
    5666                 :             :         ;
    5667                 :             : 
    5668                 :             : /*****************************************************************************
    5669                 :             :  *
    5670                 :             :  *      QUERY:
    5671                 :             :  *             CREATE SERVER name [TYPE] [VERSION] [OPTIONS]
    5672                 :             :  *
    5673                 :             :  *****************************************************************************/
    5674                 :             : 
    5675                 :             : CreateForeignServerStmt: CREATE SERVER name opt_type opt_foreign_server_version
    5676                 :             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5677                 :             :                 {
    5678                 :         183 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5679                 :             : 
    5680                 :         183 :                     n->servername = $3;
    5681                 :         183 :                     n->servertype = $4;
    5682                 :         183 :                     n->version = $5;
    5683                 :         183 :                     n->fdwname = $9;
    5684                 :         183 :                     n->options = $10;
    5685                 :         183 :                     n->if_not_exists = false;
    5686                 :         183 :                     $$ = (Node *) n;
    5687                 :             :                 }
    5688                 :             :                 | CREATE SERVER IF_P NOT EXISTS name opt_type opt_foreign_server_version
    5689                 :             :                          FOREIGN DATA_P WRAPPER name create_generic_options
    5690                 :             :                 {
    5691                 :          13 :                     CreateForeignServerStmt *n = makeNode(CreateForeignServerStmt);
    5692                 :             : 
    5693                 :          13 :                     n->servername = $6;
    5694                 :          13 :                     n->servertype = $7;
    5695                 :          13 :                     n->version = $8;
    5696                 :          13 :                     n->fdwname = $12;
    5697                 :          13 :                     n->options = $13;
    5698                 :          13 :                     n->if_not_exists = true;
    5699                 :          13 :                     $$ = (Node *) n;
    5700                 :             :                 }
    5701                 :             :         ;
    5702                 :             : 
    5703                 :             : opt_type:
    5704                 :          12 :             TYPE_P Sconst           { $$ = $2; }
    5705                 :         184 :             | /*EMPTY*/             { $$ = NULL; }
    5706                 :             :         ;
    5707                 :             : 
    5708                 :             : 
    5709                 :             : foreign_server_version:
    5710                 :          44 :             VERSION_P Sconst        { $$ = $2; }
    5711                 :           0 :         |   VERSION_P NULL_P        { $$ = NULL; }
    5712                 :             :         ;
    5713                 :             : 
    5714                 :             : opt_foreign_server_version:
    5715                 :          12 :             foreign_server_version  { $$ = $1; }
    5716                 :         184 :             | /*EMPTY*/             { $$ = NULL; }
    5717                 :             :         ;
    5718                 :             : 
    5719                 :             : /*****************************************************************************
    5720                 :             :  *
    5721                 :             :  *      QUERY :
    5722                 :             :  *              ALTER SERVER name [VERSION] [OPTIONS]
    5723                 :             :  *
    5724                 :             :  ****************************************************************************/
    5725                 :             : 
    5726                 :             : AlterForeignServerStmt: ALTER SERVER name foreign_server_version alter_generic_options
    5727                 :             :                 {
    5728                 :           4 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5729                 :             : 
    5730                 :           4 :                     n->servername = $3;
    5731                 :           4 :                     n->version = $4;
    5732                 :           4 :                     n->options = $5;
    5733                 :           4 :                     n->has_version = true;
    5734                 :           4 :                     $$ = (Node *) n;
    5735                 :             :                 }
    5736                 :             :             | ALTER SERVER name foreign_server_version
    5737                 :             :                 {
    5738                 :          28 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5739                 :             : 
    5740                 :          28 :                     n->servername = $3;
    5741                 :          28 :                     n->version = $4;
    5742                 :          28 :                     n->has_version = true;
    5743                 :          28 :                     $$ = (Node *) n;
    5744                 :             :                 }
    5745                 :             :             | ALTER SERVER name alter_generic_options
    5746                 :             :                 {
    5747                 :          97 :                     AlterForeignServerStmt *n = makeNode(AlterForeignServerStmt);
    5748                 :             : 
    5749                 :          97 :                     n->servername = $3;
    5750                 :          97 :                     n->options = $4;
    5751                 :          97 :                     $$ = (Node *) n;
    5752                 :             :                 }
    5753                 :             :         ;
    5754                 :             : 
    5755                 :             : /*****************************************************************************
    5756                 :             :  *
    5757                 :             :  *      QUERY:
    5758                 :             :  *             CREATE FOREIGN TABLE relname (...) SERVER name (...)
    5759                 :             :  *
    5760                 :             :  *****************************************************************************/
    5761                 :             : 
    5762                 :             : CreateForeignTableStmt:
    5763                 :             :         CREATE FOREIGN TABLE qualified_name
    5764                 :             :             '(' OptTableElementList ')'
    5765                 :             :             OptInherit SERVER name create_generic_options
    5766                 :             :                 {
    5767                 :         251 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5768                 :             : 
    5769                 :         251 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5770                 :         251 :                     n->base.relation = $4;
    5771                 :         251 :                     n->base.tableElts = $6;
    5772                 :         251 :                     n->base.inhRelations = $8;
    5773                 :         251 :                     n->base.ofTypename = NULL;
    5774                 :         251 :                     n->base.constraints = NIL;
    5775                 :         251 :                     n->base.options = NIL;
    5776                 :         251 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5777                 :         251 :                     n->base.tablespacename = NULL;
    5778                 :         251 :                     n->base.if_not_exists = false;
    5779                 :             :                     /* FDW-specific data */
    5780                 :         251 :                     n->servername = $10;
    5781                 :         251 :                     n->options = $11;
    5782                 :         251 :                     $$ = (Node *) n;
    5783                 :             :                 }
    5784                 :             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5785                 :             :             '(' OptTableElementList ')'
    5786                 :             :             OptInherit SERVER name create_generic_options
    5787                 :             :                 {
    5788                 :           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5789                 :             : 
    5790                 :           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5791                 :           0 :                     n->base.relation = $7;
    5792                 :           0 :                     n->base.tableElts = $9;
    5793                 :           0 :                     n->base.inhRelations = $11;
    5794                 :           0 :                     n->base.ofTypename = NULL;
    5795                 :           0 :                     n->base.constraints = NIL;
    5796                 :           0 :                     n->base.options = NIL;
    5797                 :           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5798                 :           0 :                     n->base.tablespacename = NULL;
    5799                 :           0 :                     n->base.if_not_exists = true;
    5800                 :             :                     /* FDW-specific data */
    5801                 :           0 :                     n->servername = $13;
    5802                 :           0 :                     n->options = $14;
    5803                 :           0 :                     $$ = (Node *) n;
    5804                 :             :                 }
    5805                 :             :         | CREATE FOREIGN TABLE qualified_name
    5806                 :             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5807                 :             :             SERVER name create_generic_options
    5808                 :             :                 {
    5809                 :          54 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5810                 :             : 
    5811                 :          54 :                     $4->relpersistence = RELPERSISTENCE_PERMANENT;
    5812                 :          54 :                     n->base.relation = $4;
    5813                 :          54 :                     n->base.inhRelations = list_make1($7);
    5814                 :          54 :                     n->base.tableElts = $8;
    5815                 :          54 :                     n->base.partbound = $9;
    5816                 :          54 :                     n->base.ofTypename = NULL;
    5817                 :          54 :                     n->base.constraints = NIL;
    5818                 :          54 :                     n->base.options = NIL;
    5819                 :          54 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5820                 :          54 :                     n->base.tablespacename = NULL;
    5821                 :          54 :                     n->base.if_not_exists = false;
    5822                 :             :                     /* FDW-specific data */
    5823                 :          54 :                     n->servername = $11;
    5824                 :          54 :                     n->options = $12;
    5825                 :          54 :                     $$ = (Node *) n;
    5826                 :             :                 }
    5827                 :             :         | CREATE FOREIGN TABLE IF_P NOT EXISTS qualified_name
    5828                 :             :             PARTITION OF qualified_name OptTypedTableElementList PartitionBoundSpec
    5829                 :             :             SERVER name create_generic_options
    5830                 :             :                 {
    5831                 :           0 :                     CreateForeignTableStmt *n = makeNode(CreateForeignTableStmt);
    5832                 :             : 
    5833                 :           0 :                     $7->relpersistence = RELPERSISTENCE_PERMANENT;
    5834                 :           0 :                     n->base.relation = $7;
    5835                 :           0 :                     n->base.inhRelations = list_make1($10);
    5836                 :           0 :                     n->base.tableElts = $11;
    5837                 :           0 :                     n->base.partbound = $12;
    5838                 :           0 :                     n->base.ofTypename = NULL;
    5839                 :           0 :                     n->base.constraints = NIL;
    5840                 :           0 :                     n->base.options = NIL;
    5841                 :           0 :                     n->base.oncommit = ONCOMMIT_NOOP;
    5842                 :           0 :                     n->base.tablespacename = NULL;
    5843                 :           0 :                     n->base.if_not_exists = true;
    5844                 :             :                     /* FDW-specific data */
    5845                 :           0 :                     n->servername = $14;
    5846                 :           0 :                     n->options = $15;
    5847                 :           0 :                     $$ = (Node *) n;
    5848                 :             :                 }
    5849                 :             :         ;
    5850                 :             : 
    5851                 :             : /*****************************************************************************
    5852                 :             :  *
    5853                 :             :  *      QUERY:
    5854                 :             :  *              IMPORT FOREIGN SCHEMA remote_schema
    5855                 :             :  *              [ { LIMIT TO | EXCEPT } ( table_list ) ]
    5856                 :             :  *              FROM SERVER server_name INTO local_schema [ OPTIONS (...) ]
    5857                 :             :  *
    5858                 :             :  ****************************************************************************/
    5859                 :             : 
    5860                 :             : ImportForeignSchemaStmt:
    5861                 :             :         IMPORT_P FOREIGN SCHEMA name import_qualification
    5862                 :             :           FROM SERVER name INTO name create_generic_options
    5863                 :             :             {
    5864                 :          28 :                 ImportForeignSchemaStmt *n = makeNode(ImportForeignSchemaStmt);
    5865                 :             : 
    5866                 :          28 :                 n->server_name = $8;
    5867                 :          28 :                 n->remote_schema = $4;
    5868                 :          28 :                 n->local_schema = $10;
    5869                 :          28 :                 n->list_type = $5->type;
    5870                 :          28 :                 n->table_list = $5->table_names;
    5871                 :          28 :                 n->options = $11;
    5872                 :          28 :                 $$ = (Node *) n;
    5873                 :             :             }
    5874                 :             :         ;
    5875                 :             : 
    5876                 :             : import_qualification_type:
    5877                 :           8 :         LIMIT TO                { $$ = FDW_IMPORT_SCHEMA_LIMIT_TO; }
    5878                 :           9 :         | EXCEPT                { $$ = FDW_IMPORT_SCHEMA_EXCEPT; }
    5879                 :             :         ;
    5880                 :             : 
    5881                 :             : import_qualification:
    5882                 :             :         import_qualification_type '(' relation_expr_list ')'
    5883                 :             :             {
    5884                 :          17 :                 ImportQual *n = palloc_object(ImportQual);
    5885                 :             : 
    5886                 :          17 :                 n->type = $1;
    5887                 :          17 :                 n->table_names = $3;
    5888                 :          17 :                 $$ = n;
    5889                 :             :             }
    5890                 :             :         | /*EMPTY*/
    5891                 :             :             {
    5892                 :          11 :                 ImportQual *n = palloc_object(ImportQual);
    5893                 :          11 :                 n->type = FDW_IMPORT_SCHEMA_ALL;
    5894                 :          11 :                 n->table_names = NIL;
    5895                 :          11 :                 $$ = n;
    5896                 :             :             }
    5897                 :             :         ;
    5898                 :             : 
    5899                 :             : /*****************************************************************************
    5900                 :             :  *
    5901                 :             :  *      QUERY:
    5902                 :             :  *             CREATE USER MAPPING FOR auth_ident SERVER name [OPTIONS]
    5903                 :             :  *
    5904                 :             :  *****************************************************************************/
    5905                 :             : 
    5906                 :             : CreateUserMappingStmt: CREATE USER MAPPING FOR auth_ident SERVER name create_generic_options
    5907                 :             :                 {
    5908                 :         163 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5909                 :             : 
    5910                 :         163 :                     n->user = $5;
    5911                 :         163 :                     n->servername = $7;
    5912                 :         163 :                     n->options = $8;
    5913                 :         163 :                     n->if_not_exists = false;
    5914                 :         163 :                     $$ = (Node *) n;
    5915                 :             :                 }
    5916                 :             :                 | CREATE USER MAPPING IF_P NOT EXISTS FOR auth_ident SERVER name create_generic_options
    5917                 :             :                 {
    5918                 :           4 :                     CreateUserMappingStmt *n = makeNode(CreateUserMappingStmt);
    5919                 :             : 
    5920                 :           4 :                     n->user = $8;
    5921                 :           4 :                     n->servername = $10;
    5922                 :           4 :                     n->options = $11;
    5923                 :           4 :                     n->if_not_exists = true;
    5924                 :           4 :                     $$ = (Node *) n;
    5925                 :             :                 }
    5926                 :             :         ;
    5927                 :             : 
    5928                 :             : /* User mapping authorization identifier */
    5929                 :         290 : auth_ident: RoleSpec            { $$ = $1; }
    5930                 :          29 :             | USER              { $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1); }
    5931                 :             :         ;
    5932                 :             : 
    5933                 :             : /*****************************************************************************
    5934                 :             :  *
    5935                 :             :  *      QUERY :
    5936                 :             :  *              DROP USER MAPPING FOR auth_ident SERVER name
    5937                 :             :  *
    5938                 :             :  * XXX you'd think this should have a CASCADE/RESTRICT option, even if it's
    5939                 :             :  * only pro forma; but the SQL standard doesn't show one.
    5940                 :             :  ****************************************************************************/
    5941                 :             : 
    5942                 :             : DropUserMappingStmt: DROP USER MAPPING FOR auth_ident SERVER name
    5943                 :             :                 {
    5944                 :          57 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5945                 :             : 
    5946                 :          57 :                     n->user = $5;
    5947                 :          57 :                     n->servername = $7;
    5948                 :          57 :                     n->missing_ok = false;
    5949                 :          57 :                     $$ = (Node *) n;
    5950                 :             :                 }
    5951                 :             :                 |  DROP USER MAPPING IF_P EXISTS FOR auth_ident SERVER name
    5952                 :             :                 {
    5953                 :          22 :                     DropUserMappingStmt *n = makeNode(DropUserMappingStmt);
    5954                 :             : 
    5955                 :          22 :                     n->user = $7;
    5956                 :          22 :                     n->servername = $9;
    5957                 :          22 :                     n->missing_ok = true;
    5958                 :          22 :                     $$ = (Node *) n;
    5959                 :             :                 }
    5960                 :             :         ;
    5961                 :             : 
    5962                 :             : /*****************************************************************************
    5963                 :             :  *
    5964                 :             :  *      QUERY :
    5965                 :             :  *              ALTER USER MAPPING FOR auth_ident SERVER name OPTIONS
    5966                 :             :  *
    5967                 :             :  ****************************************************************************/
    5968                 :             : 
    5969                 :             : AlterUserMappingStmt: ALTER USER MAPPING FOR auth_ident SERVER name alter_generic_options
    5970                 :             :                 {
    5971                 :          73 :                     AlterUserMappingStmt *n = makeNode(AlterUserMappingStmt);
    5972                 :             : 
    5973                 :          73 :                     n->user = $5;
    5974                 :          73 :                     n->servername = $7;
    5975                 :          73 :                     n->options = $8;
    5976                 :          73 :                     $$ = (Node *) n;
    5977                 :             :                 }
    5978                 :             :         ;
    5979                 :             : 
    5980                 :             : /*****************************************************************************
    5981                 :             :  *
    5982                 :             :  *      QUERIES:
    5983                 :             :  *              CREATE POLICY name ON table
    5984                 :             :  *                  [AS { PERMISSIVE | RESTRICTIVE } ]
    5985                 :             :  *                  [FOR { SELECT | INSERT | UPDATE | DELETE } ]
    5986                 :             :  *                  [TO role, ...]
    5987                 :             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5988                 :             :  *              ALTER POLICY name ON table [TO role, ...]
    5989                 :             :  *                  [USING (qual)] [WITH CHECK (with check qual)]
    5990                 :             :  *
    5991                 :             :  *****************************************************************************/
    5992                 :             : 
    5993                 :             : CreatePolicyStmt:
    5994                 :             :             CREATE POLICY name ON qualified_name RowSecurityDefaultPermissive
    5995                 :             :                 RowSecurityDefaultForCmd RowSecurityDefaultToRole
    5996                 :             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    5997                 :             :                 {
    5998                 :         539 :                     CreatePolicyStmt *n = makeNode(CreatePolicyStmt);
    5999                 :             : 
    6000                 :         539 :                     n->policy_name = $3;
    6001                 :         539 :                     n->table = $5;
    6002                 :         539 :                     n->permissive = $6;
    6003                 :         539 :                     n->cmd_name = $7;
    6004                 :         539 :                     n->roles = $8;
    6005                 :         539 :                     n->qual = $9;
    6006                 :         539 :                     n->with_check = $10;
    6007                 :         539 :                     $$ = (Node *) n;
    6008                 :             :                 }
    6009                 :             :         ;
    6010                 :             : 
    6011                 :             : AlterPolicyStmt:
    6012                 :             :             ALTER POLICY name ON qualified_name RowSecurityOptionalToRole
    6013                 :             :                 RowSecurityOptionalExpr RowSecurityOptionalWithCheck
    6014                 :             :                 {
    6015                 :          56 :                     AlterPolicyStmt *n = makeNode(AlterPolicyStmt);
    6016                 :             : 
    6017                 :          56 :                     n->policy_name = $3;
    6018                 :          56 :                     n->table = $5;
    6019                 :          56 :                     n->roles = $6;
    6020                 :          56 :                     n->qual = $7;
    6021                 :          56 :                     n->with_check = $8;
    6022                 :          56 :                     $$ = (Node *) n;
    6023                 :             :                 }
    6024                 :             :         ;
    6025                 :             : 
    6026                 :             : RowSecurityOptionalExpr:
    6027                 :         549 :             USING '(' a_expr ')'    { $$ = $3; }
    6028                 :          46 :             | /* EMPTY */           { $$ = NULL; }
    6029                 :             :         ;
    6030                 :             : 
    6031                 :             : RowSecurityOptionalWithCheck:
    6032                 :         103 :             WITH CHECK '(' a_expr ')'       { $$ = $4; }
    6033                 :         492 :             | /* EMPTY */                   { $$ = NULL; }
    6034                 :             :         ;
    6035                 :             : 
    6036                 :             : RowSecurityDefaultToRole:
    6037                 :          89 :             TO role_list            { $$ = $2; }
    6038                 :         450 :             | /* EMPTY */           { $$ = list_make1(makeRoleSpec(ROLESPEC_PUBLIC, -1)); }
    6039                 :             :         ;
    6040                 :             : 
    6041                 :             : RowSecurityOptionalToRole:
    6042                 :           8 :             TO role_list            { $$ = $2; }
    6043                 :          48 :             | /* EMPTY */           { $$ = NULL; }
    6044                 :             :         ;
    6045                 :             : 
    6046                 :             : RowSecurityDefaultPermissive:
    6047                 :             :             AS IDENT
    6048                 :             :                 {
    6049         [ +  + ]:          65 :                     if (strcmp($2, "permissive") == 0)
    6050                 :          16 :                         $$ = true;
    6051         [ +  + ]:          49 :                     else if (strcmp($2, "restrictive") == 0)
    6052                 :          45 :                         $$ = false;
    6053                 :             :                     else
    6054         [ +  - ]:           4 :                         ereport(ERROR,
    6055                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6056                 :             :                                  errmsg("unrecognized row security option \"%s\"", $2),
    6057                 :             :                                  errhint("Only PERMISSIVE or RESTRICTIVE policies are supported currently."),
    6058                 :             :                                  parser_errposition(@2)));
    6059                 :             : 
    6060                 :             :                 }
    6061                 :         478 :             | /* EMPTY */           { $$ = true; }
    6062                 :             :         ;
    6063                 :             : 
    6064                 :             : RowSecurityDefaultForCmd:
    6065                 :         249 :             FOR row_security_cmd    { $$ = $2; }
    6066                 :         290 :             | /* EMPTY */           { $$ = "all"; }
    6067                 :             :         ;
    6068                 :             : 
    6069                 :             : row_security_cmd:
    6070                 :          33 :             ALL             { $$ = "all"; }
    6071                 :          85 :         |   SELECT          { $$ = "select"; }
    6072                 :          37 :         |   INSERT          { $$ = "insert"; }
    6073                 :          63 :         |   UPDATE          { $$ = "update"; }
    6074                 :          31 :         |   DELETE_P        { $$ = "delete"; }
    6075                 :             :         ;
    6076                 :             : 
    6077                 :             : /*****************************************************************************
    6078                 :             :  *
    6079                 :             :  *      QUERY:
    6080                 :             :  *             CREATE ACCESS METHOD name HANDLER handler_name
    6081                 :             :  *
    6082                 :             :  *****************************************************************************/
    6083                 :             : 
    6084                 :             : CreateAmStmt: CREATE ACCESS METHOD name TYPE_P am_type HANDLER handler_name
    6085                 :             :                 {
    6086                 :          38 :                     CreateAmStmt *n = makeNode(CreateAmStmt);
    6087                 :             : 
    6088                 :          38 :                     n->amname = $4;
    6089                 :          38 :                     n->handler_name = $8;
    6090                 :          38 :                     n->amtype = $6;
    6091                 :          38 :                     $$ = (Node *) n;
    6092                 :             :                 }
    6093                 :             :         ;
    6094                 :             : 
    6095                 :             : am_type:
    6096                 :          20 :             INDEX           { $$ = AMTYPE_INDEX; }
    6097                 :          18 :         |   TABLE           { $$ = AMTYPE_TABLE; }
    6098                 :             :         ;
    6099                 :             : 
    6100                 :             : /*****************************************************************************
    6101                 :             :  *
    6102                 :             :  *      QUERIES :
    6103                 :             :  *              CREATE TRIGGER ...
    6104                 :             :  *
    6105                 :             :  *****************************************************************************/
    6106                 :             : 
    6107                 :             : CreateTrigStmt:
    6108                 :             :             CREATE opt_or_replace TRIGGER name TriggerActionTime TriggerEvents ON
    6109                 :             :             qualified_name TriggerReferencing TriggerForSpec TriggerWhen
    6110                 :             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6111                 :             :                 {
    6112                 :        2001 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6113                 :             : 
    6114                 :        2001 :                     n->replace = $2;
    6115                 :        2001 :                     n->isconstraint = false;
    6116                 :        2001 :                     n->trigname = $4;
    6117                 :        2001 :                     n->relation = $8;
    6118                 :        2001 :                     n->funcname = $14;
    6119                 :        2001 :                     n->args = $16;
    6120                 :        2001 :                     n->row = $10;
    6121                 :        2001 :                     n->timing = $5;
    6122                 :        2001 :                     n->events = intVal(linitial($6));
    6123                 :        2001 :                     n->columns = (List *) lsecond($6);
    6124                 :        2001 :                     n->whenClause = $11;
    6125                 :        2001 :                     n->transitionRels = $9;
    6126                 :        2001 :                     n->deferrable = false;
    6127                 :        2001 :                     n->initdeferred = false;
    6128                 :        2001 :                     n->constrrel = NULL;
    6129                 :        2001 :                     $$ = (Node *) n;
    6130                 :             :                 }
    6131                 :             :           | CREATE opt_or_replace CONSTRAINT TRIGGER name AFTER TriggerEvents ON
    6132                 :             :             qualified_name OptConstrFromTable ConstraintAttributeSpec
    6133                 :             :             FOR EACH ROW TriggerWhen
    6134                 :             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' TriggerFuncArgs ')'
    6135                 :             :                 {
    6136                 :          57 :                     CreateTrigStmt *n = makeNode(CreateTrigStmt);
    6137                 :             :                     bool        dummy;
    6138                 :             : 
    6139         [ +  + ]:          57 :                     if (($11 & CAS_NOT_VALID) != 0)
    6140         [ +  - ]:           4 :                         ereport(ERROR,
    6141                 :             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6142                 :             :                                 errmsg("constraint triggers cannot be marked %s",
    6143                 :             :                                        "NOT VALID"),
    6144                 :             :                                 parser_errposition(@11));
    6145         [ +  + ]:          53 :                     if (($11 & CAS_NO_INHERIT) != 0)
    6146         [ +  - ]:           4 :                         ereport(ERROR,
    6147                 :             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6148                 :             :                                 errmsg("constraint triggers cannot be marked %s",
    6149                 :             :                                        "NO INHERIT"),
    6150                 :             :                                 parser_errposition(@11));
    6151         [ +  + ]:          49 :                     if (($11 & CAS_NOT_ENFORCED) != 0)
    6152         [ +  - ]:           4 :                         ereport(ERROR,
    6153                 :             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6154                 :             :                                 errmsg("constraint triggers cannot be marked %s",
    6155                 :             :                                        "NOT ENFORCED"),
    6156                 :             :                                 parser_errposition(@11));
    6157                 :             : 
    6158                 :          45 :                     n->replace = $2;
    6159         [ -  + ]:          45 :                     if (n->replace) /* not supported, see CreateTrigger */
    6160         [ #  # ]:           0 :                         ereport(ERROR,
    6161                 :             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6162                 :             :                                  errmsg("CREATE OR REPLACE CONSTRAINT TRIGGER is not supported"),
    6163                 :             :                                  parser_errposition(@1)));
    6164                 :          45 :                     n->isconstraint = true;
    6165                 :          45 :                     n->trigname = $5;
    6166                 :          45 :                     n->relation = $9;
    6167                 :          45 :                     n->funcname = $18;
    6168                 :          45 :                     n->args = $20;
    6169                 :          45 :                     n->row = true;
    6170                 :          45 :                     n->timing = TRIGGER_TYPE_AFTER;
    6171                 :          45 :                     n->events = intVal(linitial($7));
    6172                 :          45 :                     n->columns = (List *) lsecond($7);
    6173                 :          45 :                     n->whenClause = $15;
    6174                 :          45 :                     n->transitionRels = NIL;
    6175                 :          45 :                     processCASbits($11, @11, "TRIGGER",
    6176                 :             :                                    &n->deferrable, &n->initdeferred, &dummy,
    6177                 :             :                                    NULL, NULL, yyscanner);
    6178                 :          45 :                     n->constrrel = $10;
    6179                 :          45 :                     $$ = (Node *) n;
    6180                 :             :                 }
    6181                 :             :         ;
    6182                 :             : 
    6183                 :             : TriggerActionTime:
    6184                 :         888 :             BEFORE                              { $$ = TRIGGER_TYPE_BEFORE; }
    6185                 :        1026 :             | AFTER                             { $$ = TRIGGER_TYPE_AFTER; }
    6186                 :          95 :             | INSTEAD OF                        { $$ = TRIGGER_TYPE_INSTEAD; }
    6187                 :             :         ;
    6188                 :             : 
    6189                 :             : TriggerEvents:
    6190                 :             :             TriggerOneEvent
    6191                 :        2066 :                 { $$ = $1; }
    6192                 :             :             | TriggerEvents OR TriggerOneEvent
    6193                 :             :                 {
    6194                 :         708 :                     int         events1 = intVal(linitial($1));
    6195                 :         708 :                     int         events2 = intVal(linitial($3));
    6196                 :         708 :                     List       *columns1 = (List *) lsecond($1);
    6197                 :         708 :                     List       *columns2 = (List *) lsecond($3);
    6198                 :             : 
    6199         [ +  + ]:         708 :                     if (events1 & events2)
    6200                 :           4 :                         parser_yyerror("duplicate trigger events specified");
    6201                 :             :                     /*
    6202                 :             :                      * concat'ing the columns lists loses information about
    6203                 :             :                      * which columns went with which event, but so long as
    6204                 :             :                      * only UPDATE carries columns and we disallow multiple
    6205                 :             :                      * UPDATE items, it doesn't matter.  Command execution
    6206                 :             :                      * should just ignore the columns for non-UPDATE events.
    6207                 :             :                      */
    6208                 :         704 :                     $$ = list_make2(makeInteger(events1 | events2),
    6209                 :             :                                     list_concat(columns1, columns2));
    6210                 :             :                 }
    6211                 :             :         ;
    6212                 :             : 
    6213                 :             : TriggerOneEvent:
    6214                 :             :             INSERT
    6215                 :        1100 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_INSERT), NIL); }
    6216                 :             :             | DELETE_P
    6217                 :         544 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_DELETE), NIL); }
    6218                 :             :             | UPDATE
    6219                 :        1041 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), NIL); }
    6220                 :             :             | UPDATE OF columnList
    6221                 :          65 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_UPDATE), $3); }
    6222                 :             :             | TRUNCATE
    6223                 :          24 :                 { $$ = list_make2(makeInteger(TRIGGER_TYPE_TRUNCATE), NIL); }
    6224                 :             :         ;
    6225                 :             : 
    6226                 :             : TriggerReferencing:
    6227                 :         304 :             REFERENCING TriggerTransitions          { $$ = $2; }
    6228                 :        1697 :             | /*EMPTY*/                             { $$ = NIL; }
    6229                 :             :         ;
    6230                 :             : 
    6231                 :             : TriggerTransitions:
    6232                 :         304 :             TriggerTransition                       { $$ = list_make1($1); }
    6233                 :          92 :             | TriggerTransitions TriggerTransition  { $$ = lappend($1, $2); }
    6234                 :             :         ;
    6235                 :             : 
    6236                 :             : TriggerTransition:
    6237                 :             :             TransitionOldOrNew TransitionRowOrTable opt_as TransitionRelName
    6238                 :             :                 {
    6239                 :         396 :                     TriggerTransition *n = makeNode(TriggerTransition);
    6240                 :             : 
    6241                 :         396 :                     n->name = $4;
    6242                 :         396 :                     n->isNew = $1;
    6243                 :         396 :                     n->isTable = $2;
    6244                 :         396 :                     $$ = (Node *) n;
    6245                 :             :                 }
    6246                 :             :         ;
    6247                 :             : 
    6248                 :             : TransitionOldOrNew:
    6249                 :         216 :             NEW                                     { $$ = true; }
    6250                 :         180 :             | OLD                                   { $$ = false; }
    6251                 :             :         ;
    6252                 :             : 
    6253                 :             : TransitionRowOrTable:
    6254                 :         396 :             TABLE                                   { $$ = true; }
    6255                 :             :             /*
    6256                 :             :              * According to the standard, lack of a keyword here implies ROW.
    6257                 :             :              * Support for that would require prohibiting ROW entirely here,
    6258                 :             :              * reserving the keyword ROW, and/or requiring AS (instead of
    6259                 :             :              * allowing it to be optional, as the standard specifies) as the
    6260                 :             :              * next token.  Requiring ROW seems cleanest and easiest to
    6261                 :             :              * explain.
    6262                 :             :              */
    6263                 :           0 :             | ROW                                   { $$ = false; }
    6264                 :             :         ;
    6265                 :             : 
    6266                 :             : TransitionRelName:
    6267                 :         396 :             ColId                                   { $$ = $1; }
    6268                 :             :         ;
    6269                 :             : 
    6270                 :             : TriggerForSpec:
    6271                 :             :             FOR TriggerForOptEach TriggerForType
    6272                 :             :                 {
    6273                 :        1867 :                     $$ = $3;
    6274                 :             :                 }
    6275                 :             :             | /* EMPTY */
    6276                 :             :                 {
    6277                 :             :                     /*
    6278                 :             :                      * If ROW/STATEMENT not specified, default to
    6279                 :             :                      * STATEMENT, per SQL
    6280                 :             :                      */
    6281                 :         134 :                     $$ = false;
    6282                 :             :                 }
    6283                 :             :         ;
    6284                 :             : 
    6285                 :             : TriggerForOptEach:
    6286                 :             :             EACH
    6287                 :             :             | /*EMPTY*/
    6288                 :             :         ;
    6289                 :             : 
    6290                 :             : TriggerForType:
    6291                 :        1331 :             ROW                                     { $$ = true; }
    6292                 :         536 :             | STATEMENT                             { $$ = false; }
    6293                 :             :         ;
    6294                 :             : 
    6295                 :             : TriggerWhen:
    6296                 :         124 :             WHEN '(' a_expr ')'                     { $$ = $3; }
    6297                 :        1934 :             | /*EMPTY*/                             { $$ = NULL; }
    6298                 :             :         ;
    6299                 :             : 
    6300                 :             : FUNCTION_or_PROCEDURE:
    6301                 :             :             FUNCTION
    6302                 :             :         |   PROCEDURE
    6303                 :             :         ;
    6304                 :             : 
    6305                 :             : TriggerFuncArgs:
    6306                 :         336 :             TriggerFuncArg                          { $$ = list_make1($1); }
    6307                 :          63 :             | TriggerFuncArgs ',' TriggerFuncArg    { $$ = lappend($1, $3); }
    6308                 :        1722 :             | /*EMPTY*/                             { $$ = NIL; }
    6309                 :             :         ;
    6310                 :             : 
    6311                 :             : TriggerFuncArg:
    6312                 :             :             Iconst
    6313                 :             :                 {
    6314                 :          49 :                     $$ = (Node *) makeString(psprintf("%d", $1));
    6315                 :             :                 }
    6316                 :           0 :             | FCONST                                { $$ = (Node *) makeString($1); }
    6317                 :         337 :             | Sconst                                { $$ = (Node *) makeString($1); }
    6318                 :          13 :             | ColLabel                              { $$ = (Node *) makeString($1); }
    6319                 :             :         ;
    6320                 :             : 
    6321                 :             : OptConstrFromTable:
    6322                 :           8 :             FROM qualified_name                     { $$ = $2; }
    6323                 :          49 :             | /*EMPTY*/                             { $$ = NULL; }
    6324                 :             :         ;
    6325                 :             : 
    6326                 :             : ConstraintAttributeSpec:
    6327                 :             :             /*EMPTY*/
    6328                 :       11362 :                 { $$ = 0; }
    6329                 :             :             | ConstraintAttributeSpec ConstraintAttributeElem
    6330                 :             :                 {
    6331                 :             :                     /*
    6332                 :             :                      * We must complain about conflicting options.
    6333                 :             :                      * We could, but choose not to, complain about redundant
    6334                 :             :                      * options (ie, where $2's bit is already set in $1).
    6335                 :             :                      */
    6336                 :        1261 :                     int     newspec = $1 | $2;
    6337                 :             : 
    6338                 :             :                     /* special message for this case */
    6339         [ +  + ]:        1261 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED)) == (CAS_NOT_DEFERRABLE | CAS_INITIALLY_DEFERRED))
    6340         [ +  - ]:           4 :                         ereport(ERROR,
    6341                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6342                 :             :                                  errmsg("constraint declared INITIALLY DEFERRED must be DEFERRABLE"),
    6343                 :             :                                  parser_errposition(@2)));
    6344                 :             :                     /* generic message for other conflicts */
    6345         [ +  - ]:        1257 :                     if ((newspec & (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE)) == (CAS_NOT_DEFERRABLE | CAS_DEFERRABLE) ||
    6346         [ +  - ]:        1257 :                         (newspec & (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED)) == (CAS_INITIALLY_IMMEDIATE | CAS_INITIALLY_DEFERRED) ||
    6347         [ +  + ]:        1257 :                         (newspec & (CAS_NOT_ENFORCED | CAS_ENFORCED)) == (CAS_NOT_ENFORCED | CAS_ENFORCED))
    6348         [ +  - ]:           4 :                         ereport(ERROR,
    6349                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
    6350                 :             :                                  errmsg("conflicting constraint properties"),
    6351                 :             :                                  parser_errposition(@2)));
    6352                 :        1253 :                     $$ = newspec;
    6353                 :             :                 }
    6354                 :             :         ;
    6355                 :             : 
    6356                 :             : ConstraintAttributeElem:
    6357                 :          32 :             NOT DEFERRABLE                  { $$ = CAS_NOT_DEFERRABLE; }
    6358                 :         154 :             | DEFERRABLE                    { $$ = CAS_DEFERRABLE; }
    6359                 :          20 :             | INITIALLY IMMEDIATE           { $$ = CAS_INITIALLY_IMMEDIATE; }
    6360                 :         109 :             | INITIALLY DEFERRED            { $$ = CAS_INITIALLY_DEFERRED; }
    6361                 :         436 :             | NOT VALID                     { $$ = CAS_NOT_VALID; }
    6362                 :         171 :             | NO INHERIT                    { $$ = CAS_NO_INHERIT; }
    6363                 :         199 :             | NOT ENFORCED                  { $$ = CAS_NOT_ENFORCED; }
    6364                 :         140 :             | ENFORCED                      { $$ = CAS_ENFORCED; }
    6365                 :             :         ;
    6366                 :             : 
    6367                 :             : 
    6368                 :             : /*****************************************************************************
    6369                 :             :  *
    6370                 :             :  *      QUERIES :
    6371                 :             :  *              CREATE EVENT TRIGGER ...
    6372                 :             :  *              ALTER EVENT TRIGGER ...
    6373                 :             :  *
    6374                 :             :  *****************************************************************************/
    6375                 :             : 
    6376                 :             : CreateEventTrigStmt:
    6377                 :             :             CREATE EVENT TRIGGER name ON ColLabel
    6378                 :             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6379                 :             :                 {
    6380                 :          64 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6381                 :             : 
    6382                 :          64 :                     n->trigname = $4;
    6383                 :          64 :                     n->eventname = $6;
    6384                 :          64 :                     n->whenclause = NULL;
    6385                 :          64 :                     n->funcname = $9;
    6386                 :          64 :                     $$ = (Node *) n;
    6387                 :             :                 }
    6388                 :             :           | CREATE EVENT TRIGGER name ON ColLabel
    6389                 :             :             WHEN event_trigger_when_list
    6390                 :             :             EXECUTE FUNCTION_or_PROCEDURE func_name '(' ')'
    6391                 :             :                 {
    6392                 :          65 :                     CreateEventTrigStmt *n = makeNode(CreateEventTrigStmt);
    6393                 :             : 
    6394                 :          65 :                     n->trigname = $4;
    6395                 :          65 :                     n->eventname = $6;
    6396                 :          65 :                     n->whenclause = $8;
    6397                 :          65 :                     n->funcname = $11;
    6398                 :          65 :                     $$ = (Node *) n;
    6399                 :             :                 }
    6400                 :             :         ;
    6401                 :             : 
    6402                 :             : event_trigger_when_list:
    6403                 :             :           event_trigger_when_item
    6404                 :          65 :             { $$ = list_make1($1); }
    6405                 :             :         | event_trigger_when_list AND event_trigger_when_item
    6406                 :           4 :             { $$ = lappend($1, $3); }
    6407                 :             :         ;
    6408                 :             : 
    6409                 :             : event_trigger_when_item:
    6410                 :             :         ColId IN_P '(' event_trigger_value_list ')'
    6411                 :          69 :             { $$ = makeDefElem($1, (Node *) $4, @1); }
    6412                 :             :         ;
    6413                 :             : 
    6414                 :             : event_trigger_value_list:
    6415                 :             :           SCONST
    6416                 :          69 :             { $$ = list_make1(makeString($1)); }
    6417                 :             :         | event_trigger_value_list ',' SCONST
    6418                 :          44 :             { $$ = lappend($1, makeString($3)); }
    6419                 :             :         ;
    6420                 :             : 
    6421                 :             : AlterEventTrigStmt:
    6422                 :             :             ALTER EVENT TRIGGER name enable_trigger
    6423                 :             :                 {
    6424                 :          32 :                     AlterEventTrigStmt *n = makeNode(AlterEventTrigStmt);
    6425                 :             : 
    6426                 :          32 :                     n->trigname = $4;
    6427                 :          32 :                     n->tgenabled = $5;
    6428                 :          32 :                     $$ = (Node *) n;
    6429                 :             :                 }
    6430                 :             :         ;
    6431                 :             : 
    6432                 :             : enable_trigger:
    6433                 :           4 :             ENABLE_P                    { $$ = TRIGGER_FIRES_ON_ORIGIN; }
    6434                 :           4 :             | ENABLE_P REPLICA          { $$ = TRIGGER_FIRES_ON_REPLICA; }
    6435                 :          11 :             | ENABLE_P ALWAYS           { $$ = TRIGGER_FIRES_ALWAYS; }
    6436                 :          13 :             | DISABLE_P                 { $$ = TRIGGER_DISABLED; }
    6437                 :             :         ;
    6438                 :             : 
    6439                 :             : /*****************************************************************************
    6440                 :             :  *
    6441                 :             :  *      QUERY :
    6442                 :             :  *              CREATE ASSERTION ...
    6443                 :             :  *
    6444                 :             :  *****************************************************************************/
    6445                 :             : 
    6446                 :             : CreateAssertionStmt:
    6447                 :             :             CREATE ASSERTION any_name CHECK '(' a_expr ')' ConstraintAttributeSpec
    6448                 :             :                 {
    6449         [ #  # ]:           0 :                     ereport(ERROR,
    6450                 :             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6451                 :             :                              errmsg("CREATE ASSERTION is not yet implemented"),
    6452                 :             :                              parser_errposition(@1)));
    6453                 :             : 
    6454                 :             :                     $$ = NULL;
    6455                 :             :                 }
    6456                 :             :         ;
    6457                 :             : 
    6458                 :             : 
    6459                 :             : /*****************************************************************************
    6460                 :             :  *
    6461                 :             :  *      QUERY :
    6462                 :             :  *              define (aggregate,operator,type)
    6463                 :             :  *
    6464                 :             :  *****************************************************************************/
    6465                 :             : 
    6466                 :             : DefineStmt:
    6467                 :             :             CREATE opt_or_replace AGGREGATE func_name aggr_args definition
    6468                 :             :                 {
    6469                 :         341 :                     DefineStmt *n = makeNode(DefineStmt);
    6470                 :             : 
    6471                 :         341 :                     n->kind = OBJECT_AGGREGATE;
    6472                 :         341 :                     n->oldstyle = false;
    6473                 :         341 :                     n->replace = $2;
    6474                 :         341 :                     n->defnames = $4;
    6475                 :         341 :                     n->args = $5;
    6476                 :         341 :                     n->definition = $6;
    6477                 :         341 :                     $$ = (Node *) n;
    6478                 :             :                 }
    6479                 :             :             | CREATE opt_or_replace AGGREGATE func_name old_aggr_definition
    6480                 :             :                 {
    6481                 :             :                     /* old-style (pre-8.2) syntax for CREATE AGGREGATE */
    6482                 :         240 :                     DefineStmt *n = makeNode(DefineStmt);
    6483                 :             : 
    6484                 :         240 :                     n->kind = OBJECT_AGGREGATE;
    6485                 :         240 :                     n->oldstyle = true;
    6486                 :         240 :                     n->replace = $2;
    6487                 :         240 :                     n->defnames = $4;
    6488                 :         240 :                     n->args = NIL;
    6489                 :         240 :                     n->definition = $5;
    6490                 :         240 :                     $$ = (Node *) n;
    6491                 :             :                 }
    6492                 :             :             | CREATE OPERATOR any_operator definition
    6493                 :             :                 {
    6494                 :         893 :                     DefineStmt *n = makeNode(DefineStmt);
    6495                 :             : 
    6496                 :         893 :                     n->kind = OBJECT_OPERATOR;
    6497                 :         893 :                     n->oldstyle = false;
    6498                 :         893 :                     n->defnames = $3;
    6499                 :         893 :                     n->args = NIL;
    6500                 :         893 :                     n->definition = $4;
    6501                 :         893 :                     $$ = (Node *) n;
    6502                 :             :                 }
    6503                 :             :             | CREATE TYPE_P any_name definition
    6504                 :             :                 {
    6505                 :         145 :                     DefineStmt *n = makeNode(DefineStmt);
    6506                 :             : 
    6507                 :         145 :                     n->kind = OBJECT_TYPE;
    6508                 :         145 :                     n->oldstyle = false;
    6509                 :         145 :                     n->defnames = $3;
    6510                 :         145 :                     n->args = NIL;
    6511                 :         145 :                     n->definition = $4;
    6512                 :         145 :                     $$ = (Node *) n;
    6513                 :             :                 }
    6514                 :             :             | CREATE TYPE_P any_name
    6515                 :             :                 {
    6516                 :             :                     /* Shell type (identified by lack of definition) */
    6517                 :          97 :                     DefineStmt *n = makeNode(DefineStmt);
    6518                 :             : 
    6519                 :          97 :                     n->kind = OBJECT_TYPE;
    6520                 :          97 :                     n->oldstyle = false;
    6521                 :          97 :                     n->defnames = $3;
    6522                 :          97 :                     n->args = NIL;
    6523                 :          97 :                     n->definition = NIL;
    6524                 :          97 :                     $$ = (Node *) n;
    6525                 :             :                 }
    6526                 :             :             | CREATE TYPE_P any_name AS '(' OptTableFuncElementList ')'
    6527                 :             :                 {
    6528                 :        2387 :                     CompositeTypeStmt *n = makeNode(CompositeTypeStmt);
    6529                 :             : 
    6530                 :             :                     /* can't use qualified_name, sigh */
    6531                 :        2387 :                     n->typevar = makeRangeVarFromAnyName($3, @3, yyscanner);
    6532                 :        2387 :                     n->coldeflist = $6;
    6533                 :        2387 :                     $$ = (Node *) n;
    6534                 :             :                 }
    6535                 :             :             | CREATE TYPE_P any_name AS ENUM_P '(' opt_enum_val_list ')'
    6536                 :             :                 {
    6537                 :         162 :                     CreateEnumStmt *n = makeNode(CreateEnumStmt);
    6538                 :             : 
    6539                 :         162 :                     n->typeName = $3;
    6540                 :         162 :                     n->vals = $7;
    6541                 :         162 :                     $$ = (Node *) n;
    6542                 :             :                 }
    6543                 :             :             | CREATE TYPE_P any_name AS RANGE definition
    6544                 :             :                 {
    6545                 :         148 :                     CreateRangeStmt *n = makeNode(CreateRangeStmt);
    6546                 :             : 
    6547                 :         148 :                     n->typeName = $3;
    6548                 :         148 :                     n->params = $6;
    6549                 :         148 :                     $$ = (Node *) n;
    6550                 :             :                 }
    6551                 :             :             | CREATE TEXT_P SEARCH PARSER any_name definition
    6552                 :             :                 {
    6553                 :          26 :                     DefineStmt *n = makeNode(DefineStmt);
    6554                 :             : 
    6555                 :          26 :                     n->kind = OBJECT_TSPARSER;
    6556                 :          26 :                     n->args = NIL;
    6557                 :          26 :                     n->defnames = $5;
    6558                 :          26 :                     n->definition = $6;
    6559                 :          26 :                     $$ = (Node *) n;
    6560                 :             :                 }
    6561                 :             :             | CREATE TEXT_P SEARCH DICTIONARY any_name definition
    6562                 :             :                 {
    6563                 :        1860 :                     DefineStmt *n = makeNode(DefineStmt);
    6564                 :             : 
    6565                 :        1860 :                     n->kind = OBJECT_TSDICTIONARY;
    6566                 :        1860 :                     n->args = NIL;
    6567                 :        1860 :                     n->defnames = $5;
    6568                 :        1860 :                     n->definition = $6;
    6569                 :        1860 :                     $$ = (Node *) n;
    6570                 :             :                 }
    6571                 :             :             | CREATE TEXT_P SEARCH TEMPLATE any_name definition
    6572                 :             :                 {
    6573                 :          85 :                     DefineStmt *n = makeNode(DefineStmt);
    6574                 :             : 
    6575                 :          85 :                     n->kind = OBJECT_TSTEMPLATE;
    6576                 :          85 :                     n->args = NIL;
    6577                 :          85 :                     n->defnames = $5;
    6578                 :          85 :                     n->definition = $6;
    6579                 :          85 :                     $$ = (Node *) n;
    6580                 :             :                 }
    6581                 :             :             | CREATE TEXT_P SEARCH CONFIGURATION any_name definition
    6582                 :             :                 {
    6583                 :        1824 :                     DefineStmt *n = makeNode(DefineStmt);
    6584                 :             : 
    6585                 :        1824 :                     n->kind = OBJECT_TSCONFIGURATION;
    6586                 :        1824 :                     n->args = NIL;
    6587                 :        1824 :                     n->defnames = $5;
    6588                 :        1824 :                     n->definition = $6;
    6589                 :        1824 :                     $$ = (Node *) n;
    6590                 :             :                 }
    6591                 :             :             | CREATE COLLATION any_name definition
    6592                 :             :                 {
    6593                 :         196 :                     DefineStmt *n = makeNode(DefineStmt);
    6594                 :             : 
    6595                 :         196 :                     n->kind = OBJECT_COLLATION;
    6596                 :         196 :                     n->args = NIL;
    6597                 :         196 :                     n->defnames = $3;
    6598                 :         196 :                     n->definition = $4;
    6599                 :         196 :                     $$ = (Node *) n;
    6600                 :             :                 }
    6601                 :             :             | CREATE COLLATION IF_P NOT EXISTS any_name definition
    6602                 :             :                 {
    6603                 :           9 :                     DefineStmt *n = makeNode(DefineStmt);
    6604                 :             : 
    6605                 :           9 :                     n->kind = OBJECT_COLLATION;
    6606                 :           9 :                     n->args = NIL;
    6607                 :           9 :                     n->defnames = $6;
    6608                 :           9 :                     n->definition = $7;
    6609                 :           9 :                     n->if_not_exists = true;
    6610                 :           9 :                     $$ = (Node *) n;
    6611                 :             :                 }
    6612                 :             :             | CREATE COLLATION any_name FROM any_name
    6613                 :             :                 {
    6614                 :          35 :                     DefineStmt *n = makeNode(DefineStmt);
    6615                 :             : 
    6616                 :          35 :                     n->kind = OBJECT_COLLATION;
    6617                 :          35 :                     n->args = NIL;
    6618                 :          35 :                     n->defnames = $3;
    6619                 :          35 :                     n->definition = list_make1(makeDefElem("from", (Node *) $5, @5));
    6620                 :          35 :                     $$ = (Node *) n;
    6621                 :             :                 }
    6622                 :             :             | CREATE COLLATION IF_P NOT EXISTS any_name FROM any_name
    6623                 :             :                 {
    6624                 :           0 :                     DefineStmt *n = makeNode(DefineStmt);
    6625                 :             : 
    6626                 :           0 :                     n->kind = OBJECT_COLLATION;
    6627                 :           0 :                     n->args = NIL;
    6628                 :           0 :                     n->defnames = $6;
    6629                 :           0 :                     n->definition = list_make1(makeDefElem("from", (Node *) $8, @8));
    6630                 :           0 :                     n->if_not_exists = true;
    6631                 :           0 :                     $$ = (Node *) n;
    6632                 :             :                 }
    6633                 :             :         ;
    6634                 :             : 
    6635                 :        6361 : definition: '(' def_list ')'                        { $$ = $2; }
    6636                 :             :         ;
    6637                 :             : 
    6638                 :        6361 : def_list:   def_elem                                { $$ = list_make1($1); }
    6639                 :        8622 :             | def_list ',' def_elem                 { $$ = lappend($1, $3); }
    6640                 :             :         ;
    6641                 :             : 
    6642                 :             : def_elem:   ColLabel '=' def_arg
    6643                 :             :                 {
    6644                 :       14788 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6645                 :             :                 }
    6646                 :             :             | ColLabel
    6647                 :             :                 {
    6648                 :         195 :                     $$ = makeDefElem($1, NULL, @1);
    6649                 :             :                 }
    6650                 :             :         ;
    6651                 :             : 
    6652                 :             : /* Note: any simple identifier will be returned as a type name! */
    6653                 :       11872 : def_arg:    func_type                       { $$ = (Node *) $1; }
    6654                 :        2806 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
    6655                 :         626 :             | qual_all_Op                   { $$ = (Node *) $1; }
    6656                 :         916 :             | NumericOnly                   { $$ = (Node *) $1; }
    6657                 :        1259 :             | Sconst                        { $$ = (Node *) makeString($1); }
    6658                 :         153 :             | NONE                          { $$ = (Node *) makeString(pstrdup($1)); }
    6659                 :             :         ;
    6660                 :             : 
    6661                 :         240 : old_aggr_definition: '(' old_aggr_list ')'          { $$ = $2; }
    6662                 :             :         ;
    6663                 :             : 
    6664                 :         240 : old_aggr_list: old_aggr_elem                        { $$ = list_make1($1); }
    6665                 :         856 :             | old_aggr_list ',' old_aggr_elem       { $$ = lappend($1, $3); }
    6666                 :             :         ;
    6667                 :             : 
    6668                 :             : /*
    6669                 :             :  * Must use IDENT here to avoid reduce/reduce conflicts; fortunately none of
    6670                 :             :  * the item names needed in old aggregate definitions are likely to become
    6671                 :             :  * SQL keywords.
    6672                 :             :  */
    6673                 :             : old_aggr_elem:  IDENT '=' def_arg
    6674                 :             :                 {
    6675                 :        1096 :                     $$ = makeDefElem($1, (Node *) $3, @1);
    6676                 :             :                 }
    6677                 :             :         ;
    6678                 :             : 
    6679                 :             : opt_enum_val_list:
    6680                 :         158 :         enum_val_list                           { $$ = $1; }
    6681                 :           4 :         | /*EMPTY*/                             { $$ = NIL; }
    6682                 :             :         ;
    6683                 :             : 
    6684                 :             : enum_val_list:  Sconst
    6685                 :         158 :                 { $$ = list_make1(makeString($1)); }
    6686                 :             :             | enum_val_list ',' Sconst
    6687                 :        5292 :                 { $$ = lappend($1, makeString($3)); }
    6688                 :             :         ;
    6689                 :             : 
    6690                 :             : /*****************************************************************************
    6691                 :             :  *
    6692                 :             :  *  ALTER TYPE enumtype ADD ...
    6693                 :             :  *
    6694                 :             :  *****************************************************************************/
    6695                 :             : 
    6696                 :             : AlterEnumStmt:
    6697                 :             :         ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst
    6698                 :             :             {
    6699                 :          86 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6700                 :             : 
    6701                 :          86 :                 n->typeName = $3;
    6702                 :          86 :                 n->oldVal = NULL;
    6703                 :          86 :                 n->newVal = $7;
    6704                 :          86 :                 n->newValNeighbor = NULL;
    6705                 :          86 :                 n->newValIsAfter = true;
    6706                 :          86 :                 n->skipIfNewValExists = $6;
    6707                 :          86 :                 $$ = (Node *) n;
    6708                 :             :             }
    6709                 :             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst BEFORE Sconst
    6710                 :             :             {
    6711                 :         130 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6712                 :             : 
    6713                 :         130 :                 n->typeName = $3;
    6714                 :         130 :                 n->oldVal = NULL;
    6715                 :         130 :                 n->newVal = $7;
    6716                 :         130 :                 n->newValNeighbor = $9;
    6717                 :         130 :                 n->newValIsAfter = false;
    6718                 :         130 :                 n->skipIfNewValExists = $6;
    6719                 :         130 :                 $$ = (Node *) n;
    6720                 :             :             }
    6721                 :             :          | ALTER TYPE_P any_name ADD_P VALUE_P opt_if_not_exists Sconst AFTER Sconst
    6722                 :             :             {
    6723                 :          14 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6724                 :             : 
    6725                 :          14 :                 n->typeName = $3;
    6726                 :          14 :                 n->oldVal = NULL;
    6727                 :          14 :                 n->newVal = $7;
    6728                 :          14 :                 n->newValNeighbor = $9;
    6729                 :          14 :                 n->newValIsAfter = true;
    6730                 :          14 :                 n->skipIfNewValExists = $6;
    6731                 :          14 :                 $$ = (Node *) n;
    6732                 :             :             }
    6733                 :             :          | ALTER TYPE_P any_name RENAME VALUE_P Sconst TO Sconst
    6734                 :             :             {
    6735                 :          16 :                 AlterEnumStmt *n = makeNode(AlterEnumStmt);
    6736                 :             : 
    6737                 :          16 :                 n->typeName = $3;
    6738                 :          16 :                 n->oldVal = $6;
    6739                 :          16 :                 n->newVal = $8;
    6740                 :          16 :                 n->newValNeighbor = NULL;
    6741                 :          16 :                 n->newValIsAfter = false;
    6742                 :          16 :                 n->skipIfNewValExists = false;
    6743                 :          16 :                 $$ = (Node *) n;
    6744                 :             :             }
    6745                 :             :          | ALTER TYPE_P any_name DROP VALUE_P Sconst
    6746                 :             :             {
    6747                 :             :                 /*
    6748                 :             :                  * The following problems must be solved before this can be
    6749                 :             :                  * implemented:
    6750                 :             :                  *
    6751                 :             :                  * - There must be no instance of the target value in
    6752                 :             :                  *   any table.
    6753                 :             :                  *
    6754                 :             :                  * - The value must not appear in any catalog metadata,
    6755                 :             :                  *   such as stored view expressions or column defaults.
    6756                 :             :                  *
    6757                 :             :                  * - The value must not appear in any non-leaf page of a
    6758                 :             :                  *   btree (and similar issues with other index types).
    6759                 :             :                  *   This is problematic because a value could persist
    6760                 :             :                  *   there long after it's gone from user-visible data.
    6761                 :             :                  *
    6762                 :             :                  * - Concurrent sessions must not be able to insert the
    6763                 :             :                  *   value while the preceding conditions are being checked.
    6764                 :             :                  *
    6765                 :             :                  * - Possibly more...
    6766                 :             :                  */
    6767         [ #  # ]:           0 :                 ereport(ERROR,
    6768                 :             :                         (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    6769                 :             :                          errmsg("dropping an enum value is not implemented"),
    6770                 :             :                          parser_errposition(@4)));
    6771                 :             :             }
    6772                 :             :          ;
    6773                 :             : 
    6774                 :           8 : opt_if_not_exists: IF_P NOT EXISTS              { $$ = true; }
    6775                 :         222 :         | /* EMPTY */                          { $$ = false; }
    6776                 :             :         ;
    6777                 :             : 
    6778                 :             : 
    6779                 :             : /*****************************************************************************
    6780                 :             :  *
    6781                 :             :  *      QUERIES :
    6782                 :             :  *              CREATE OPERATOR CLASS ...
    6783                 :             :  *              CREATE OPERATOR FAMILY ...
    6784                 :             :  *              ALTER OPERATOR FAMILY ...
    6785                 :             :  *              DROP OPERATOR CLASS ...
    6786                 :             :  *              DROP OPERATOR FAMILY ...
    6787                 :             :  *
    6788                 :             :  *****************************************************************************/
    6789                 :             : 
    6790                 :             : CreateOpClassStmt:
    6791                 :             :             CREATE OPERATOR CLASS any_name opt_default FOR TYPE_P Typename
    6792                 :             :             USING name opt_opfamily AS opclass_item_list
    6793                 :             :                 {
    6794                 :         299 :                     CreateOpClassStmt *n = makeNode(CreateOpClassStmt);
    6795                 :             : 
    6796                 :         299 :                     n->opclassname = $4;
    6797                 :         299 :                     n->isDefault = $5;
    6798                 :         299 :                     n->datatype = $8;
    6799                 :         299 :                     n->amname = $10;
    6800                 :         299 :                     n->opfamilyname = $11;
    6801                 :         299 :                     n->items = $13;
    6802                 :         299 :                     $$ = (Node *) n;
    6803                 :             :                 }
    6804                 :             :         ;
    6805                 :             : 
    6806                 :             : opclass_item_list:
    6807                 :         545 :             opclass_item                            { $$ = list_make1($1); }
    6808                 :        3082 :             | opclass_item_list ',' opclass_item    { $$ = lappend($1, $3); }
    6809                 :             :         ;
    6810                 :             : 
    6811                 :             : opclass_item:
    6812                 :             :             OPERATOR Iconst any_operator opclass_purpose
    6813                 :             :                 {
    6814                 :        1063 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6815                 :        1063 :                     ObjectWithArgs *owa = makeNode(ObjectWithArgs);
    6816                 :             : 
    6817                 :        1063 :                     owa->objname = $3;
    6818                 :        1063 :                     owa->objargs = NIL;
    6819                 :        1063 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6820                 :        1063 :                     n->name = owa;
    6821                 :        1063 :                     n->number = $2;
    6822                 :        1063 :                     n->order_family = $4;
    6823                 :        1063 :                     $$ = (Node *) n;
    6824                 :             :                 }
    6825                 :             :             | OPERATOR Iconst operator_with_argtypes opclass_purpose
    6826                 :             :                 {
    6827                 :         823 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6828                 :             : 
    6829                 :         823 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6830                 :         823 :                     n->name = $3;
    6831                 :         823 :                     n->number = $2;
    6832                 :         823 :                     n->order_family = $4;
    6833                 :         823 :                     $$ = (Node *) n;
    6834                 :             :                 }
    6835                 :             :             | FUNCTION Iconst function_with_argtypes
    6836                 :             :                 {
    6837                 :        1423 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6838                 :             : 
    6839                 :        1423 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6840                 :        1423 :                     n->name = $3;
    6841                 :        1423 :                     n->number = $2;
    6842                 :        1423 :                     $$ = (Node *) n;
    6843                 :             :                 }
    6844                 :             :             | FUNCTION Iconst '(' type_list ')' function_with_argtypes
    6845                 :             :                 {
    6846                 :         132 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6847                 :             : 
    6848                 :         132 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6849                 :         132 :                     n->name = $6;
    6850                 :         132 :                     n->number = $2;
    6851                 :         132 :                     n->class_args = $4;
    6852                 :         132 :                     $$ = (Node *) n;
    6853                 :             :                 }
    6854                 :             :             | STORAGE Typename
    6855                 :             :                 {
    6856                 :         186 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6857                 :             : 
    6858                 :         186 :                     n->itemtype = OPCLASS_ITEM_STORAGETYPE;
    6859                 :         186 :                     n->storedtype = $2;
    6860                 :         186 :                     $$ = (Node *) n;
    6861                 :             :                 }
    6862                 :             :         ;
    6863                 :             : 
    6864                 :         226 : opt_default:    DEFAULT                     { $$ = true; }
    6865                 :         115 :             | /*EMPTY*/                     { $$ = false; }
    6866                 :             :         ;
    6867                 :             : 
    6868                 :          26 : opt_opfamily:   FAMILY any_name             { $$ = $2; }
    6869                 :         273 :             | /*EMPTY*/                     { $$ = NIL; }
    6870                 :             :         ;
    6871                 :             : 
    6872                 :           0 : opclass_purpose: FOR SEARCH                 { $$ = NIL; }
    6873                 :          63 :             | FOR ORDER BY any_name         { $$ = $4; }
    6874                 :        1823 :             | /*EMPTY*/                     { $$ = NIL; }
    6875                 :             :         ;
    6876                 :             : 
    6877                 :             : 
    6878                 :             : CreateOpFamilyStmt:
    6879                 :             :             CREATE OPERATOR FAMILY any_name USING name
    6880                 :             :                 {
    6881                 :          99 :                     CreateOpFamilyStmt *n = makeNode(CreateOpFamilyStmt);
    6882                 :             : 
    6883                 :          99 :                     n->opfamilyname = $4;
    6884                 :          99 :                     n->amname = $6;
    6885                 :          99 :                     $$ = (Node *) n;
    6886                 :             :                 }
    6887                 :             :         ;
    6888                 :             : 
    6889                 :             : AlterOpFamilyStmt:
    6890                 :             :             ALTER OPERATOR FAMILY any_name USING name ADD_P opclass_item_list
    6891                 :             :                 {
    6892                 :         246 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6893                 :             : 
    6894                 :         246 :                     n->opfamilyname = $4;
    6895                 :         246 :                     n->amname = $6;
    6896                 :         246 :                     n->isDrop = false;
    6897                 :         246 :                     n->items = $8;
    6898                 :         246 :                     $$ = (Node *) n;
    6899                 :             :                 }
    6900                 :             :             | ALTER OPERATOR FAMILY any_name USING name DROP opclass_drop_list
    6901                 :             :                 {
    6902                 :          42 :                     AlterOpFamilyStmt *n = makeNode(AlterOpFamilyStmt);
    6903                 :             : 
    6904                 :          42 :                     n->opfamilyname = $4;
    6905                 :          42 :                     n->amname = $6;
    6906                 :          42 :                     n->isDrop = true;
    6907                 :          42 :                     n->items = $8;
    6908                 :          42 :                     $$ = (Node *) n;
    6909                 :             :                 }
    6910                 :             :         ;
    6911                 :             : 
    6912                 :             : opclass_drop_list:
    6913                 :          42 :             opclass_drop                            { $$ = list_make1($1); }
    6914                 :          20 :             | opclass_drop_list ',' opclass_drop    { $$ = lappend($1, $3); }
    6915                 :             :         ;
    6916                 :             : 
    6917                 :             : opclass_drop:
    6918                 :             :             OPERATOR Iconst '(' type_list ')'
    6919                 :             :                 {
    6920                 :          40 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6921                 :             : 
    6922                 :          40 :                     n->itemtype = OPCLASS_ITEM_OPERATOR;
    6923                 :          40 :                     n->number = $2;
    6924                 :          40 :                     n->class_args = $4;
    6925                 :          40 :                     $$ = (Node *) n;
    6926                 :             :                 }
    6927                 :             :             | FUNCTION Iconst '(' type_list ')'
    6928                 :             :                 {
    6929                 :          22 :                     CreateOpClassItem *n = makeNode(CreateOpClassItem);
    6930                 :             : 
    6931                 :          22 :                     n->itemtype = OPCLASS_ITEM_FUNCTION;
    6932                 :          22 :                     n->number = $2;
    6933                 :          22 :                     n->class_args = $4;
    6934                 :          22 :                     $$ = (Node *) n;
    6935                 :             :                 }
    6936                 :             :         ;
    6937                 :             : 
    6938                 :             : 
    6939                 :             : DropOpClassStmt:
    6940                 :             :             DROP OPERATOR CLASS any_name USING name opt_drop_behavior
    6941                 :             :                 {
    6942                 :          25 :                     DropStmt *n = makeNode(DropStmt);
    6943                 :             : 
    6944                 :          25 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6945                 :          25 :                     n->removeType = OBJECT_OPCLASS;
    6946                 :          25 :                     n->behavior = $7;
    6947                 :          25 :                     n->missing_ok = false;
    6948                 :          25 :                     n->concurrent = false;
    6949                 :          25 :                     $$ = (Node *) n;
    6950                 :             :                 }
    6951                 :             :             | DROP OPERATOR CLASS IF_P EXISTS any_name USING name opt_drop_behavior
    6952                 :             :                 {
    6953                 :          12 :                     DropStmt *n = makeNode(DropStmt);
    6954                 :             : 
    6955                 :          12 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6956                 :          12 :                     n->removeType = OBJECT_OPCLASS;
    6957                 :          12 :                     n->behavior = $9;
    6958                 :          12 :                     n->missing_ok = true;
    6959                 :          12 :                     n->concurrent = false;
    6960                 :          12 :                     $$ = (Node *) n;
    6961                 :             :                 }
    6962                 :             :         ;
    6963                 :             : 
    6964                 :             : DropOpFamilyStmt:
    6965                 :             :             DROP OPERATOR FAMILY any_name USING name opt_drop_behavior
    6966                 :             :                 {
    6967                 :          73 :                     DropStmt *n = makeNode(DropStmt);
    6968                 :             : 
    6969                 :          73 :                     n->objects = list_make1(lcons(makeString($6), $4));
    6970                 :          73 :                     n->removeType = OBJECT_OPFAMILY;
    6971                 :          73 :                     n->behavior = $7;
    6972                 :          73 :                     n->missing_ok = false;
    6973                 :          73 :                     n->concurrent = false;
    6974                 :          73 :                     $$ = (Node *) n;
    6975                 :             :                 }
    6976                 :             :             | DROP OPERATOR FAMILY IF_P EXISTS any_name USING name opt_drop_behavior
    6977                 :             :                 {
    6978                 :          12 :                     DropStmt *n = makeNode(DropStmt);
    6979                 :             : 
    6980                 :          12 :                     n->objects = list_make1(lcons(makeString($8), $6));
    6981                 :          12 :                     n->removeType = OBJECT_OPFAMILY;
    6982                 :          12 :                     n->behavior = $9;
    6983                 :          12 :                     n->missing_ok = true;
    6984                 :          12 :                     n->concurrent = false;
    6985                 :          12 :                     $$ = (Node *) n;
    6986                 :             :                 }
    6987                 :             :         ;
    6988                 :             : 
    6989                 :             : 
    6990                 :             : /*****************************************************************************
    6991                 :             :  *
    6992                 :             :  *      QUERY:
    6993                 :             :  *
    6994                 :             :  *      DROP OWNED BY username [, username ...] [ RESTRICT | CASCADE ]
    6995                 :             :  *      REASSIGN OWNED BY username [, username ...] TO username
    6996                 :             :  *
    6997                 :             :  *****************************************************************************/
    6998                 :             : DropOwnedStmt:
    6999                 :             :             DROP OWNED BY role_list opt_drop_behavior
    7000                 :             :                 {
    7001                 :         103 :                     DropOwnedStmt *n = makeNode(DropOwnedStmt);
    7002                 :             : 
    7003                 :         103 :                     n->roles = $4;
    7004                 :         103 :                     n->behavior = $5;
    7005                 :         103 :                     $$ = (Node *) n;
    7006                 :             :                 }
    7007                 :             :         ;
    7008                 :             : 
    7009                 :             : ReassignOwnedStmt:
    7010                 :             :             REASSIGN OWNED BY role_list TO RoleSpec
    7011                 :             :                 {
    7012                 :          39 :                     ReassignOwnedStmt *n = makeNode(ReassignOwnedStmt);
    7013                 :             : 
    7014                 :          39 :                     n->roles = $4;
    7015                 :          39 :                     n->newrole = $6;
    7016                 :          39 :                     $$ = (Node *) n;
    7017                 :             :                 }
    7018                 :             :         ;
    7019                 :             : 
    7020                 :             : /*****************************************************************************
    7021                 :             :  *
    7022                 :             :  *      QUERY:
    7023                 :             :  *
    7024                 :             :  *      DROP itemtype [ IF EXISTS ] itemname [, itemname ...]
    7025                 :             :  *           [ RESTRICT | CASCADE ]
    7026                 :             :  *
    7027                 :             :  *****************************************************************************/
    7028                 :             : 
    7029                 :             : DropStmt:   DROP object_type_any_name IF_P EXISTS any_name_list opt_drop_behavior
    7030                 :             :                 {
    7031                 :         755 :                     DropStmt *n = makeNode(DropStmt);
    7032                 :             : 
    7033                 :         755 :                     n->removeType = $2;
    7034                 :         755 :                     n->missing_ok = true;
    7035                 :         755 :                     n->objects = $5;
    7036                 :         755 :                     n->behavior = $6;
    7037                 :         755 :                     n->concurrent = false;
    7038                 :         755 :                     $$ = (Node *) n;
    7039                 :             :                 }
    7040                 :             :             | DROP object_type_any_name any_name_list opt_drop_behavior
    7041                 :             :                 {
    7042                 :       10878 :                     DropStmt *n = makeNode(DropStmt);
    7043                 :             : 
    7044                 :       10878 :                     n->removeType = $2;
    7045                 :       10878 :                     n->missing_ok = false;
    7046                 :       10878 :                     n->objects = $3;
    7047                 :       10878 :                     n->behavior = $4;
    7048                 :       10878 :                     n->concurrent = false;
    7049                 :       10878 :                     $$ = (Node *) n;
    7050                 :             :                 }
    7051                 :             :             | DROP drop_type_name IF_P EXISTS name_list opt_drop_behavior
    7052                 :             :                 {
    7053                 :         124 :                     DropStmt *n = makeNode(DropStmt);
    7054                 :             : 
    7055                 :         124 :                     n->removeType = $2;
    7056                 :         124 :                     n->missing_ok = true;
    7057                 :         124 :                     n->objects = $5;
    7058                 :         124 :                     n->behavior = $6;
    7059                 :         124 :                     n->concurrent = false;
    7060                 :         124 :                     $$ = (Node *) n;
    7061                 :             :                 }
    7062                 :             :             | DROP drop_type_name name_list opt_drop_behavior
    7063                 :             :                 {
    7064                 :        1054 :                     DropStmt *n = makeNode(DropStmt);
    7065                 :             : 
    7066                 :        1054 :                     n->removeType = $2;
    7067                 :        1054 :                     n->missing_ok = false;
    7068                 :        1054 :                     n->objects = $3;
    7069                 :        1054 :                     n->behavior = $4;
    7070                 :        1054 :                     n->concurrent = false;
    7071                 :        1054 :                     $$ = (Node *) n;
    7072                 :             :                 }
    7073                 :             :             | DROP object_type_name_on_any_name name ON any_name opt_drop_behavior
    7074                 :             :                 {
    7075                 :         767 :                     DropStmt *n = makeNode(DropStmt);
    7076                 :             : 
    7077                 :         767 :                     n->removeType = $2;
    7078                 :         767 :                     n->objects = list_make1(lappend($5, makeString($3)));
    7079                 :         767 :                     n->behavior = $6;
    7080                 :         767 :                     n->missing_ok = false;
    7081                 :         767 :                     n->concurrent = false;
    7082                 :         767 :                     $$ = (Node *) n;
    7083                 :             :                 }
    7084                 :             :             | DROP object_type_name_on_any_name IF_P EXISTS name ON any_name opt_drop_behavior
    7085                 :             :                 {
    7086                 :          32 :                     DropStmt *n = makeNode(DropStmt);
    7087                 :             : 
    7088                 :          32 :                     n->removeType = $2;
    7089                 :          32 :                     n->objects = list_make1(lappend($7, makeString($5)));
    7090                 :          32 :                     n->behavior = $8;
    7091                 :          32 :                     n->missing_ok = true;
    7092                 :          32 :                     n->concurrent = false;
    7093                 :          32 :                     $$ = (Node *) n;
    7094                 :             :                 }
    7095                 :             :             | DROP TYPE_P type_name_list opt_drop_behavior
    7096                 :             :                 {
    7097                 :         420 :                     DropStmt *n = makeNode(DropStmt);
    7098                 :             : 
    7099                 :         420 :                     n->removeType = OBJECT_TYPE;
    7100                 :         420 :                     n->missing_ok = false;
    7101                 :         420 :                     n->objects = $3;
    7102                 :         420 :                     n->behavior = $4;
    7103                 :         420 :                     n->concurrent = false;
    7104                 :         420 :                     $$ = (Node *) n;
    7105                 :             :                 }
    7106                 :             :             | DROP TYPE_P IF_P EXISTS type_name_list opt_drop_behavior
    7107                 :             :                 {
    7108                 :          50 :                     DropStmt *n = makeNode(DropStmt);
    7109                 :             : 
    7110                 :          50 :                     n->removeType = OBJECT_TYPE;
    7111                 :          50 :                     n->missing_ok = true;
    7112                 :          50 :                     n->objects = $5;
    7113                 :          50 :                     n->behavior = $6;
    7114                 :          50 :                     n->concurrent = false;
    7115                 :          50 :                     $$ = (Node *) n;
    7116                 :             :                 }
    7117                 :             :             | DROP DOMAIN_P type_name_list opt_drop_behavior
    7118                 :             :                 {
    7119                 :         354 :                     DropStmt *n = makeNode(DropStmt);
    7120                 :             : 
    7121                 :         354 :                     n->removeType = OBJECT_DOMAIN;
    7122                 :         354 :                     n->missing_ok = false;
    7123                 :         354 :                     n->objects = $3;
    7124                 :         354 :                     n->behavior = $4;
    7125                 :         354 :                     n->concurrent = false;
    7126                 :         354 :                     $$ = (Node *) n;
    7127                 :             :                 }
    7128                 :             :             | DROP DOMAIN_P IF_P EXISTS type_name_list opt_drop_behavior
    7129                 :             :                 {
    7130                 :          46 :                     DropStmt *n = makeNode(DropStmt);
    7131                 :             : 
    7132                 :          46 :                     n->removeType = OBJECT_DOMAIN;
    7133                 :          46 :                     n->missing_ok = true;
    7134                 :          46 :                     n->objects = $5;
    7135                 :          46 :                     n->behavior = $6;
    7136                 :          46 :                     n->concurrent = false;
    7137                 :          46 :                     $$ = (Node *) n;
    7138                 :             :                 }
    7139                 :             :             | DROP INDEX CONCURRENTLY any_name_list opt_drop_behavior
    7140                 :             :                 {
    7141                 :         119 :                     DropStmt *n = makeNode(DropStmt);
    7142                 :             : 
    7143                 :         119 :                     n->removeType = OBJECT_INDEX;
    7144                 :         119 :                     n->missing_ok = false;
    7145                 :         119 :                     n->objects = $4;
    7146                 :         119 :                     n->behavior = $5;
    7147                 :         119 :                     n->concurrent = true;
    7148                 :         119 :                     $$ = (Node *) n;
    7149                 :             :                 }
    7150                 :             :             | DROP INDEX CONCURRENTLY IF_P EXISTS any_name_list opt_drop_behavior
    7151                 :             :                 {
    7152                 :           8 :                     DropStmt *n = makeNode(DropStmt);
    7153                 :             : 
    7154                 :           8 :                     n->removeType = OBJECT_INDEX;
    7155                 :           8 :                     n->missing_ok = true;
    7156                 :           8 :                     n->objects = $6;
    7157                 :           8 :                     n->behavior = $7;
    7158                 :           8 :                     n->concurrent = true;
    7159                 :           8 :                     $$ = (Node *) n;
    7160                 :             :                 }
    7161                 :             :         ;
    7162                 :             : 
    7163                 :             : /* object types taking any_name/any_name_list */
    7164                 :             : object_type_any_name:
    7165                 :        9975 :             TABLE                                   { $$ = OBJECT_TABLE; }
    7166                 :         137 :             | SEQUENCE                              { $$ = OBJECT_SEQUENCE; }
    7167                 :         707 :             | VIEW                                  { $$ = OBJECT_VIEW; }
    7168                 :          86 :             | MATERIALIZED VIEW                     { $$ = OBJECT_MATVIEW; }
    7169                 :         518 :             | INDEX                                 { $$ = OBJECT_INDEX; }
    7170                 :         124 :             | FOREIGN TABLE                         { $$ = OBJECT_FOREIGN_TABLE; }
    7171                 :          63 :             | COLLATION                             { $$ = OBJECT_COLLATION; }
    7172                 :          37 :             | CONVERSION_P                          { $$ = OBJECT_CONVERSION; }
    7173                 :         157 :             | STATISTICS                            { $$ = OBJECT_STATISTIC_EXT; }
    7174                 :          13 :             | TEXT_P SEARCH PARSER                  { $$ = OBJECT_TSPARSER; }
    7175                 :        1786 :             | TEXT_P SEARCH DICTIONARY              { $$ = OBJECT_TSDICTIONARY; }
    7176                 :          70 :             | TEXT_P SEARCH TEMPLATE                { $$ = OBJECT_TSTEMPLATE; }
    7177                 :        1789 :             | TEXT_P SEARCH CONFIGURATION           { $$ = OBJECT_TSCONFIGURATION; }
    7178                 :             :         ;
    7179                 :             : 
    7180                 :             : /*
    7181                 :             :  * object types taking name/name_list
    7182                 :             :  *
    7183                 :             :  * DROP handles some of them separately
    7184                 :             :  */
    7185                 :             : 
    7186                 :             : object_type_name:
    7187                 :         143 :             drop_type_name                          { $$ = $1; }
    7188                 :         143 :             | DATABASE                              { $$ = OBJECT_DATABASE; }
    7189                 :          44 :             | ROLE                                  { $$ = OBJECT_ROLE; }
    7190                 :           6 :             | SUBSCRIPTION                          { $$ = OBJECT_SUBSCRIPTION; }
    7191                 :           0 :             | TABLESPACE                            { $$ = OBJECT_TABLESPACE; }
    7192                 :             :         ;
    7193                 :             : 
    7194                 :             : drop_type_name:
    7195                 :          29 :             ACCESS METHOD                           { $$ = OBJECT_ACCESS_METHOD; }
    7196                 :          85 :             | EVENT TRIGGER                         { $$ = OBJECT_EVENT_TRIGGER; }
    7197                 :         128 :             | EXTENSION                             { $$ = OBJECT_EXTENSION; }
    7198                 :         124 :             | FOREIGN DATA_P WRAPPER                { $$ = OBJECT_FDW; }
    7199                 :          90 :             | opt_procedural LANGUAGE               { $$ = OBJECT_LANGUAGE; }
    7200                 :         318 :             | PUBLICATION                           { $$ = OBJECT_PUBLICATION; }
    7201                 :         434 :             | SCHEMA                                { $$ = OBJECT_SCHEMA; }
    7202                 :         113 :             | SERVER                                { $$ = OBJECT_FOREIGN_SERVER; }
    7203                 :             :         ;
    7204                 :             : 
    7205                 :             : /* object types attached to a table */
    7206                 :             : object_type_name_on_any_name:
    7207                 :         122 :             POLICY                                  { $$ = OBJECT_POLICY; }
    7208                 :         197 :             | RULE                                  { $$ = OBJECT_RULE; }
    7209                 :         515 :             | TRIGGER                               { $$ = OBJECT_TRIGGER; }
    7210                 :             :         ;
    7211                 :             : 
    7212                 :             : any_name_list:
    7213                 :       17264 :             any_name                                { $$ = list_make1($1); }
    7214                 :        2697 :             | any_name_list ',' any_name            { $$ = lappend($1, $3); }
    7215                 :             :         ;
    7216                 :             : 
    7217                 :       43531 : any_name:   ColId                       { $$ = list_make1(makeString($1)); }
    7218                 :        6040 :             | ColId attrs               { $$ = lcons(makeString($1), $2); }
    7219                 :             :         ;
    7220                 :             : 
    7221                 :             : attrs:      '.' attr_name
    7222                 :       75337 :                     { $$ = list_make1(makeString($2)); }
    7223                 :             :             | attrs '.' attr_name
    7224                 :          36 :                     { $$ = lappend($1, makeString($3)); }
    7225                 :             :         ;
    7226                 :             : 
    7227                 :             : type_name_list:
    7228                 :         870 :             Typename                                { $$ = list_make1($1); }
    7229                 :          84 :             | type_name_list ',' Typename           { $$ = lappend($1, $3); }
    7230                 :             :         ;
    7231                 :             : 
    7232                 :             : /*****************************************************************************
    7233                 :             :  *
    7234                 :             :  *      QUERY:
    7235                 :             :  *              truncate table relname1, relname2, ...
    7236                 :             :  *
    7237                 :             :  *****************************************************************************/
    7238                 :             : 
    7239                 :             : TruncateStmt:
    7240                 :             :             TRUNCATE opt_table relation_expr_list opt_restart_seqs opt_drop_behavior
    7241                 :             :                 {
    7242                 :        1179 :                     TruncateStmt *n = makeNode(TruncateStmt);
    7243                 :             : 
    7244                 :        1179 :                     n->relations = $3;
    7245                 :        1179 :                     n->restart_seqs = $4;
    7246                 :        1179 :                     n->behavior = $5;
    7247                 :        1179 :                     $$ = (Node *) n;
    7248                 :             :                 }
    7249                 :             :         ;
    7250                 :             : 
    7251                 :             : opt_restart_seqs:
    7252                 :          12 :             CONTINUE_P IDENTITY_P       { $$ = false; }
    7253                 :          14 :             | RESTART IDENTITY_P        { $$ = true; }
    7254                 :        1153 :             | /* EMPTY */               { $$ = false; }
    7255                 :             :         ;
    7256                 :             : 
    7257                 :             : /*****************************************************************************
    7258                 :             :  *
    7259                 :             :  * COMMENT ON <object> IS <text>
    7260                 :             :  *
    7261                 :             :  *****************************************************************************/
    7262                 :             : 
    7263                 :             : CommentStmt:
    7264                 :             :             COMMENT ON object_type_any_name any_name IS comment_text
    7265                 :             :                 {
    7266                 :        3750 :                     CommentStmt *n = makeNode(CommentStmt);
    7267                 :             : 
    7268                 :        3750 :                     n->objtype = $3;
    7269                 :        3750 :                     n->object = (Node *) $4;
    7270                 :        3750 :                     n->comment = $6;
    7271                 :        3750 :                     $$ = (Node *) n;
    7272                 :             :                 }
    7273                 :             :             | COMMENT ON COLUMN any_name IS comment_text
    7274                 :             :                 {
    7275                 :          74 :                     CommentStmt *n = makeNode(CommentStmt);
    7276                 :             : 
    7277                 :          74 :                     n->objtype = OBJECT_COLUMN;
    7278                 :          74 :                     n->object = (Node *) $4;
    7279                 :          74 :                     n->comment = $6;
    7280                 :          74 :                     $$ = (Node *) n;
    7281                 :             :                 }
    7282                 :             :             | COMMENT ON object_type_name name IS comment_text
    7283                 :             :                 {
    7284                 :         301 :                     CommentStmt *n = makeNode(CommentStmt);
    7285                 :             : 
    7286                 :         301 :                     n->objtype = $3;
    7287                 :         301 :                     n->object = (Node *) makeString($4);
    7288                 :         301 :                     n->comment = $6;
    7289                 :         301 :                     $$ = (Node *) n;
    7290                 :             :                 }
    7291                 :             :             | COMMENT ON TYPE_P Typename IS comment_text
    7292                 :             :                 {
    7293                 :          31 :                     CommentStmt *n = makeNode(CommentStmt);
    7294                 :             : 
    7295                 :          31 :                     n->objtype = OBJECT_TYPE;
    7296                 :          31 :                     n->object = (Node *) $4;
    7297                 :          31 :                     n->comment = $6;
    7298                 :          31 :                     $$ = (Node *) n;
    7299                 :             :                 }
    7300                 :             :             | COMMENT ON DOMAIN_P Typename IS comment_text
    7301                 :             :                 {
    7302                 :           5 :                     CommentStmt *n = makeNode(CommentStmt);
    7303                 :             : 
    7304                 :           5 :                     n->objtype = OBJECT_DOMAIN;
    7305                 :           5 :                     n->object = (Node *) $4;
    7306                 :           5 :                     n->comment = $6;
    7307                 :           5 :                     $$ = (Node *) n;
    7308                 :             :                 }
    7309                 :             :             | COMMENT ON AGGREGATE aggregate_with_argtypes IS comment_text
    7310                 :             :                 {
    7311                 :          26 :                     CommentStmt *n = makeNode(CommentStmt);
    7312                 :             : 
    7313                 :          26 :                     n->objtype = OBJECT_AGGREGATE;
    7314                 :          26 :                     n->object = (Node *) $4;
    7315                 :          26 :                     n->comment = $6;
    7316                 :          26 :                     $$ = (Node *) n;
    7317                 :             :                 }
    7318                 :             :             | COMMENT ON FUNCTION function_with_argtypes IS comment_text
    7319                 :             :                 {
    7320                 :          91 :                     CommentStmt *n = makeNode(CommentStmt);
    7321                 :             : 
    7322                 :          91 :                     n->objtype = OBJECT_FUNCTION;
    7323                 :          91 :                     n->object = (Node *) $4;
    7324                 :          91 :                     n->comment = $6;
    7325                 :          91 :                     $$ = (Node *) n;
    7326                 :             :                 }
    7327                 :             :             | COMMENT ON OPERATOR operator_with_argtypes IS comment_text
    7328                 :             :                 {
    7329                 :          12 :                     CommentStmt *n = makeNode(CommentStmt);
    7330                 :             : 
    7331                 :          12 :                     n->objtype = OBJECT_OPERATOR;
    7332                 :          12 :                     n->object = (Node *) $4;
    7333                 :          12 :                     n->comment = $6;
    7334                 :          12 :                     $$ = (Node *) n;
    7335                 :             :                 }
    7336                 :             :             | COMMENT ON CONSTRAINT name ON any_name IS comment_text
    7337                 :             :                 {
    7338                 :          97 :                     CommentStmt *n = makeNode(CommentStmt);
    7339                 :             : 
    7340                 :          97 :                     n->objtype = OBJECT_TABCONSTRAINT;
    7341                 :          97 :                     n->object = (Node *) lappend($6, makeString($4));
    7342                 :          97 :                     n->comment = $8;
    7343                 :          97 :                     $$ = (Node *) n;
    7344                 :             :                 }
    7345                 :             :             | COMMENT ON CONSTRAINT name ON DOMAIN_P any_name IS comment_text
    7346                 :             :                 {
    7347                 :          31 :                     CommentStmt *n = makeNode(CommentStmt);
    7348                 :             : 
    7349                 :          31 :                     n->objtype = OBJECT_DOMCONSTRAINT;
    7350                 :             :                     /*
    7351                 :             :                      * should use Typename not any_name in the production, but
    7352                 :             :                      * there's a shift/reduce conflict if we do that, so fix it
    7353                 :             :                      * up here.
    7354                 :             :                      */
    7355                 :          31 :                     n->object = (Node *) list_make2(makeTypeNameFromNameList($7), makeString($4));
    7356                 :          31 :                     n->comment = $9;
    7357                 :          31 :                     $$ = (Node *) n;
    7358                 :             :                 }
    7359                 :             :             | COMMENT ON object_type_name_on_any_name name ON any_name IS comment_text
    7360                 :             :                 {
    7361                 :          27 :                     CommentStmt *n = makeNode(CommentStmt);
    7362                 :             : 
    7363                 :          27 :                     n->objtype = $3;
    7364                 :          27 :                     n->object = (Node *) lappend($6, makeString($4));
    7365                 :          27 :                     n->comment = $8;
    7366                 :          27 :                     $$ = (Node *) n;
    7367                 :             :                 }
    7368                 :             :             | COMMENT ON PROCEDURE function_with_argtypes IS comment_text
    7369                 :             :                 {
    7370                 :           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7371                 :             : 
    7372                 :           0 :                     n->objtype = OBJECT_PROCEDURE;
    7373                 :           0 :                     n->object = (Node *) $4;
    7374                 :           0 :                     n->comment = $6;
    7375                 :           0 :                     $$ = (Node *) n;
    7376                 :             :                 }
    7377                 :             :             | COMMENT ON ROUTINE function_with_argtypes IS comment_text
    7378                 :             :                 {
    7379                 :           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7380                 :             : 
    7381                 :           0 :                     n->objtype = OBJECT_ROUTINE;
    7382                 :           0 :                     n->object = (Node *) $4;
    7383                 :           0 :                     n->comment = $6;
    7384                 :           0 :                     $$ = (Node *) n;
    7385                 :             :                 }
    7386                 :             :             | COMMENT ON TRANSFORM FOR Typename LANGUAGE name IS comment_text
    7387                 :             :                 {
    7388                 :           7 :                     CommentStmt *n = makeNode(CommentStmt);
    7389                 :             : 
    7390                 :           7 :                     n->objtype = OBJECT_TRANSFORM;
    7391                 :           7 :                     n->object = (Node *) list_make2($5, makeString($7));
    7392                 :           7 :                     n->comment = $9;
    7393                 :           7 :                     $$ = (Node *) n;
    7394                 :             :                 }
    7395                 :             :             | COMMENT ON OPERATOR CLASS any_name USING name IS comment_text
    7396                 :             :                 {
    7397                 :           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7398                 :             : 
    7399                 :           0 :                     n->objtype = OBJECT_OPCLASS;
    7400                 :           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7401                 :           0 :                     n->comment = $9;
    7402                 :           0 :                     $$ = (Node *) n;
    7403                 :             :                 }
    7404                 :             :             | COMMENT ON OPERATOR FAMILY any_name USING name IS comment_text
    7405                 :             :                 {
    7406                 :           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7407                 :             : 
    7408                 :           0 :                     n->objtype = OBJECT_OPFAMILY;
    7409                 :           0 :                     n->object = (Node *) lcons(makeString($7), $5);
    7410                 :           0 :                     n->comment = $9;
    7411                 :           0 :                     $$ = (Node *) n;
    7412                 :             :                 }
    7413                 :             :             | COMMENT ON LARGE_P OBJECT_P NumericOnly IS comment_text
    7414                 :             :                 {
    7415                 :          24 :                     CommentStmt *n = makeNode(CommentStmt);
    7416                 :             : 
    7417                 :          24 :                     n->objtype = OBJECT_LARGEOBJECT;
    7418                 :          24 :                     n->object = (Node *) $5;
    7419                 :          24 :                     n->comment = $7;
    7420                 :          24 :                     $$ = (Node *) n;
    7421                 :             :                 }
    7422                 :             :             | COMMENT ON CAST '(' Typename AS Typename ')' IS comment_text
    7423                 :             :                 {
    7424                 :           0 :                     CommentStmt *n = makeNode(CommentStmt);
    7425                 :             : 
    7426                 :           0 :                     n->objtype = OBJECT_CAST;
    7427                 :           0 :                     n->object = (Node *) list_make2($5, $7);
    7428                 :           0 :                     n->comment = $10;
    7429                 :           0 :                     $$ = (Node *) n;
    7430                 :             :                 }
    7431                 :             :         ;
    7432                 :             : 
    7433                 :             : comment_text:
    7434                 :        4403 :             Sconst                              { $$ = $1; }
    7435                 :          73 :             | NULL_P                            { $$ = NULL; }
    7436                 :             :         ;
    7437                 :             : 
    7438                 :             : 
    7439                 :             : /*****************************************************************************
    7440                 :             :  *
    7441                 :             :  *  SECURITY LABEL [FOR <provider>] ON <object> IS <label>
    7442                 :             :  *
    7443                 :             :  *  As with COMMENT ON, <object> can refer to various types of database
    7444                 :             :  *  objects (e.g. TABLE, COLUMN, etc.).
    7445                 :             :  *
    7446                 :             :  *****************************************************************************/
    7447                 :             : 
    7448                 :             : SecLabelStmt:
    7449                 :             :             SECURITY LABEL opt_provider ON object_type_any_name any_name
    7450                 :             :             IS security_label
    7451                 :             :                 {
    7452                 :          28 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7453                 :             : 
    7454                 :          28 :                     n->provider = $3;
    7455                 :          28 :                     n->objtype = $5;
    7456                 :          28 :                     n->object = (Node *) $6;
    7457                 :          28 :                     n->label = $8;
    7458                 :          28 :                     $$ = (Node *) n;
    7459                 :             :                 }
    7460                 :             :             | SECURITY LABEL opt_provider ON COLUMN any_name
    7461                 :             :               IS security_label
    7462                 :             :                 {
    7463                 :           2 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7464                 :             : 
    7465                 :           2 :                     n->provider = $3;
    7466                 :           2 :                     n->objtype = OBJECT_COLUMN;
    7467                 :           2 :                     n->object = (Node *) $6;
    7468                 :           2 :                     n->label = $8;
    7469                 :           2 :                     $$ = (Node *) n;
    7470                 :             :                 }
    7471                 :             :             | SECURITY LABEL opt_provider ON object_type_name name
    7472                 :             :               IS security_label
    7473                 :             :                 {
    7474                 :          26 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7475                 :             : 
    7476                 :          26 :                     n->provider = $3;
    7477                 :          26 :                     n->objtype = $5;
    7478                 :          26 :                     n->object = (Node *) makeString($6);
    7479                 :          26 :                     n->label = $8;
    7480                 :          26 :                     $$ = (Node *) n;
    7481                 :             :                 }
    7482                 :             :             | SECURITY LABEL opt_provider ON TYPE_P Typename
    7483                 :             :               IS security_label
    7484                 :             :                 {
    7485                 :           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7486                 :             : 
    7487                 :           0 :                     n->provider = $3;
    7488                 :           0 :                     n->objtype = OBJECT_TYPE;
    7489                 :           0 :                     n->object = (Node *) $6;
    7490                 :           0 :                     n->label = $8;
    7491                 :           0 :                     $$ = (Node *) n;
    7492                 :             :                 }
    7493                 :             :             | SECURITY LABEL opt_provider ON DOMAIN_P Typename
    7494                 :             :               IS security_label
    7495                 :             :                 {
    7496                 :           1 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7497                 :             : 
    7498                 :           1 :                     n->provider = $3;
    7499                 :           1 :                     n->objtype = OBJECT_DOMAIN;
    7500                 :           1 :                     n->object = (Node *) $6;
    7501                 :           1 :                     n->label = $8;
    7502                 :           1 :                     $$ = (Node *) n;
    7503                 :             :                 }
    7504                 :             :             | SECURITY LABEL opt_provider ON AGGREGATE aggregate_with_argtypes
    7505                 :             :               IS security_label
    7506                 :             :                 {
    7507                 :           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7508                 :             : 
    7509                 :           0 :                     n->provider = $3;
    7510                 :           0 :                     n->objtype = OBJECT_AGGREGATE;
    7511                 :           0 :                     n->object = (Node *) $6;
    7512                 :           0 :                     n->label = $8;
    7513                 :           0 :                     $$ = (Node *) n;
    7514                 :             :                 }
    7515                 :             :             | SECURITY LABEL opt_provider ON FUNCTION function_with_argtypes
    7516                 :             :               IS security_label
    7517                 :             :                 {
    7518                 :           1 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7519                 :             : 
    7520                 :           1 :                     n->provider = $3;
    7521                 :           1 :                     n->objtype = OBJECT_FUNCTION;
    7522                 :           1 :                     n->object = (Node *) $6;
    7523                 :           1 :                     n->label = $8;
    7524                 :           1 :                     $$ = (Node *) n;
    7525                 :             :                 }
    7526                 :             :             | SECURITY LABEL opt_provider ON LARGE_P OBJECT_P NumericOnly
    7527                 :             :               IS security_label
    7528                 :             :                 {
    7529                 :           9 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7530                 :             : 
    7531                 :           9 :                     n->provider = $3;
    7532                 :           9 :                     n->objtype = OBJECT_LARGEOBJECT;
    7533                 :           9 :                     n->object = (Node *) $7;
    7534                 :           9 :                     n->label = $9;
    7535                 :           9 :                     $$ = (Node *) n;
    7536                 :             :                 }
    7537                 :             :             | SECURITY LABEL opt_provider ON PROCEDURE function_with_argtypes
    7538                 :             :               IS security_label
    7539                 :             :                 {
    7540                 :           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7541                 :             : 
    7542                 :           0 :                     n->provider = $3;
    7543                 :           0 :                     n->objtype = OBJECT_PROCEDURE;
    7544                 :           0 :                     n->object = (Node *) $6;
    7545                 :           0 :                     n->label = $8;
    7546                 :           0 :                     $$ = (Node *) n;
    7547                 :             :                 }
    7548                 :             :             | SECURITY LABEL opt_provider ON ROUTINE function_with_argtypes
    7549                 :             :               IS security_label
    7550                 :             :                 {
    7551                 :           0 :                     SecLabelStmt *n = makeNode(SecLabelStmt);
    7552                 :             : 
    7553                 :           0 :                     n->provider = $3;
    7554                 :           0 :                     n->objtype = OBJECT_ROUTINE;
    7555                 :           0 :                     n->object = (Node *) $6;
    7556                 :           0 :                     n->label = $8;
    7557                 :           0 :                     $$ = (Node *) n;
    7558                 :             :                 }
    7559                 :             :         ;
    7560                 :             : 
    7561                 :          16 : opt_provider:   FOR NonReservedWord_or_Sconst   { $$ = $2; }
    7562                 :          51 :                 | /* EMPTY */                   { $$ = NULL; }
    7563                 :             :         ;
    7564                 :             : 
    7565                 :          67 : security_label: Sconst              { $$ = $1; }
    7566                 :           0 :                 | NULL_P            { $$ = NULL; }
    7567                 :             :         ;
    7568                 :             : 
    7569                 :             : /*****************************************************************************
    7570                 :             :  *
    7571                 :             :  *      QUERY:
    7572                 :             :  *          fetch/move
    7573                 :             :  *
    7574                 :             :  *****************************************************************************/
    7575                 :             : 
    7576                 :             : FetchStmt:  FETCH fetch_args
    7577                 :             :                 {
    7578                 :        4444 :                     FetchStmt *n = (FetchStmt *) $2;
    7579                 :             : 
    7580                 :        4444 :                     n->ismove = false;
    7581                 :        4444 :                     $$ = (Node *) n;
    7582                 :             :                 }
    7583                 :             :             | MOVE fetch_args
    7584                 :             :                 {
    7585                 :          58 :                     FetchStmt *n = (FetchStmt *) $2;
    7586                 :             : 
    7587                 :          58 :                     n->ismove = true;
    7588                 :          58 :                     $$ = (Node *) n;
    7589                 :             :                 }
    7590                 :             :         ;
    7591                 :             : 
    7592                 :             : fetch_args: cursor_name
    7593                 :             :                 {
    7594                 :         142 :                     FetchStmt *n = makeNode(FetchStmt);
    7595                 :             : 
    7596                 :         142 :                     n->portalname = $1;
    7597                 :         142 :                     n->direction = FETCH_FORWARD;
    7598                 :         142 :                     n->howMany = 1;
    7599                 :         142 :                     n->location = -1;
    7600                 :         142 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7601                 :         142 :                     $$ = (Node *) n;
    7602                 :             :                 }
    7603                 :             :             | from_in cursor_name
    7604                 :             :                 {
    7605                 :         128 :                     FetchStmt *n = makeNode(FetchStmt);
    7606                 :             : 
    7607                 :         128 :                     n->portalname = $2;
    7608                 :         128 :                     n->direction = FETCH_FORWARD;
    7609                 :         128 :                     n->howMany = 1;
    7610                 :         128 :                     n->location = -1;
    7611                 :         128 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7612                 :         128 :                     $$ = (Node *) n;
    7613                 :             :                 }
    7614                 :             :             | SignedIconst opt_from_in cursor_name
    7615                 :             :                 {
    7616                 :        2289 :                     FetchStmt *n = makeNode(FetchStmt);
    7617                 :             : 
    7618                 :        2289 :                     n->portalname = $3;
    7619                 :        2289 :                     n->direction = FETCH_FORWARD;
    7620                 :        2289 :                     n->howMany = $1;
    7621                 :        2289 :                     n->location = @1;
    7622                 :        2289 :                     n->direction_keyword = FETCH_KEYWORD_NONE;
    7623                 :        2289 :                     $$ = (Node *) n;
    7624                 :             :                 }
    7625                 :             :             | NEXT opt_from_in cursor_name
    7626                 :             :                 {
    7627                 :        1312 :                     FetchStmt *n = makeNode(FetchStmt);
    7628                 :             : 
    7629                 :        1312 :                     n->portalname = $3;
    7630                 :        1312 :                     n->direction = FETCH_FORWARD;
    7631                 :        1312 :                     n->howMany = 1;
    7632                 :        1312 :                     n->location = -1;
    7633                 :        1312 :                     n->direction_keyword = FETCH_KEYWORD_NEXT;
    7634                 :        1312 :                     $$ = (Node *) n;
    7635                 :             :                 }
    7636                 :             :             | PRIOR opt_from_in cursor_name
    7637                 :             :                 {
    7638                 :          21 :                     FetchStmt *n = makeNode(FetchStmt);
    7639                 :             : 
    7640                 :          21 :                     n->portalname = $3;
    7641                 :          21 :                     n->direction = FETCH_BACKWARD;
    7642                 :          21 :                     n->howMany = 1;
    7643                 :          21 :                     n->location = -1;
    7644                 :          21 :                     n->direction_keyword = FETCH_KEYWORD_PRIOR;
    7645                 :          21 :                     $$ = (Node *) n;
    7646                 :             :                 }
    7647                 :             :             | FIRST_P opt_from_in cursor_name
    7648                 :             :                 {
    7649                 :          17 :                     FetchStmt *n = makeNode(FetchStmt);
    7650                 :             : 
    7651                 :          17 :                     n->portalname = $3;
    7652                 :          17 :                     n->direction = FETCH_ABSOLUTE;
    7653                 :          17 :                     n->howMany = 1;
    7654                 :          17 :                     n->location = -1;
    7655                 :          17 :                     n->direction_keyword = FETCH_KEYWORD_FIRST;
    7656                 :          17 :                     $$ = (Node *) n;
    7657                 :             :                 }
    7658                 :             :             | LAST_P opt_from_in cursor_name
    7659                 :             :                 {
    7660                 :          13 :                     FetchStmt *n = makeNode(FetchStmt);
    7661                 :             : 
    7662                 :          13 :                     n->portalname = $3;
    7663                 :          13 :                     n->direction = FETCH_ABSOLUTE;
    7664                 :          13 :                     n->howMany = -1;
    7665                 :          13 :                     n->location = -1;
    7666                 :          13 :                     n->direction_keyword = FETCH_KEYWORD_LAST;
    7667                 :          13 :                     $$ = (Node *) n;
    7668                 :             :                 }
    7669                 :             :             | ABSOLUTE_P SignedIconst opt_from_in cursor_name
    7670                 :             :                 {
    7671                 :          59 :                     FetchStmt *n = makeNode(FetchStmt);
    7672                 :             : 
    7673                 :          59 :                     n->portalname = $4;
    7674                 :          59 :                     n->direction = FETCH_ABSOLUTE;
    7675                 :          59 :                     n->howMany = $2;
    7676                 :          59 :                     n->location = @2;
    7677                 :          59 :                     n->direction_keyword = FETCH_KEYWORD_ABSOLUTE;
    7678                 :          59 :                     $$ = (Node *) n;
    7679                 :             :                 }
    7680                 :             :             | RELATIVE_P SignedIconst opt_from_in cursor_name
    7681                 :             :                 {
    7682                 :          23 :                     FetchStmt *n = makeNode(FetchStmt);
    7683                 :             : 
    7684                 :          23 :                     n->portalname = $4;
    7685                 :          23 :                     n->direction = FETCH_RELATIVE;
    7686                 :          23 :                     n->howMany = $2;
    7687                 :          23 :                     n->location = @2;
    7688                 :          23 :                     n->direction_keyword = FETCH_KEYWORD_RELATIVE;
    7689                 :          23 :                     $$ = (Node *) n;
    7690                 :             :                 }
    7691                 :             :             | ALL opt_from_in cursor_name
    7692                 :             :                 {
    7693                 :         176 :                     FetchStmt *n = makeNode(FetchStmt);
    7694                 :             : 
    7695                 :         176 :                     n->portalname = $3;
    7696                 :         176 :                     n->direction = FETCH_FORWARD;
    7697                 :         176 :                     n->howMany = FETCH_ALL;
    7698                 :         176 :                     n->location = -1;
    7699                 :         176 :                     n->direction_keyword = FETCH_KEYWORD_ALL;
    7700                 :         176 :                     $$ = (Node *) n;
    7701                 :             :                 }
    7702                 :             :             | FORWARD opt_from_in cursor_name
    7703                 :             :                 {
    7704                 :          15 :                     FetchStmt *n = makeNode(FetchStmt);
    7705                 :             : 
    7706                 :          15 :                     n->portalname = $3;
    7707                 :          15 :                     n->direction = FETCH_FORWARD;
    7708                 :          15 :                     n->howMany = 1;
    7709                 :          15 :                     n->location = -1;
    7710                 :          15 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7711                 :          15 :                     $$ = (Node *) n;
    7712                 :             :                 }
    7713                 :             :             | FORWARD SignedIconst opt_from_in cursor_name
    7714                 :             :                 {
    7715                 :          14 :                     FetchStmt *n = makeNode(FetchStmt);
    7716                 :             : 
    7717                 :          14 :                     n->portalname = $4;
    7718                 :          14 :                     n->direction = FETCH_FORWARD;
    7719                 :          14 :                     n->howMany = $2;
    7720                 :          14 :                     n->location = @2;
    7721                 :          14 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD;
    7722                 :          14 :                     $$ = (Node *) n;
    7723                 :             :                 }
    7724                 :             :             | FORWARD ALL opt_from_in cursor_name
    7725                 :             :                 {
    7726                 :          14 :                     FetchStmt *n = makeNode(FetchStmt);
    7727                 :             : 
    7728                 :          14 :                     n->portalname = $4;
    7729                 :          14 :                     n->direction = FETCH_FORWARD;
    7730                 :          14 :                     n->howMany = FETCH_ALL;
    7731                 :          14 :                     n->location = -1;
    7732                 :          14 :                     n->direction_keyword = FETCH_KEYWORD_FORWARD_ALL;
    7733                 :          14 :                     $$ = (Node *) n;
    7734                 :             :                 }
    7735                 :             :             | BACKWARD opt_from_in cursor_name
    7736                 :             :                 {
    7737                 :          53 :                     FetchStmt *n = makeNode(FetchStmt);
    7738                 :             : 
    7739                 :          53 :                     n->portalname = $3;
    7740                 :          53 :                     n->direction = FETCH_BACKWARD;
    7741                 :          53 :                     n->howMany = 1;
    7742                 :          53 :                     n->location = -1;
    7743                 :          53 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7744                 :          53 :                     $$ = (Node *) n;
    7745                 :             :                 }
    7746                 :             :             | BACKWARD SignedIconst opt_from_in cursor_name
    7747                 :             :                 {
    7748                 :         161 :                     FetchStmt *n = makeNode(FetchStmt);
    7749                 :             : 
    7750                 :         161 :                     n->portalname = $4;
    7751                 :         161 :                     n->direction = FETCH_BACKWARD;
    7752                 :         161 :                     n->howMany = $2;
    7753                 :         161 :                     n->location = @2;
    7754                 :         161 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD;
    7755                 :         161 :                     $$ = (Node *) n;
    7756                 :             :                 }
    7757                 :             :             | BACKWARD ALL opt_from_in cursor_name
    7758                 :             :                 {
    7759                 :          65 :                     FetchStmt *n = makeNode(FetchStmt);
    7760                 :             : 
    7761                 :          65 :                     n->portalname = $4;
    7762                 :          65 :                     n->direction = FETCH_BACKWARD;
    7763                 :          65 :                     n->howMany = FETCH_ALL;
    7764                 :          65 :                     n->location = -1;
    7765                 :          65 :                     n->direction_keyword = FETCH_KEYWORD_BACKWARD_ALL;
    7766                 :          65 :                     $$ = (Node *) n;
    7767                 :             :                 }
    7768                 :             :         ;
    7769                 :             : 
    7770                 :             : from_in:    FROM
    7771                 :             :             | IN_P
    7772                 :             :         ;
    7773                 :             : 
    7774                 :             : opt_from_in:    from_in
    7775                 :             :             | /* EMPTY */
    7776                 :             :         ;
    7777                 :             : 
    7778                 :             : 
    7779                 :             : /*****************************************************************************
    7780                 :             :  *
    7781                 :             :  * GRANT and REVOKE statements
    7782                 :             :  *
    7783                 :             :  *****************************************************************************/
    7784                 :             : 
    7785                 :             : GrantStmt:  GRANT privileges ON privilege_target TO grantee_list
    7786                 :             :             opt_grant_grant_option opt_granted_by
    7787                 :             :                 {
    7788                 :        6271 :                     GrantStmt *n = makeNode(GrantStmt);
    7789                 :             : 
    7790                 :        6271 :                     n->is_grant = true;
    7791                 :        6271 :                     n->privileges = $2;
    7792                 :        6271 :                     n->targtype = ($4)->targtype;
    7793                 :        6271 :                     n->objtype = ($4)->objtype;
    7794                 :        6271 :                     n->objects = ($4)->objs;
    7795                 :        6271 :                     n->grantees = $6;
    7796                 :        6271 :                     n->grant_option = $7;
    7797                 :        6271 :                     n->grantor = $8;
    7798                 :        6271 :                     $$ = (Node *) n;
    7799                 :             :                 }
    7800                 :             :         ;
    7801                 :             : 
    7802                 :             : RevokeStmt:
    7803                 :             :             REVOKE privileges ON privilege_target
    7804                 :             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7805                 :             :                 {
    7806                 :        2405 :                     GrantStmt *n = makeNode(GrantStmt);
    7807                 :             : 
    7808                 :        2405 :                     n->is_grant = false;
    7809                 :        2405 :                     n->grant_option = false;
    7810                 :        2405 :                     n->privileges = $2;
    7811                 :        2405 :                     n->targtype = ($4)->targtype;
    7812                 :        2405 :                     n->objtype = ($4)->objtype;
    7813                 :        2405 :                     n->objects = ($4)->objs;
    7814                 :        2405 :                     n->grantees = $6;
    7815                 :        2405 :                     n->grantor = $7;
    7816                 :        2405 :                     n->behavior = $8;
    7817                 :        2405 :                     $$ = (Node *) n;
    7818                 :             :                 }
    7819                 :             :             | REVOKE GRANT OPTION FOR privileges ON privilege_target
    7820                 :             :             FROM grantee_list opt_granted_by opt_drop_behavior
    7821                 :             :                 {
    7822                 :           9 :                     GrantStmt *n = makeNode(GrantStmt);
    7823                 :             : 
    7824                 :           9 :                     n->is_grant = false;
    7825                 :           9 :                     n->grant_option = true;
    7826                 :           9 :                     n->privileges = $5;
    7827                 :           9 :                     n->targtype = ($7)->targtype;
    7828                 :           9 :                     n->objtype = ($7)->objtype;
    7829                 :           9 :                     n->objects = ($7)->objs;
    7830                 :           9 :                     n->grantees = $9;
    7831                 :           9 :                     n->grantor = $10;
    7832                 :           9 :                     n->behavior = $11;
    7833                 :           9 :                     $$ = (Node *) n;
    7834                 :             :                 }
    7835                 :             :         ;
    7836                 :             : 
    7837                 :             : 
    7838                 :             : /*
    7839                 :             :  * Privilege names are represented as strings; the validity of the privilege
    7840                 :             :  * names gets checked at execution.  This is a bit annoying but we have little
    7841                 :             :  * choice because of the syntactic conflict with lists of role names in
    7842                 :             :  * GRANT/REVOKE.  What's more, we have to call out in the "privilege"
    7843                 :             :  * production any reserved keywords that need to be usable as privilege names.
    7844                 :             :  */
    7845                 :             : 
    7846                 :             : /* either ALL [PRIVILEGES] or a list of individual privileges */
    7847                 :             : privileges: privilege_list
    7848                 :        7091 :                 { $$ = $1; }
    7849                 :             :             | ALL
    7850                 :        1655 :                 { $$ = NIL; }
    7851                 :             :             | ALL PRIVILEGES
    7852                 :          68 :                 { $$ = NIL; }
    7853                 :             :             | ALL '(' columnList ')'
    7854                 :             :                 {
    7855                 :          12 :                     AccessPriv *n = makeNode(AccessPriv);
    7856                 :             : 
    7857                 :          12 :                     n->priv_name = NULL;
    7858                 :          12 :                     n->cols = $3;
    7859                 :          12 :                     $$ = list_make1(n);
    7860                 :             :                 }
    7861                 :             :             | ALL PRIVILEGES '(' columnList ')'
    7862                 :             :                 {
    7863                 :           0 :                     AccessPriv *n = makeNode(AccessPriv);
    7864                 :             : 
    7865                 :           0 :                     n->priv_name = NULL;
    7866                 :           0 :                     n->cols = $4;
    7867                 :           0 :                     $$ = list_make1(n);
    7868                 :             :                 }
    7869                 :             :         ;
    7870                 :             : 
    7871                 :        7522 : privilege_list: privilege                           { $$ = list_make1($1); }
    7872                 :         396 :             | privilege_list ',' privilege          { $$ = lappend($1, $3); }
    7873                 :             :         ;
    7874                 :             : 
    7875                 :             : privilege:  SELECT opt_column_list
    7876                 :             :             {
    7877                 :        5627 :                 AccessPriv *n = makeNode(AccessPriv);
    7878                 :             : 
    7879                 :        5627 :                 n->priv_name = pstrdup($1);
    7880                 :        5627 :                 n->cols = $2;
    7881                 :        5627 :                 $$ = n;
    7882                 :             :             }
    7883                 :             :         | REFERENCES opt_column_list
    7884                 :             :             {
    7885                 :          17 :                 AccessPriv *n = makeNode(AccessPriv);
    7886                 :             : 
    7887                 :          17 :                 n->priv_name = pstrdup($1);
    7888                 :          17 :                 n->cols = $2;
    7889                 :          17 :                 $$ = n;
    7890                 :             :             }
    7891                 :             :         | CREATE opt_column_list
    7892                 :             :             {
    7893                 :         215 :                 AccessPriv *n = makeNode(AccessPriv);
    7894                 :             : 
    7895                 :         215 :                 n->priv_name = pstrdup($1);
    7896                 :         215 :                 n->cols = $2;
    7897                 :         215 :                 $$ = n;
    7898                 :             :             }
    7899                 :             :         | ALTER SYSTEM_P
    7900                 :             :             {
    7901                 :          12 :                 AccessPriv *n = makeNode(AccessPriv);
    7902                 :          12 :                 n->priv_name = pstrdup("alter system");
    7903                 :          12 :                 n->cols = NIL;
    7904                 :          12 :                 $$ = n;
    7905                 :             :             }
    7906                 :             :         | ColId opt_column_list
    7907                 :             :             {
    7908                 :        2047 :                 AccessPriv *n = makeNode(AccessPriv);
    7909                 :             : 
    7910                 :        2047 :                 n->priv_name = $1;
    7911                 :        2047 :                 n->cols = $2;
    7912                 :        2047 :                 $$ = n;
    7913                 :             :             }
    7914                 :             :         ;
    7915                 :             : 
    7916                 :             : parameter_name_list:
    7917                 :             :         parameter_name
    7918                 :             :             {
    7919                 :          38 :                 $$ = list_make1(makeString($1));
    7920                 :             :             }
    7921                 :             :         | parameter_name_list ',' parameter_name
    7922                 :             :             {
    7923                 :          25 :                 $$ = lappend($1, makeString($3));
    7924                 :             :             }
    7925                 :             :         ;
    7926                 :             : 
    7927                 :             : parameter_name:
    7928                 :             :         ColId
    7929                 :             :             {
    7930                 :          63 :                 $$ = $1;
    7931                 :             :             }
    7932                 :             :         | parameter_name '.' ColId
    7933                 :             :             {
    7934                 :          16 :                 $$ = psprintf("%s.%s", $1, $3);
    7935                 :             :             }
    7936                 :             :         ;
    7937                 :             : 
    7938                 :             : 
    7939                 :             : /* Don't bother trying to fold the first two rules into one using
    7940                 :             :  * opt_table.  You're going to get conflicts.
    7941                 :             :  */
    7942                 :             : privilege_target:
    7943                 :             :             qualified_name_list
    7944                 :             :                 {
    7945                 :        6937 :                     PrivTarget *n = palloc_object(PrivTarget);
    7946                 :             : 
    7947                 :        6937 :                     n->targtype = ACL_TARGET_OBJECT;
    7948                 :        6937 :                     n->objtype = OBJECT_TABLE;
    7949                 :        6937 :                     n->objs = $1;
    7950                 :        6937 :                     $$ = n;
    7951                 :             :                 }
    7952                 :             :             | TABLE qualified_name_list
    7953                 :             :                 {
    7954                 :         232 :                     PrivTarget *n = palloc_object(PrivTarget);
    7955                 :             : 
    7956                 :         232 :                     n->targtype = ACL_TARGET_OBJECT;
    7957                 :         232 :                     n->objtype = OBJECT_TABLE;
    7958                 :         232 :                     n->objs = $2;
    7959                 :         232 :                     $$ = n;
    7960                 :             :                 }
    7961                 :             :             | SEQUENCE qualified_name_list
    7962                 :             :                 {
    7963                 :          12 :                     PrivTarget *n = palloc_object(PrivTarget);
    7964                 :             : 
    7965                 :          12 :                     n->targtype = ACL_TARGET_OBJECT;
    7966                 :          12 :                     n->objtype = OBJECT_SEQUENCE;
    7967                 :          12 :                     n->objs = $2;
    7968                 :          12 :                     $$ = n;
    7969                 :             :                 }
    7970                 :             :             | FOREIGN DATA_P WRAPPER name_list
    7971                 :             :                 {
    7972                 :          60 :                     PrivTarget *n = palloc_object(PrivTarget);
    7973                 :             : 
    7974                 :          60 :                     n->targtype = ACL_TARGET_OBJECT;
    7975                 :          60 :                     n->objtype = OBJECT_FDW;
    7976                 :          60 :                     n->objs = $4;
    7977                 :          60 :                     $$ = n;
    7978                 :             :                 }
    7979                 :             :             | FOREIGN SERVER name_list
    7980                 :             :                 {
    7981                 :          70 :                     PrivTarget *n = palloc_object(PrivTarget);
    7982                 :             : 
    7983                 :          70 :                     n->targtype = ACL_TARGET_OBJECT;
    7984                 :          70 :                     n->objtype = OBJECT_FOREIGN_SERVER;
    7985                 :          70 :                     n->objs = $3;
    7986                 :          70 :                     $$ = n;
    7987                 :             :                 }
    7988                 :             :             | FUNCTION function_with_argtypes_list
    7989                 :             :                 {
    7990                 :         545 :                     PrivTarget *n = palloc_object(PrivTarget);
    7991                 :             : 
    7992                 :         545 :                     n->targtype = ACL_TARGET_OBJECT;
    7993                 :         545 :                     n->objtype = OBJECT_FUNCTION;
    7994                 :         545 :                     n->objs = $2;
    7995                 :         545 :                     $$ = n;
    7996                 :             :                 }
    7997                 :             :             | PROCEDURE function_with_argtypes_list
    7998                 :             :                 {
    7999                 :          28 :                     PrivTarget *n = palloc_object(PrivTarget);
    8000                 :             : 
    8001                 :          28 :                     n->targtype = ACL_TARGET_OBJECT;
    8002                 :          28 :                     n->objtype = OBJECT_PROCEDURE;
    8003                 :          28 :                     n->objs = $2;
    8004                 :          28 :                     $$ = n;
    8005                 :             :                 }
    8006                 :             :             | ROUTINE function_with_argtypes_list
    8007                 :             :                 {
    8008                 :           0 :                     PrivTarget *n = palloc_object(PrivTarget);
    8009                 :             : 
    8010                 :           0 :                     n->targtype = ACL_TARGET_OBJECT;
    8011                 :           0 :                     n->objtype = OBJECT_ROUTINE;
    8012                 :           0 :                     n->objs = $2;
    8013                 :           0 :                     $$ = n;
    8014                 :             :                 }
    8015                 :             :             | DATABASE name_list
    8016                 :             :                 {
    8017                 :         218 :                     PrivTarget *n = palloc_object(PrivTarget);
    8018                 :             : 
    8019                 :         218 :                     n->targtype = ACL_TARGET_OBJECT;
    8020                 :         218 :                     n->objtype = OBJECT_DATABASE;
    8021                 :         218 :                     n->objs = $2;
    8022                 :         218 :                     $$ = n;
    8023                 :             :                 }
    8024                 :             :             | DOMAIN_P any_name_list
    8025                 :             :                 {
    8026                 :          17 :                     PrivTarget *n = palloc_object(PrivTarget);
    8027                 :             : 
    8028                 :          17 :                     n->targtype = ACL_TARGET_OBJECT;
    8029                 :          17 :                     n->objtype = OBJECT_DOMAIN;
    8030                 :          17 :                     n->objs = $2;
    8031                 :          17 :                     $$ = n;
    8032                 :             :                 }
    8033                 :             :             | LANGUAGE name_list
    8034                 :             :                 {
    8035                 :          27 :                     PrivTarget *n = palloc_object(PrivTarget);
    8036                 :             : 
    8037                 :          27 :                     n->targtype = ACL_TARGET_OBJECT;
    8038                 :          27 :                     n->objtype = OBJECT_LANGUAGE;
    8039                 :          27 :                     n->objs = $2;
    8040                 :          27 :                     $$ = n;
    8041                 :             :                 }
    8042                 :             :             | LARGE_P OBJECT_P NumericOnly_list
    8043                 :             :                 {
    8044                 :          62 :                     PrivTarget *n = palloc_object(PrivTarget);
    8045                 :             : 
    8046                 :          62 :                     n->targtype = ACL_TARGET_OBJECT;
    8047                 :          62 :                     n->objtype = OBJECT_LARGEOBJECT;
    8048                 :          62 :                     n->objs = $3;
    8049                 :          62 :                     $$ = n;
    8050                 :             :                 }
    8051                 :             :             | PARAMETER parameter_name_list
    8052                 :             :                 {
    8053                 :          38 :                     PrivTarget *n = palloc_object(PrivTarget);
    8054                 :          38 :                     n->targtype = ACL_TARGET_OBJECT;
    8055                 :          38 :                     n->objtype = OBJECT_PARAMETER_ACL;
    8056                 :          38 :                     n->objs = $2;
    8057                 :          38 :                     $$ = n;
    8058                 :             :                 }
    8059                 :             :             | SCHEMA name_list
    8060                 :             :                 {
    8061                 :         331 :                     PrivTarget *n = palloc_object(PrivTarget);
    8062                 :             : 
    8063                 :         331 :                     n->targtype = ACL_TARGET_OBJECT;
    8064                 :         331 :                     n->objtype = OBJECT_SCHEMA;
    8065                 :         331 :                     n->objs = $2;
    8066                 :         331 :                     $$ = n;
    8067                 :             :                 }
    8068                 :             :             | TABLESPACE name_list
    8069                 :             :                 {
    8070                 :           9 :                     PrivTarget *n = palloc_object(PrivTarget);
    8071                 :             : 
    8072                 :           9 :                     n->targtype = ACL_TARGET_OBJECT;
    8073                 :           9 :                     n->objtype = OBJECT_TABLESPACE;
    8074                 :           9 :                     n->objs = $2;
    8075                 :           9 :                     $$ = n;
    8076                 :             :                 }
    8077                 :             :             | TYPE_P any_name_list
    8078                 :             :                 {
    8079                 :          84 :                     PrivTarget *n = palloc_object(PrivTarget);
    8080                 :             : 
    8081                 :          84 :                     n->targtype = ACL_TARGET_OBJECT;
    8082                 :          84 :                     n->objtype = OBJECT_TYPE;
    8083                 :          84 :                     n->objs = $2;
    8084                 :          84 :                     $$ = n;
    8085                 :             :                 }
    8086                 :             :             | ALL TABLES IN_P SCHEMA name_list
    8087                 :             :                 {
    8088                 :           8 :                     PrivTarget *n = palloc_object(PrivTarget);
    8089                 :             : 
    8090                 :           8 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8091                 :           8 :                     n->objtype = OBJECT_TABLE;
    8092                 :           8 :                     n->objs = $5;
    8093                 :           8 :                     $$ = n;
    8094                 :             :                 }
    8095                 :             :             | ALL SEQUENCES IN_P SCHEMA name_list
    8096                 :             :                 {
    8097                 :           1 :                     PrivTarget *n = palloc_object(PrivTarget);
    8098                 :             : 
    8099                 :           1 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8100                 :           1 :                     n->objtype = OBJECT_SEQUENCE;
    8101                 :           1 :                     n->objs = $5;
    8102                 :           1 :                     $$ = n;
    8103                 :             :                 }
    8104                 :             :             | ALL FUNCTIONS IN_P SCHEMA name_list
    8105                 :             :                 {
    8106                 :           4 :                     PrivTarget *n = palloc_object(PrivTarget);
    8107                 :             : 
    8108                 :           4 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8109                 :           4 :                     n->objtype = OBJECT_FUNCTION;
    8110                 :           4 :                     n->objs = $5;
    8111                 :           4 :                     $$ = n;
    8112                 :             :                 }
    8113                 :             :             | ALL PROCEDURES IN_P SCHEMA name_list
    8114                 :             :                 {
    8115                 :           4 :                     PrivTarget *n = palloc_object(PrivTarget);
    8116                 :             : 
    8117                 :           4 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8118                 :           4 :                     n->objtype = OBJECT_PROCEDURE;
    8119                 :           4 :                     n->objs = $5;
    8120                 :           4 :                     $$ = n;
    8121                 :             :                 }
    8122                 :             :             | ALL ROUTINES IN_P SCHEMA name_list
    8123                 :             :                 {
    8124                 :           4 :                     PrivTarget *n = palloc_object(PrivTarget);
    8125                 :             : 
    8126                 :           4 :                     n->targtype = ACL_TARGET_ALL_IN_SCHEMA;
    8127                 :           4 :                     n->objtype = OBJECT_ROUTINE;
    8128                 :           4 :                     n->objs = $5;
    8129                 :           4 :                     $$ = n;
    8130                 :             :                 }
    8131                 :             :         ;
    8132                 :             : 
    8133                 :             : 
    8134                 :             : grantee_list:
    8135                 :        8820 :             grantee                                 { $$ = list_make1($1); }
    8136                 :          71 :             | grantee_list ',' grantee              { $$ = lappend($1, $3); }
    8137                 :             :         ;
    8138                 :             : 
    8139                 :             : grantee:
    8140                 :        8875 :             RoleSpec                                { $$ = $1; }
    8141                 :          16 :             | GROUP_P RoleSpec                      { $$ = $2; }
    8142                 :             :         ;
    8143                 :             : 
    8144                 :             : 
    8145                 :             : opt_grant_grant_option:
    8146                 :          77 :             WITH GRANT OPTION { $$ = true; }
    8147                 :        6276 :             | /*EMPTY*/ { $$ = false; }
    8148                 :             :         ;
    8149                 :             : 
    8150                 :             : /*****************************************************************************
    8151                 :             :  *
    8152                 :             :  * GRANT and REVOKE ROLE statements
    8153                 :             :  *
    8154                 :             :  *****************************************************************************/
    8155                 :             : 
    8156                 :             : GrantRoleStmt:
    8157                 :             :             GRANT privilege_list TO role_list opt_granted_by
    8158                 :             :                 {
    8159                 :         202 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8160                 :             : 
    8161                 :         202 :                     n->is_grant = true;
    8162                 :         202 :                     n->granted_roles = $2;
    8163                 :         202 :                     n->grantee_roles = $4;
    8164                 :         202 :                     n->opt = NIL;
    8165                 :         202 :                     n->grantor = $5;
    8166                 :         202 :                     $$ = (Node *) n;
    8167                 :             :                 }
    8168                 :             :           | GRANT privilege_list TO role_list WITH grant_role_opt_list opt_granted_by
    8169                 :             :                 {
    8170                 :         122 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8171                 :             : 
    8172                 :         122 :                     n->is_grant = true;
    8173                 :         122 :                     n->granted_roles = $2;
    8174                 :         122 :                     n->grantee_roles = $4;
    8175                 :         122 :                     n->opt = $6;
    8176                 :         122 :                     n->grantor = $7;
    8177                 :         122 :                     $$ = (Node *) n;
    8178                 :             :                 }
    8179                 :             :         ;
    8180                 :             : 
    8181                 :             : RevokeRoleStmt:
    8182                 :             :             REVOKE privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8183                 :             :                 {
    8184                 :          59 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8185                 :             : 
    8186                 :          59 :                     n->is_grant = false;
    8187                 :          59 :                     n->opt = NIL;
    8188                 :          59 :                     n->granted_roles = $2;
    8189                 :          59 :                     n->grantee_roles = $4;
    8190                 :          59 :                     n->grantor = $5;
    8191                 :          59 :                     n->behavior = $6;
    8192                 :          59 :                     $$ = (Node *) n;
    8193                 :             :                 }
    8194                 :             :             | REVOKE ColId OPTION FOR privilege_list FROM role_list opt_granted_by opt_drop_behavior
    8195                 :             :                 {
    8196                 :          48 :                     GrantRoleStmt *n = makeNode(GrantRoleStmt);
    8197                 :             :                     DefElem *opt;
    8198                 :             : 
    8199                 :          48 :                     opt = makeDefElem(pstrdup($2),
    8200                 :          48 :                                       (Node *) makeBoolean(false), @2);
    8201                 :          48 :                     n->is_grant = false;
    8202                 :          48 :                     n->opt = list_make1(opt);
    8203                 :          48 :                     n->granted_roles = $5;
    8204                 :          48 :                     n->grantee_roles = $7;
    8205                 :          48 :                     n->grantor = $8;
    8206                 :          48 :                     n->behavior = $9;
    8207                 :          48 :                     $$ = (Node *) n;
    8208                 :             :                 }
    8209                 :             :         ;
    8210                 :             : 
    8211                 :             : grant_role_opt_list:
    8212                 :          79 :             grant_role_opt_list ',' grant_role_opt  { $$ = lappend($1, $3); }
    8213                 :         122 :             | grant_role_opt                        { $$ = list_make1($1); }
    8214                 :             :         ;
    8215                 :             : 
    8216                 :             : grant_role_opt:
    8217                 :             :         ColLabel grant_role_opt_value
    8218                 :             :             {
    8219                 :         201 :                 $$ = makeDefElem(pstrdup($1), $2, @1);
    8220                 :             :             }
    8221                 :             :         ;
    8222                 :             : 
    8223                 :             : grant_role_opt_value:
    8224                 :          49 :         OPTION          { $$ = (Node *) makeBoolean(true); }
    8225                 :          77 :         | TRUE_P        { $$ = (Node *) makeBoolean(true); }
    8226                 :          75 :         | FALSE_P       { $$ = (Node *) makeBoolean(false); }
    8227                 :             :         ;
    8228                 :             : 
    8229                 :         108 : opt_granted_by: GRANTED BY RoleSpec                     { $$ = $3; }
    8230                 :        9008 :             | /*EMPTY*/                                 { $$ = NULL; }
    8231                 :             :         ;
    8232                 :             : 
    8233                 :             : /*****************************************************************************
    8234                 :             :  *
    8235                 :             :  * ALTER DEFAULT PRIVILEGES statement
    8236                 :             :  *
    8237                 :             :  *****************************************************************************/
    8238                 :             : 
    8239                 :             : AlterDefaultPrivilegesStmt:
    8240                 :             :             ALTER DEFAULT PRIVILEGES DefACLOptionList DefACLAction
    8241                 :             :                 {
    8242                 :         135 :                     AlterDefaultPrivilegesStmt *n = makeNode(AlterDefaultPrivilegesStmt);
    8243                 :             : 
    8244                 :         135 :                     n->options = $4;
    8245                 :         135 :                     n->action = (GrantStmt *) $5;
    8246                 :         135 :                     $$ = (Node *) n;
    8247                 :             :                 }
    8248                 :             :         ;
    8249                 :             : 
    8250                 :             : DefACLOptionList:
    8251                 :          93 :             DefACLOptionList DefACLOption           { $$ = lappend($1, $2); }
    8252                 :         135 :             | /* EMPTY */                           { $$ = NIL; }
    8253                 :             :         ;
    8254                 :             : 
    8255                 :             : DefACLOption:
    8256                 :             :             IN_P SCHEMA name_list
    8257                 :             :                 {
    8258                 :          39 :                     $$ = makeDefElem("schemas", (Node *) $3, @1);
    8259                 :             :                 }
    8260                 :             :             | FOR ROLE role_list
    8261                 :             :                 {
    8262                 :          54 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8263                 :             :                 }
    8264                 :             :             | FOR USER role_list
    8265                 :             :                 {
    8266                 :           0 :                     $$ = makeDefElem("roles", (Node *) $3, @1);
    8267                 :             :                 }
    8268                 :             :         ;
    8269                 :             : 
    8270                 :             : /*
    8271                 :             :  * This should match GRANT/REVOKE, except that individual target objects
    8272                 :             :  * are not mentioned and we only allow a subset of object types.
    8273                 :             :  */
    8274                 :             : DefACLAction:
    8275                 :             :             GRANT privileges ON defacl_privilege_target TO grantee_list
    8276                 :             :             opt_grant_grant_option
    8277                 :             :                 {
    8278                 :          82 :                     GrantStmt *n = makeNode(GrantStmt);
    8279                 :             : 
    8280                 :          82 :                     n->is_grant = true;
    8281                 :          82 :                     n->privileges = $2;
    8282                 :          82 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8283                 :          82 :                     n->objtype = $4;
    8284                 :          82 :                     n->objects = NIL;
    8285                 :          82 :                     n->grantees = $6;
    8286                 :          82 :                     n->grant_option = $7;
    8287                 :          82 :                     $$ = (Node *) n;
    8288                 :             :                 }
    8289                 :             :             | REVOKE privileges ON defacl_privilege_target
    8290                 :             :             FROM grantee_list opt_drop_behavior
    8291                 :             :                 {
    8292                 :          53 :                     GrantStmt *n = makeNode(GrantStmt);
    8293                 :             : 
    8294                 :          53 :                     n->is_grant = false;
    8295                 :          53 :                     n->grant_option = false;
    8296                 :          53 :                     n->privileges = $2;
    8297                 :          53 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8298                 :          53 :                     n->objtype = $4;
    8299                 :          53 :                     n->objects = NIL;
    8300                 :          53 :                     n->grantees = $6;
    8301                 :          53 :                     n->behavior = $7;
    8302                 :          53 :                     $$ = (Node *) n;
    8303                 :             :                 }
    8304                 :             :             | REVOKE GRANT OPTION FOR privileges ON defacl_privilege_target
    8305                 :             :             FROM grantee_list opt_drop_behavior
    8306                 :             :                 {
    8307                 :           0 :                     GrantStmt *n = makeNode(GrantStmt);
    8308                 :             : 
    8309                 :           0 :                     n->is_grant = false;
    8310                 :           0 :                     n->grant_option = true;
    8311                 :           0 :                     n->privileges = $5;
    8312                 :           0 :                     n->targtype = ACL_TARGET_DEFAULTS;
    8313                 :           0 :                     n->objtype = $7;
    8314                 :           0 :                     n->objects = NIL;
    8315                 :           0 :                     n->grantees = $9;
    8316                 :           0 :                     n->behavior = $10;
    8317                 :           0 :                     $$ = (Node *) n;
    8318                 :             :                 }
    8319                 :             :         ;
    8320                 :             : 
    8321                 :             : defacl_privilege_target:
    8322                 :          51 :             TABLES          { $$ = OBJECT_TABLE; }
    8323                 :          10 :             | FUNCTIONS     { $$ = OBJECT_FUNCTION; }
    8324                 :           4 :             | ROUTINES      { $$ = OBJECT_FUNCTION; }
    8325                 :           4 :             | SEQUENCES     { $$ = OBJECT_SEQUENCE; }
    8326                 :          22 :             | TYPES_P       { $$ = OBJECT_TYPE; }
    8327                 :          24 :             | SCHEMAS       { $$ = OBJECT_SCHEMA; }
    8328                 :          20 :             | LARGE_P OBJECTS_P { $$ = OBJECT_LARGEOBJECT; }
    8329                 :             :         ;
    8330                 :             : 
    8331                 :             : 
    8332                 :             : /*****************************************************************************
    8333                 :             :  *
    8334                 :             :  *      QUERY: CREATE INDEX
    8335                 :             :  *
    8336                 :             :  * Note: we cannot put TABLESPACE clause after WHERE clause unless we are
    8337                 :             :  * willing to make TABLESPACE a fully reserved word.
    8338                 :             :  *****************************************************************************/
    8339                 :             : 
    8340                 :             : IndexStmt:  CREATE opt_unique INDEX opt_concurrently opt_single_name
    8341                 :             :             ON relation_expr access_method_clause '(' index_params ')'
    8342                 :             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8343                 :             :                 {
    8344                 :        4601 :                     IndexStmt *n = makeNode(IndexStmt);
    8345                 :             : 
    8346                 :        4601 :                     n->unique = $2;
    8347                 :        4601 :                     n->concurrent = $4;
    8348                 :        4601 :                     n->idxname = $5;
    8349                 :        4601 :                     n->relation = $7;
    8350                 :        4601 :                     n->accessMethod = $8;
    8351                 :        4601 :                     n->indexParams = $10;
    8352                 :        4601 :                     n->indexIncludingParams = $12;
    8353                 :        4601 :                     n->nulls_not_distinct = !$13;
    8354                 :        4601 :                     n->options = $14;
    8355                 :        4601 :                     n->tableSpace = $15;
    8356                 :        4601 :                     n->whereClause = $16;
    8357                 :        4601 :                     n->excludeOpNames = NIL;
    8358                 :        4601 :                     n->idxcomment = NULL;
    8359                 :        4601 :                     n->indexOid = InvalidOid;
    8360                 :        4601 :                     n->oldNumber = InvalidRelFileNumber;
    8361                 :        4601 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8362                 :        4601 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8363                 :        4601 :                     n->primary = false;
    8364                 :        4601 :                     n->isconstraint = false;
    8365                 :        4601 :                     n->deferrable = false;
    8366                 :        4601 :                     n->initdeferred = false;
    8367                 :        4601 :                     n->transformed = false;
    8368                 :        4601 :                     n->if_not_exists = false;
    8369                 :        4601 :                     n->reset_default_tblspc = false;
    8370                 :        4601 :                     $$ = (Node *) n;
    8371                 :             :                 }
    8372                 :             :             | CREATE opt_unique INDEX opt_concurrently IF_P NOT EXISTS name
    8373                 :             :             ON relation_expr access_method_clause '(' index_params ')'
    8374                 :             :             opt_include opt_unique_null_treatment opt_reloptions OptTableSpace where_clause
    8375                 :             :                 {
    8376                 :          12 :                     IndexStmt *n = makeNode(IndexStmt);
    8377                 :             : 
    8378                 :          12 :                     n->unique = $2;
    8379                 :          12 :                     n->concurrent = $4;
    8380                 :          12 :                     n->idxname = $8;
    8381                 :          12 :                     n->relation = $10;
    8382                 :          12 :                     n->accessMethod = $11;
    8383                 :          12 :                     n->indexParams = $13;
    8384                 :          12 :                     n->indexIncludingParams = $15;
    8385                 :          12 :                     n->nulls_not_distinct = !$16;
    8386                 :          12 :                     n->options = $17;
    8387                 :          12 :                     n->tableSpace = $18;
    8388                 :          12 :                     n->whereClause = $19;
    8389                 :          12 :                     n->excludeOpNames = NIL;
    8390                 :          12 :                     n->idxcomment = NULL;
    8391                 :          12 :                     n->indexOid = InvalidOid;
    8392                 :          12 :                     n->oldNumber = InvalidRelFileNumber;
    8393                 :          12 :                     n->oldCreateSubid = InvalidSubTransactionId;
    8394                 :          12 :                     n->oldFirstRelfilelocatorSubid = InvalidSubTransactionId;
    8395                 :          12 :                     n->primary = false;
    8396                 :          12 :                     n->isconstraint = false;
    8397                 :          12 :                     n->deferrable = false;
    8398                 :          12 :                     n->initdeferred = false;
    8399                 :          12 :                     n->transformed = false;
    8400                 :          12 :                     n->if_not_exists = true;
    8401                 :          12 :                     n->reset_default_tblspc = false;
    8402                 :          12 :                     $$ = (Node *) n;
    8403                 :             :                 }
    8404                 :             :         ;
    8405                 :             : 
    8406                 :             : opt_unique:
    8407                 :         869 :             UNIQUE                                  { $$ = true; }
    8408                 :        3748 :             | /*EMPTY*/                             { $$ = false; }
    8409                 :             :         ;
    8410                 :             : 
    8411                 :             : access_method_clause:
    8412                 :        1891 :             USING name                              { $$ = $2; }
    8413                 :        2891 :             | /*EMPTY*/                             { $$ = DEFAULT_INDEX_TYPE; }
    8414                 :             :         ;
    8415                 :             : 
    8416                 :        5905 : index_params:   index_elem                          { $$ = list_make1($1); }
    8417                 :        1432 :             | index_params ',' index_elem           { $$ = lappend($1, $3); }
    8418                 :             :         ;
    8419                 :             : 
    8420                 :             : 
    8421                 :             : index_elem_options:
    8422                 :             :     opt_collate opt_qualified_name opt_asc_desc opt_nulls_order
    8423                 :             :         {
    8424                 :        7756 :             $$ = makeNode(IndexElem);
    8425                 :        7756 :             $$->name = NULL;
    8426                 :        7756 :             $$->expr = NULL;
    8427                 :        7756 :             $$->indexcolname = NULL;
    8428                 :        7756 :             $$->collation = $1;
    8429                 :        7756 :             $$->opclass = $2;
    8430                 :        7756 :             $$->opclassopts = NIL;
    8431                 :        7756 :             $$->ordering = $3;
    8432                 :        7756 :             $$->nulls_ordering = $4;
    8433                 :             :             /* location will be filled in index_elem production */
    8434                 :             :         }
    8435                 :             :     | opt_collate any_name reloptions opt_asc_desc opt_nulls_order
    8436                 :             :         {
    8437                 :          91 :             $$ = makeNode(IndexElem);
    8438                 :          91 :             $$->name = NULL;
    8439                 :          91 :             $$->expr = NULL;
    8440                 :          91 :             $$->indexcolname = NULL;
    8441                 :          91 :             $$->collation = $1;
    8442                 :          91 :             $$->opclass = $2;
    8443                 :          91 :             $$->opclassopts = $3;
    8444                 :          91 :             $$->ordering = $4;
    8445                 :          91 :             $$->nulls_ordering = $5;
    8446                 :             :             /* location will be filled in index_elem production */
    8447                 :             :         }
    8448                 :             :     ;
    8449                 :             : 
    8450                 :             : /*
    8451                 :             :  * Index attributes can be either simple column references, or arbitrary
    8452                 :             :  * expressions in parens.  For backwards-compatibility reasons, we allow
    8453                 :             :  * an expression that's just a function call to be written without parens.
    8454                 :             :  */
    8455                 :             : index_elem: ColId index_elem_options
    8456                 :             :                 {
    8457                 :        6882 :                     $$ = $2;
    8458                 :        6882 :                     $$->name = $1;
    8459                 :        6882 :                     $$->location = @1;
    8460                 :             :                 }
    8461                 :             :             | func_expr_windowless index_elem_options
    8462                 :             :                 {
    8463                 :         551 :                     $$ = $2;
    8464                 :         551 :                     $$->expr = $1;
    8465                 :         551 :                     $$->location = @1;
    8466                 :             :                 }
    8467                 :             :             | '(' a_expr ')' index_elem_options
    8468                 :             :                 {
    8469                 :         414 :                     $$ = $4;
    8470                 :         414 :                     $$->expr = $2;
    8471                 :         414 :                     $$->location = @1;
    8472                 :             :                 }
    8473                 :             :         ;
    8474                 :             : 
    8475                 :         149 : opt_include:        INCLUDE '(' index_including_params ')'          { $$ = $3; }
    8476                 :        4464 :              |      /* EMPTY */                     { $$ = NIL; }
    8477                 :             :         ;
    8478                 :             : 
    8479                 :         149 : index_including_params: index_elem                      { $$ = list_make1($1); }
    8480                 :         109 :             | index_including_params ',' index_elem     { $$ = lappend($1, $3); }
    8481                 :             :         ;
    8482                 :             : 
    8483                 :         142 : opt_collate: COLLATE any_name                       { $$ = $2; }
    8484                 :       11444 :             | /*EMPTY*/                             { $$ = NIL; }
    8485                 :             :         ;
    8486                 :             : 
    8487                 :             : 
    8488                 :        1018 : opt_asc_desc: ASC                           { $$ = SORTBY_ASC; }
    8489                 :        2368 :             | DESC                          { $$ = SORTBY_DESC; }
    8490                 :       75788 :             | /*EMPTY*/                     { $$ = SORTBY_DEFAULT; }
    8491                 :             :         ;
    8492                 :             : 
    8493                 :         212 : opt_nulls_order: NULLS_LA FIRST_P           { $$ = SORTBY_NULLS_FIRST; }
    8494                 :         908 :             | NULLS_LA LAST_P               { $$ = SORTBY_NULLS_LAST; }
    8495                 :       78196 :             | /*EMPTY*/                     { $$ = SORTBY_NULLS_DEFAULT; }
    8496                 :             :         ;
    8497                 :             : 
    8498                 :             : 
    8499                 :             : /*****************************************************************************
    8500                 :             :  *
    8501                 :             :  *      QUERY:
    8502                 :             :  *              create [or replace] function <fname>
    8503                 :             :  *                      [(<type-1> { , <type-n>})]
    8504                 :             :  *                      returns <type-r>
    8505                 :             :  *                      as <filename or code in language as appropriate>
    8506                 :             :  *                      language <lang> [with parameters]
    8507                 :             :  *
    8508                 :             :  *****************************************************************************/
    8509                 :             : 
    8510                 :             : CreateFunctionStmt:
    8511                 :             :             CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8512                 :             :             RETURNS func_return opt_createfunc_opt_list opt_routine_body
    8513                 :             :                 {
    8514                 :       12812 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8515                 :             : 
    8516                 :       12812 :                     n->is_procedure = false;
    8517                 :       12812 :                     n->replace = $2;
    8518                 :       12812 :                     n->funcname = $4;
    8519                 :       12812 :                     n->parameters = $5;
    8520                 :       12812 :                     n->returnType = $7;
    8521                 :       12812 :                     n->options = $8;
    8522                 :       12812 :                     n->sql_body = $9;
    8523                 :       12812 :                     $$ = (Node *) n;
    8524                 :             :                 }
    8525                 :             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8526                 :             :               RETURNS TABLE '(' table_func_column_list ')' opt_createfunc_opt_list opt_routine_body
    8527                 :             :                 {
    8528                 :         141 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8529                 :             : 
    8530                 :         141 :                     n->is_procedure = false;
    8531                 :         141 :                     n->replace = $2;
    8532                 :         141 :                     n->funcname = $4;
    8533                 :         141 :                     n->parameters = mergeTableFuncParameters($5, $9, yyscanner);
    8534                 :         141 :                     n->returnType = TableFuncTypeName($9);
    8535                 :         141 :                     n->returnType->location = @7;
    8536                 :         141 :                     n->options = $11;
    8537                 :         141 :                     n->sql_body = $12;
    8538                 :         141 :                     $$ = (Node *) n;
    8539                 :             :                 }
    8540                 :             :             | CREATE opt_or_replace FUNCTION func_name func_args_with_defaults
    8541                 :             :               opt_createfunc_opt_list opt_routine_body
    8542                 :             :                 {
    8543                 :         315 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8544                 :             : 
    8545                 :         315 :                     n->is_procedure = false;
    8546                 :         315 :                     n->replace = $2;
    8547                 :         315 :                     n->funcname = $4;
    8548                 :         315 :                     n->parameters = $5;
    8549                 :         315 :                     n->returnType = NULL;
    8550                 :         315 :                     n->options = $6;
    8551                 :         315 :                     n->sql_body = $7;
    8552                 :         315 :                     $$ = (Node *) n;
    8553                 :             :                 }
    8554                 :             :             | CREATE opt_or_replace PROCEDURE func_name func_args_with_defaults
    8555                 :             :               opt_createfunc_opt_list opt_routine_body
    8556                 :             :                 {
    8557                 :         225 :                     CreateFunctionStmt *n = makeNode(CreateFunctionStmt);
    8558                 :             : 
    8559                 :         225 :                     n->is_procedure = true;
    8560                 :         225 :                     n->replace = $2;
    8561                 :         225 :                     n->funcname = $4;
    8562                 :         225 :                     n->parameters = $5;
    8563                 :         225 :                     n->returnType = NULL;
    8564                 :         225 :                     n->options = $6;
    8565                 :         225 :                     n->sql_body = $7;
    8566                 :         225 :                     $$ = (Node *) n;
    8567                 :             :                 }
    8568                 :             :         ;
    8569                 :             : 
    8570                 :             : opt_or_replace:
    8571                 :        3905 :             OR REPLACE                              { $$ = true; }
    8572                 :       13082 :             | /*EMPTY*/                             { $$ = false; }
    8573                 :             :         ;
    8574                 :             : 
    8575                 :        4045 : func_args:  '(' func_args_list ')'                  { $$ = $2; }
    8576                 :        1307 :             | '(' ')'                               { $$ = NIL; }
    8577                 :             :         ;
    8578                 :             : 
    8579                 :             : func_args_list:
    8580                 :        4045 :             func_arg                                { $$ = list_make1($1); }
    8581                 :        4015 :             | func_args_list ',' func_arg           { $$ = lappend($1, $3); }
    8582                 :             :         ;
    8583                 :             : 
    8584                 :             : function_with_argtypes_list:
    8585                 :        3164 :             function_with_argtypes                  { $$ = list_make1($1); }
    8586                 :             :             | function_with_argtypes_list ',' function_with_argtypes
    8587                 :          60 :                                                     { $$ = lappend($1, $3); }
    8588                 :             :         ;
    8589                 :             : 
    8590                 :             : function_with_argtypes:
    8591                 :             :             func_name func_args
    8592                 :             :                 {
    8593                 :        5352 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8594                 :             : 
    8595                 :        5352 :                     n->objname = $1;
    8596                 :        5352 :                     n->objargs = extractArgTypes($2);
    8597                 :        5352 :                     n->objfuncargs = $2;
    8598                 :        5352 :                     $$ = n;
    8599                 :             :                 }
    8600                 :             :             /*
    8601                 :             :              * Because of reduce/reduce conflicts, we can't use func_name
    8602                 :             :              * below, but we can write it out the long way, which actually
    8603                 :             :              * allows more cases.
    8604                 :             :              */
    8605                 :             :             | type_func_name_keyword
    8606                 :             :                 {
    8607                 :           0 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8608                 :             : 
    8609                 :           0 :                     n->objname = list_make1(makeString(pstrdup($1)));
    8610                 :           0 :                     n->args_unspecified = true;
    8611                 :           0 :                     $$ = n;
    8612                 :             :                 }
    8613                 :             :             | ColId
    8614                 :             :                 {
    8615                 :         312 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8616                 :             : 
    8617                 :         312 :                     n->objname = list_make1(makeString($1));
    8618                 :         312 :                     n->args_unspecified = true;
    8619                 :         312 :                     $$ = n;
    8620                 :             :                 }
    8621                 :             :             | ColId indirection
    8622                 :             :                 {
    8623                 :          14 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8624                 :             : 
    8625                 :          14 :                     n->objname = check_func_name(lcons(makeString($1), $2),
    8626                 :             :                                                   yyscanner);
    8627                 :          14 :                     n->args_unspecified = true;
    8628                 :          14 :                     $$ = n;
    8629                 :             :                 }
    8630                 :             :         ;
    8631                 :             : 
    8632                 :             : /*
    8633                 :             :  * func_args_with_defaults is separate because we only want to accept
    8634                 :             :  * defaults in CREATE FUNCTION, not in ALTER etc.
    8635                 :             :  */
    8636                 :             : func_args_with_defaults:
    8637                 :       10642 :         '(' func_args_with_defaults_list ')'        { $$ = $2; }
    8638                 :        2851 :         | '(' ')'                                   { $$ = NIL; }
    8639                 :             :         ;
    8640                 :             : 
    8641                 :             : func_args_with_defaults_list:
    8642                 :       10642 :         func_arg_with_default                       { $$ = list_make1($1); }
    8643                 :             :         | func_args_with_defaults_list ',' func_arg_with_default
    8644                 :       15124 :                                                     { $$ = lappend($1, $3); }
    8645                 :             :         ;
    8646                 :             : 
    8647                 :             : /*
    8648                 :             :  * The style with arg_class first is SQL99 standard, but Oracle puts
    8649                 :             :  * param_name first; accept both since it's likely people will try both
    8650                 :             :  * anyway.  Don't bother trying to save productions by letting arg_class
    8651                 :             :  * have an empty alternative ... you'll get shift/reduce conflicts.
    8652                 :             :  *
    8653                 :             :  * We can catch over-specified arguments here if we want to,
    8654                 :             :  * but for now better to silently swallow typmod, etc.
    8655                 :             :  * - thomas 2000-03-22
    8656                 :             :  */
    8657                 :             : func_arg:
    8658                 :             :             arg_class param_name func_type
    8659                 :             :                 {
    8660                 :        7842 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8661                 :             : 
    8662                 :        7842 :                     n->name = $2;
    8663                 :        7842 :                     n->argType = $3;
    8664                 :        7842 :                     n->mode = $1;
    8665                 :        7842 :                     n->defexpr = NULL;
    8666                 :        7842 :                     n->location = @1;
    8667                 :        7842 :                     $$ = n;
    8668                 :             :                 }
    8669                 :             :             | param_name arg_class func_type
    8670                 :             :                 {
    8671                 :         260 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8672                 :             : 
    8673                 :         260 :                     n->name = $1;
    8674                 :         260 :                     n->argType = $3;
    8675                 :         260 :                     n->mode = $2;
    8676                 :         260 :                     n->defexpr = NULL;
    8677                 :         260 :                     n->location = @1;
    8678                 :         260 :                     $$ = n;
    8679                 :             :                 }
    8680                 :             :             | param_name func_type
    8681                 :             :                 {
    8682                 :        4391 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8683                 :             : 
    8684                 :        4391 :                     n->name = $1;
    8685                 :        4391 :                     n->argType = $2;
    8686                 :        4391 :                     n->mode = FUNC_PARAM_DEFAULT;
    8687                 :        4391 :                     n->defexpr = NULL;
    8688                 :        4391 :                     n->location = @1;
    8689                 :        4391 :                     $$ = n;
    8690                 :             :                 }
    8691                 :             :             | arg_class func_type
    8692                 :             :                 {
    8693                 :         203 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8694                 :             : 
    8695                 :         203 :                     n->name = NULL;
    8696                 :         203 :                     n->argType = $2;
    8697                 :         203 :                     n->mode = $1;
    8698                 :         203 :                     n->defexpr = NULL;
    8699                 :         203 :                     n->location = @1;
    8700                 :         203 :                     $$ = n;
    8701                 :             :                 }
    8702                 :             :             | func_type
    8703                 :             :                 {
    8704                 :       21686 :                     FunctionParameter *n = makeNode(FunctionParameter);
    8705                 :             : 
    8706                 :       21686 :                     n->name = NULL;
    8707                 :       21686 :                     n->argType = $1;
    8708                 :       21686 :                     n->mode = FUNC_PARAM_DEFAULT;
    8709                 :       21686 :                     n->defexpr = NULL;
    8710                 :       21686 :                     n->location = @1;
    8711                 :       21686 :                     $$ = n;
    8712                 :             :                 }
    8713                 :             :         ;
    8714                 :             : 
    8715                 :             : /* INOUT is SQL99 standard, IN OUT is for Oracle compatibility */
    8716                 :        1899 : arg_class:  IN_P                                { $$ = FUNC_PARAM_IN; }
    8717                 :        6163 :             | OUT_P                             { $$ = FUNC_PARAM_OUT; }
    8718                 :         122 :             | INOUT                             { $$ = FUNC_PARAM_INOUT; }
    8719                 :           0 :             | IN_P OUT_P                        { $$ = FUNC_PARAM_INOUT; }
    8720                 :         121 :             | VARIADIC                          { $$ = FUNC_PARAM_VARIADIC; }
    8721                 :             :         ;
    8722                 :             : 
    8723                 :             : /*
    8724                 :             :  * Ideally param_name should be ColId, but that causes too many conflicts.
    8725                 :             :  */
    8726                 :             : param_name: type_function_name
    8727                 :             :         ;
    8728                 :             : 
    8729                 :             : func_return:
    8730                 :             :             func_type
    8731                 :             :                 {
    8732                 :             :                     /* We can catch over-specified results here if we want to,
    8733                 :             :                      * but for now better to silently swallow typmod, etc.
    8734                 :             :                      * - thomas 2000-03-22
    8735                 :             :                      */
    8736                 :       12812 :                     $$ = $1;
    8737                 :             :                 }
    8738                 :             :         ;
    8739                 :             : 
    8740                 :             : /*
    8741                 :             :  * We would like to make the %TYPE productions here be ColId attrs etc,
    8742                 :             :  * but that causes reduce/reduce conflicts.  type_function_name
    8743                 :             :  * is next best choice.
    8744                 :             :  */
    8745                 :       59914 : func_type:  Typename                                { $$ = $1; }
    8746                 :             :             | type_function_name attrs '%' TYPE_P
    8747                 :             :                 {
    8748                 :          16 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
    8749                 :          16 :                     $$->pct_type = true;
    8750                 :          16 :                     $$->location = @1;
    8751                 :             :                 }
    8752                 :             :             | SETOF type_function_name attrs '%' TYPE_P
    8753                 :             :                 {
    8754                 :           4 :                     $$ = makeTypeNameFromNameList(lcons(makeString($2), $3));
    8755                 :           4 :                     $$->pct_type = true;
    8756                 :           4 :                     $$->setof = true;
    8757                 :           4 :                     $$->location = @2;
    8758                 :             :                 }
    8759                 :             :         ;
    8760                 :             : 
    8761                 :             : func_arg_with_default:
    8762                 :             :         func_arg
    8763                 :             :                 {
    8764                 :       25071 :                     $$ = $1;
    8765                 :             :                 }
    8766                 :             :         | func_arg DEFAULT a_expr
    8767                 :             :                 {
    8768                 :         567 :                     $$ = $1;
    8769                 :         567 :                     $$->defexpr = $3;
    8770                 :             :                 }
    8771                 :             :         | func_arg '=' a_expr
    8772                 :             :                 {
    8773                 :         128 :                     $$ = $1;
    8774                 :         128 :                     $$->defexpr = $3;
    8775                 :             :                 }
    8776                 :             :         ;
    8777                 :             : 
    8778                 :             : /* Aggregate args can be most things that function args can be */
    8779                 :             : aggr_arg:   func_arg
    8780                 :             :                 {
    8781         [ +  + ]:         556 :                     if (!($1->mode == FUNC_PARAM_DEFAULT ||
    8782         [ +  - ]:          36 :                           $1->mode == FUNC_PARAM_IN ||
    8783         [ -  + ]:          36 :                           $1->mode == FUNC_PARAM_VARIADIC))
    8784         [ #  # ]:           0 :                         ereport(ERROR,
    8785                 :             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
    8786                 :             :                                  errmsg("aggregates cannot have output arguments"),
    8787                 :             :                                  parser_errposition(@1)));
    8788                 :         556 :                     $$ = $1;
    8789                 :             :                 }
    8790                 :             :         ;
    8791                 :             : 
    8792                 :             : /*
    8793                 :             :  * The SQL standard offers no guidance on how to declare aggregate argument
    8794                 :             :  * lists, since it doesn't have CREATE AGGREGATE etc.  We accept these cases:
    8795                 :             :  *
    8796                 :             :  * (*)                                  - normal agg with no args
    8797                 :             :  * (aggr_arg,...)                       - normal agg with args
    8798                 :             :  * (ORDER BY aggr_arg,...)              - ordered-set agg with no direct args
    8799                 :             :  * (aggr_arg,... ORDER BY aggr_arg,...) - ordered-set agg with direct args
    8800                 :             :  *
    8801                 :             :  * The zero-argument case is spelled with '*' for consistency with COUNT(*).
    8802                 :             :  *
    8803                 :             :  * An additional restriction is that if the direct-args list ends in a
    8804                 :             :  * VARIADIC item, the ordered-args list must contain exactly one item that
    8805                 :             :  * is also VARIADIC with the same type.  This allows us to collapse the two
    8806                 :             :  * VARIADIC items into one, which is necessary to represent the aggregate in
    8807                 :             :  * pg_proc.  We check this at the grammar stage so that we can return a list
    8808                 :             :  * in which the second VARIADIC item is already discarded, avoiding extra work
    8809                 :             :  * in cases such as DROP AGGREGATE.
    8810                 :             :  *
    8811                 :             :  * The return value of this production is a two-element list, in which the
    8812                 :             :  * first item is a sublist of FunctionParameter nodes (with any duplicate
    8813                 :             :  * VARIADIC item already dropped, as per above) and the second is an Integer
    8814                 :             :  * node, containing -1 if there was no ORDER BY and otherwise the number
    8815                 :             :  * of argument declarations before the ORDER BY.  (If this number is equal
    8816                 :             :  * to the first sublist's length, then we dropped a duplicate VARIADIC item.)
    8817                 :             :  * This representation is passed as-is to CREATE AGGREGATE; for operations
    8818                 :             :  * on existing aggregates, we can just apply extractArgTypes to the first
    8819                 :             :  * sublist.
    8820                 :             :  */
    8821                 :             : aggr_args:  '(' '*' ')'
    8822                 :             :                 {
    8823                 :          85 :                     $$ = list_make2(NIL, makeInteger(-1));
    8824                 :             :                 }
    8825                 :             :             | '(' aggr_args_list ')'
    8826                 :             :                 {
    8827                 :         452 :                     $$ = list_make2($2, makeInteger(-1));
    8828                 :             :                 }
    8829                 :             :             | '(' ORDER BY aggr_args_list ')'
    8830                 :             :                 {
    8831                 :           4 :                     $$ = list_make2($4, makeInteger(0));
    8832                 :             :                 }
    8833                 :             :             | '(' aggr_args_list ORDER BY aggr_args_list ')'
    8834                 :             :                 {
    8835                 :             :                     /* this is the only case requiring consistency checking */
    8836                 :          20 :                     $$ = makeOrderedSetArgs($2, $5, yyscanner);
    8837                 :             :                 }
    8838                 :             :         ;
    8839                 :             : 
    8840                 :             : aggr_args_list:
    8841                 :         496 :             aggr_arg                                { $$ = list_make1($1); }
    8842                 :          60 :             | aggr_args_list ',' aggr_arg           { $$ = lappend($1, $3); }
    8843                 :             :         ;
    8844                 :             : 
    8845                 :             : aggregate_with_argtypes:
    8846                 :             :             func_name aggr_args
    8847                 :             :                 {
    8848                 :         220 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    8849                 :             : 
    8850                 :         220 :                     n->objname = $1;
    8851                 :         220 :                     n->objargs = extractAggrArgTypes($2);
    8852                 :         220 :                     n->objfuncargs = (List *) linitial($2);
    8853                 :         220 :                     $$ = n;
    8854                 :             :                 }
    8855                 :             :         ;
    8856                 :             : 
    8857                 :             : aggregate_with_argtypes_list:
    8858                 :          69 :             aggregate_with_argtypes                 { $$ = list_make1($1); }
    8859                 :             :             | aggregate_with_argtypes_list ',' aggregate_with_argtypes
    8860                 :           0 :                                                     { $$ = lappend($1, $3); }
    8861                 :             :         ;
    8862                 :             : 
    8863                 :             : opt_createfunc_opt_list:
    8864                 :             :             createfunc_opt_list
    8865                 :          70 :             | /*EMPTY*/ { $$ = NIL; }
    8866                 :             :     ;
    8867                 :             : 
    8868                 :             : createfunc_opt_list:
    8869                 :             :             /* Must be at least one to prevent conflict */
    8870                 :       13423 :             createfunc_opt_item                     { $$ = list_make1($1); }
    8871                 :       32573 :             | createfunc_opt_list createfunc_opt_item { $$ = lappend($1, $2); }
    8872                 :             :     ;
    8873                 :             : 
    8874                 :             : /*
    8875                 :             :  * Options common to both CREATE FUNCTION and ALTER FUNCTION
    8876                 :             :  */
    8877                 :             : common_func_opt_item:
    8878                 :             :             CALLED ON NULL_P INPUT_P
    8879                 :             :                 {
    8880                 :          91 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(false), @1);
    8881                 :             :                 }
    8882                 :             :             | RETURNS NULL_P ON NULL_P INPUT_P
    8883                 :             :                 {
    8884                 :         526 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8885                 :             :                 }
    8886                 :             :             | STRICT_P
    8887                 :             :                 {
    8888                 :        6382 :                     $$ = makeDefElem("strict", (Node *) makeBoolean(true), @1);
    8889                 :             :                 }
    8890                 :             :             | IMMUTABLE
    8891                 :             :                 {
    8892                 :        5040 :                     $$ = makeDefElem("volatility", (Node *) makeString("immutable"), @1);
    8893                 :             :                 }
    8894                 :             :             | STABLE
    8895                 :             :                 {
    8896                 :        1007 :                     $$ = makeDefElem("volatility", (Node *) makeString("stable"), @1);
    8897                 :             :                 }
    8898                 :             :             | VOLATILE
    8899                 :             :                 {
    8900                 :         221 :                     $$ = makeDefElem("volatility", (Node *) makeString("volatile"), @1);
    8901                 :             :                 }
    8902                 :             :             | EXTERNAL SECURITY DEFINER
    8903                 :             :                 {
    8904                 :           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8905                 :             :                 }
    8906                 :             :             | EXTERNAL SECURITY INVOKER
    8907                 :             :                 {
    8908                 :           0 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8909                 :             :                 }
    8910                 :             :             | SECURITY DEFINER
    8911                 :             :                 {
    8912                 :          36 :                     $$ = makeDefElem("security", (Node *) makeBoolean(true), @1);
    8913                 :             :                 }
    8914                 :             :             | SECURITY INVOKER
    8915                 :             :                 {
    8916                 :          12 :                     $$ = makeDefElem("security", (Node *) makeBoolean(false), @1);
    8917                 :             :                 }
    8918                 :             :             | LEAKPROOF
    8919                 :             :                 {
    8920                 :          30 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(true), @1);
    8921                 :             :                 }
    8922                 :             :             | NOT LEAKPROOF
    8923                 :             :                 {
    8924                 :           8 :                     $$ = makeDefElem("leakproof", (Node *) makeBoolean(false), @1);
    8925                 :             :                 }
    8926                 :             :             | COST NumericOnly
    8927                 :             :                 {
    8928                 :        2248 :                     $$ = makeDefElem("cost", (Node *) $2, @1);
    8929                 :             :                 }
    8930                 :             :             | ROWS NumericOnly
    8931                 :             :                 {
    8932                 :          70 :                     $$ = makeDefElem("rows", (Node *) $2, @1);
    8933                 :             :                 }
    8934                 :             :             | SUPPORT any_name
    8935                 :             :                 {
    8936                 :          72 :                     $$ = makeDefElem("support", (Node *) $2, @1);
    8937                 :             :                 }
    8938                 :             :             | FunctionSetResetClause
    8939                 :             :                 {
    8940                 :             :                     /* we abuse the normal content of a DefElem here */
    8941                 :          97 :                     $$ = makeDefElem("set", (Node *) $1, @1);
    8942                 :             :                 }
    8943                 :             :             | PARALLEL ColId
    8944                 :             :                 {
    8945                 :        6778 :                     $$ = makeDefElem("parallel", (Node *) makeString($2), @1);
    8946                 :             :                 }
    8947                 :             :         ;
    8948                 :             : 
    8949                 :             : createfunc_opt_item:
    8950                 :             :             AS func_as
    8951                 :             :                 {
    8952                 :       10102 :                     $$ = makeDefElem("as", (Node *) $2, @1);
    8953                 :             :                 }
    8954                 :             :             | LANGUAGE NonReservedWord_or_Sconst
    8955                 :             :                 {
    8956                 :       13410 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    8957                 :             :                 }
    8958                 :             :             | TRANSFORM transform_type_list
    8959                 :             :                 {
    8960                 :          76 :                     $$ = makeDefElem("transform", (Node *) $2, @1);
    8961                 :             :                 }
    8962                 :             :             | WINDOW
    8963                 :             :                 {
    8964                 :          13 :                     $$ = makeDefElem("window", (Node *) makeBoolean(true), @1);
    8965                 :             :                 }
    8966                 :             :             | common_func_opt_item
    8967                 :             :                 {
    8968                 :       22395 :                     $$ = $1;
    8969                 :             :                 }
    8970                 :             :         ;
    8971                 :             : 
    8972                 :        7947 : func_as:    Sconst                      { $$ = list_make1(makeString($1)); }
    8973                 :             :             | Sconst ',' Sconst
    8974                 :             :                 {
    8975                 :        2155 :                     $$ = list_make2(makeString($1), makeString($3));
    8976                 :             :                 }
    8977                 :             :         ;
    8978                 :             : 
    8979                 :             : ReturnStmt: RETURN a_expr
    8980                 :             :                 {
    8981                 :        2880 :                     ReturnStmt *r = makeNode(ReturnStmt);
    8982                 :             : 
    8983                 :        2880 :                     r->returnval = (Node *) $2;
    8984                 :        2880 :                     $$ = (Node *) r;
    8985                 :             :                 }
    8986                 :             :         ;
    8987                 :             : 
    8988                 :             : opt_routine_body:
    8989                 :             :             ReturnStmt
    8990                 :             :                 {
    8991                 :        2876 :                     $$ = $1;
    8992                 :             :                 }
    8993                 :             :             | BEGIN_P ATOMIC routine_body_stmt_list END_P
    8994                 :             :                 {
    8995                 :             :                     /*
    8996                 :             :                      * A compound statement is stored as a single-item list
    8997                 :             :                      * containing the list of statements as its member.  That
    8998                 :             :                      * way, the parse analysis code can tell apart an empty
    8999                 :             :                      * body from no body at all.
    9000                 :             :                      */
    9001                 :         519 :                     $$ = (Node *) list_make1($3);
    9002                 :             :                 }
    9003                 :             :             | /*EMPTY*/
    9004                 :             :                 {
    9005                 :       10098 :                     $$ = NULL;
    9006                 :             :                 }
    9007                 :             :         ;
    9008                 :             : 
    9009                 :             : routine_body_stmt_list:
    9010                 :             :             routine_body_stmt_list routine_body_stmt ';'
    9011                 :             :                 {
    9012                 :             :                     /* As in stmtmulti, discard empty statements */
    9013         [ +  + ]:         534 :                     if ($2 != NULL)
    9014                 :         518 :                         $$ = lappend($1, $2);
    9015                 :             :                     else
    9016                 :          16 :                         $$ = $1;
    9017                 :             :                 }
    9018                 :             :             | /*EMPTY*/
    9019                 :             :                 {
    9020                 :         519 :                     $$ = NIL;
    9021                 :             :                 }
    9022                 :             :         ;
    9023                 :             : 
    9024                 :             : routine_body_stmt:
    9025                 :             :             stmt
    9026                 :             :             | ReturnStmt
    9027                 :             :         ;
    9028                 :             : 
    9029                 :             : transform_type_list:
    9030                 :          76 :             FOR TYPE_P Typename { $$ = list_make1($3); }
    9031                 :           2 :             | transform_type_list ',' FOR TYPE_P Typename { $$ = lappend($1, $5); }
    9032                 :             :         ;
    9033                 :             : 
    9034                 :             : opt_definition:
    9035                 :         503 :             WITH definition                         { $$ = $2; }
    9036                 :        6610 :             | /*EMPTY*/                             { $$ = NIL; }
    9037                 :             :         ;
    9038                 :             : 
    9039                 :             : table_func_column:  param_name func_type
    9040                 :             :                 {
    9041                 :         333 :                     FunctionParameter *n = makeNode(FunctionParameter);
    9042                 :             : 
    9043                 :         333 :                     n->name = $1;
    9044                 :         333 :                     n->argType = $2;
    9045                 :         333 :                     n->mode = FUNC_PARAM_TABLE;
    9046                 :         333 :                     n->defexpr = NULL;
    9047                 :         333 :                     n->location = @1;
    9048                 :         333 :                     $$ = n;
    9049                 :             :                 }
    9050                 :             :         ;
    9051                 :             : 
    9052                 :             : table_func_column_list:
    9053                 :             :             table_func_column
    9054                 :             :                 {
    9055                 :         141 :                     $$ = list_make1($1);
    9056                 :             :                 }
    9057                 :             :             | table_func_column_list ',' table_func_column
    9058                 :             :                 {
    9059                 :         192 :                     $$ = lappend($1, $3);
    9060                 :             :                 }
    9061                 :             :         ;
    9062                 :             : 
    9063                 :             : /*****************************************************************************
    9064                 :             :  * ALTER FUNCTION / ALTER PROCEDURE / ALTER ROUTINE
    9065                 :             :  *
    9066                 :             :  * RENAME and OWNER subcommands are already provided by the generic
    9067                 :             :  * ALTER infrastructure, here we just specify alterations that can
    9068                 :             :  * only be applied to functions.
    9069                 :             :  *
    9070                 :             :  *****************************************************************************/
    9071                 :             : AlterFunctionStmt:
    9072                 :             :             ALTER FUNCTION function_with_argtypes alterfunc_opt_list opt_restrict
    9073                 :             :                 {
    9074                 :         209 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9075                 :             : 
    9076                 :         209 :                     n->objtype = OBJECT_FUNCTION;
    9077                 :         209 :                     n->func = $3;
    9078                 :         209 :                     n->actions = $4;
    9079                 :         209 :                     $$ = (Node *) n;
    9080                 :             :                 }
    9081                 :             :             | ALTER PROCEDURE function_with_argtypes alterfunc_opt_list opt_restrict
    9082                 :             :                 {
    9083                 :          12 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9084                 :             : 
    9085                 :          12 :                     n->objtype = OBJECT_PROCEDURE;
    9086                 :          12 :                     n->func = $3;
    9087                 :          12 :                     n->actions = $4;
    9088                 :          12 :                     $$ = (Node *) n;
    9089                 :             :                 }
    9090                 :             :             | ALTER ROUTINE function_with_argtypes alterfunc_opt_list opt_restrict
    9091                 :             :                 {
    9092                 :           0 :                     AlterFunctionStmt *n = makeNode(AlterFunctionStmt);
    9093                 :             : 
    9094                 :           0 :                     n->objtype = OBJECT_ROUTINE;
    9095                 :           0 :                     n->func = $3;
    9096                 :           0 :                     n->actions = $4;
    9097                 :           0 :                     $$ = (Node *) n;
    9098                 :             :                 }
    9099                 :             :         ;
    9100                 :             : 
    9101                 :             : alterfunc_opt_list:
    9102                 :             :             /* At least one option must be specified */
    9103                 :         221 :             common_func_opt_item                    { $$ = list_make1($1); }
    9104                 :           2 :             | alterfunc_opt_list common_func_opt_item { $$ = lappend($1, $2); }
    9105                 :             :         ;
    9106                 :             : 
    9107                 :             : /* Ignored, merely for SQL compliance */
    9108                 :             : opt_restrict:
    9109                 :             :             RESTRICT
    9110                 :             :             | /* EMPTY */
    9111                 :             :         ;
    9112                 :             : 
    9113                 :             : 
    9114                 :             : /*****************************************************************************
    9115                 :             :  *
    9116                 :             :  *      QUERY:
    9117                 :             :  *
    9118                 :             :  *      DROP FUNCTION funcname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9119                 :             :  *      DROP PROCEDURE procname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9120                 :             :  *      DROP ROUTINE routname (arg1, arg2, ...) [ RESTRICT | CASCADE ]
    9121                 :             :  *      DROP AGGREGATE aggname (arg1, ...) [ RESTRICT | CASCADE ]
    9122                 :             :  *      DROP OPERATOR opname (leftoperand_typ, rightoperand_typ) [ RESTRICT | CASCADE ]
    9123                 :             :  *
    9124                 :             :  *****************************************************************************/
    9125                 :             : 
    9126                 :             : RemoveFuncStmt:
    9127                 :             :             DROP FUNCTION function_with_argtypes_list opt_drop_behavior
    9128                 :             :                 {
    9129                 :        2226 :                     DropStmt *n = makeNode(DropStmt);
    9130                 :             : 
    9131                 :        2226 :                     n->removeType = OBJECT_FUNCTION;
    9132                 :        2226 :                     n->objects = $3;
    9133                 :        2226 :                     n->behavior = $4;
    9134                 :        2226 :                     n->missing_ok = false;
    9135                 :        2226 :                     n->concurrent = false;
    9136                 :        2226 :                     $$ = (Node *) n;
    9137                 :             :                 }
    9138                 :             :             | DROP FUNCTION IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9139                 :             :                 {
    9140                 :         255 :                     DropStmt *n = makeNode(DropStmt);
    9141                 :             : 
    9142                 :         255 :                     n->removeType = OBJECT_FUNCTION;
    9143                 :         255 :                     n->objects = $5;
    9144                 :         255 :                     n->behavior = $6;
    9145                 :         255 :                     n->missing_ok = true;
    9146                 :         255 :                     n->concurrent = false;
    9147                 :         255 :                     $$ = (Node *) n;
    9148                 :             :                 }
    9149                 :             :             | DROP PROCEDURE function_with_argtypes_list opt_drop_behavior
    9150                 :             :                 {
    9151                 :          94 :                     DropStmt *n = makeNode(DropStmt);
    9152                 :             : 
    9153                 :          94 :                     n->removeType = OBJECT_PROCEDURE;
    9154                 :          94 :                     n->objects = $3;
    9155                 :          94 :                     n->behavior = $4;
    9156                 :          94 :                     n->missing_ok = false;
    9157                 :          94 :                     n->concurrent = false;
    9158                 :          94 :                     $$ = (Node *) n;
    9159                 :             :                 }
    9160                 :             :             | DROP PROCEDURE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9161                 :             :                 {
    9162                 :           4 :                     DropStmt *n = makeNode(DropStmt);
    9163                 :             : 
    9164                 :           4 :                     n->removeType = OBJECT_PROCEDURE;
    9165                 :           4 :                     n->objects = $5;
    9166                 :           4 :                     n->behavior = $6;
    9167                 :           4 :                     n->missing_ok = true;
    9168                 :           4 :                     n->concurrent = false;
    9169                 :           4 :                     $$ = (Node *) n;
    9170                 :             :                 }
    9171                 :             :             | DROP ROUTINE function_with_argtypes_list opt_drop_behavior
    9172                 :             :                 {
    9173                 :           8 :                     DropStmt *n = makeNode(DropStmt);
    9174                 :             : 
    9175                 :           8 :                     n->removeType = OBJECT_ROUTINE;
    9176                 :           8 :                     n->objects = $3;
    9177                 :           8 :                     n->behavior = $4;
    9178                 :           8 :                     n->missing_ok = false;
    9179                 :           8 :                     n->concurrent = false;
    9180                 :           8 :                     $$ = (Node *) n;
    9181                 :             :                 }
    9182                 :             :             | DROP ROUTINE IF_P EXISTS function_with_argtypes_list opt_drop_behavior
    9183                 :             :                 {
    9184                 :           4 :                     DropStmt *n = makeNode(DropStmt);
    9185                 :             : 
    9186                 :           4 :                     n->removeType = OBJECT_ROUTINE;
    9187                 :           4 :                     n->objects = $5;
    9188                 :           4 :                     n->behavior = $6;
    9189                 :           4 :                     n->missing_ok = true;
    9190                 :           4 :                     n->concurrent = false;
    9191                 :           4 :                     $$ = (Node *) n;
    9192                 :             :                 }
    9193                 :             :         ;
    9194                 :             : 
    9195                 :             : RemoveAggrStmt:
    9196                 :             :             DROP AGGREGATE aggregate_with_argtypes_list opt_drop_behavior
    9197                 :             :                 {
    9198                 :          49 :                     DropStmt *n = makeNode(DropStmt);
    9199                 :             : 
    9200                 :          49 :                     n->removeType = OBJECT_AGGREGATE;
    9201                 :          49 :                     n->objects = $3;
    9202                 :          49 :                     n->behavior = $4;
    9203                 :          49 :                     n->missing_ok = false;
    9204                 :          49 :                     n->concurrent = false;
    9205                 :          49 :                     $$ = (Node *) n;
    9206                 :             :                 }
    9207                 :             :             | DROP AGGREGATE IF_P EXISTS aggregate_with_argtypes_list opt_drop_behavior
    9208                 :             :                 {
    9209                 :          20 :                     DropStmt *n = makeNode(DropStmt);
    9210                 :             : 
    9211                 :          20 :                     n->removeType = OBJECT_AGGREGATE;
    9212                 :          20 :                     n->objects = $5;
    9213                 :          20 :                     n->behavior = $6;
    9214                 :          20 :                     n->missing_ok = true;
    9215                 :          20 :                     n->concurrent = false;
    9216                 :          20 :                     $$ = (Node *) n;
    9217                 :             :                 }
    9218                 :             :         ;
    9219                 :             : 
    9220                 :             : RemoveOperStmt:
    9221                 :             :             DROP OPERATOR operator_with_argtypes_list opt_drop_behavior
    9222                 :             :                 {
    9223                 :         124 :                     DropStmt *n = makeNode(DropStmt);
    9224                 :             : 
    9225                 :         124 :                     n->removeType = OBJECT_OPERATOR;
    9226                 :         124 :                     n->objects = $3;
    9227                 :         124 :                     n->behavior = $4;
    9228                 :         124 :                     n->missing_ok = false;
    9229                 :         124 :                     n->concurrent = false;
    9230                 :         124 :                     $$ = (Node *) n;
    9231                 :             :                 }
    9232                 :             :             | DROP OPERATOR IF_P EXISTS operator_with_argtypes_list opt_drop_behavior
    9233                 :             :                 {
    9234                 :          20 :                     DropStmt *n = makeNode(DropStmt);
    9235                 :             : 
    9236                 :          20 :                     n->removeType = OBJECT_OPERATOR;
    9237                 :          20 :                     n->objects = $5;
    9238                 :          20 :                     n->behavior = $6;
    9239                 :          20 :                     n->missing_ok = true;
    9240                 :          20 :                     n->concurrent = false;
    9241                 :          20 :                     $$ = (Node *) n;
    9242                 :             :                 }
    9243                 :             :         ;
    9244                 :             : 
    9245                 :             : oper_argtypes:
    9246                 :             :             '(' Typename ')'
    9247                 :             :                 {
    9248         [ +  - ]:           8 :                    ereport(ERROR,
    9249                 :             :                            (errcode(ERRCODE_SYNTAX_ERROR),
    9250                 :             :                             errmsg("missing argument"),
    9251                 :             :                             errhint("Use NONE to denote the missing argument of a unary operator."),
    9252                 :             :                             parser_errposition(@3)));
    9253                 :             :                 }
    9254                 :             :             | '(' Typename ',' Typename ')'
    9255                 :        1331 :                     { $$ = list_make2($2, $4); }
    9256                 :             :             | '(' NONE ',' Typename ')'                 /* left unary */
    9257                 :          20 :                     { $$ = list_make2(NULL, $4); }
    9258                 :             :             | '(' Typename ',' NONE ')'                 /* right unary */
    9259                 :           8 :                     { $$ = list_make2($2, NULL); }
    9260                 :             :         ;
    9261                 :             : 
    9262                 :             : any_operator:
    9263                 :             :             all_Op
    9264                 :       13181 :                     { $$ = list_make1(makeString($1)); }
    9265                 :             :             | ColId '.' any_operator
    9266                 :        9667 :                     { $$ = lcons(makeString($1), $3); }
    9267                 :             :         ;
    9268                 :             : 
    9269                 :             : operator_with_argtypes_list:
    9270                 :         144 :             operator_with_argtypes                  { $$ = list_make1($1); }
    9271                 :             :             | operator_with_argtypes_list ',' operator_with_argtypes
    9272                 :           0 :                                                     { $$ = lappend($1, $3); }
    9273                 :             :         ;
    9274                 :             : 
    9275                 :             : operator_with_argtypes:
    9276                 :             :             any_operator oper_argtypes
    9277                 :             :                 {
    9278                 :        1359 :                     ObjectWithArgs *n = makeNode(ObjectWithArgs);
    9279                 :             : 
    9280                 :        1359 :                     n->objname = $1;
    9281                 :        1359 :                     n->objargs = $2;
    9282                 :        1359 :                     $$ = n;
    9283                 :             :                 }
    9284                 :             :         ;
    9285                 :             : 
    9286                 :             : /*****************************************************************************
    9287                 :             :  *
    9288                 :             :  *      DO <anonymous code block> [ LANGUAGE language ]
    9289                 :             :  *
    9290                 :             :  * We use a DefElem list for future extensibility, and to allow flexibility
    9291                 :             :  * in the clause order.
    9292                 :             :  *
    9293                 :             :  *****************************************************************************/
    9294                 :             : 
    9295                 :             : DoStmt: DO dostmt_opt_list
    9296                 :             :                 {
    9297                 :         708 :                     DoStmt *n = makeNode(DoStmt);
    9298                 :             : 
    9299                 :         708 :                     n->args = $2;
    9300                 :         708 :                     $$ = (Node *) n;
    9301                 :             :                 }
    9302                 :             :         ;
    9303                 :             : 
    9304                 :             : dostmt_opt_list:
    9305                 :         708 :             dostmt_opt_item                     { $$ = list_make1($1); }
    9306                 :         103 :             | dostmt_opt_list dostmt_opt_item   { $$ = lappend($1, $2); }
    9307                 :             :         ;
    9308                 :             : 
    9309                 :             : dostmt_opt_item:
    9310                 :             :             Sconst
    9311                 :             :                 {
    9312                 :         708 :                     $$ = makeDefElem("as", (Node *) makeString($1), @1);
    9313                 :             :                 }
    9314                 :             :             | LANGUAGE NonReservedWord_or_Sconst
    9315                 :             :                 {
    9316                 :         103 :                     $$ = makeDefElem("language", (Node *) makeString($2), @1);
    9317                 :             :                 }
    9318                 :             :         ;
    9319                 :             : 
    9320                 :             : /*****************************************************************************
    9321                 :             :  *
    9322                 :             :  *      CREATE CAST / DROP CAST
    9323                 :             :  *
    9324                 :             :  *****************************************************************************/
    9325                 :             : 
    9326                 :             : CreateCastStmt: CREATE CAST '(' Typename AS Typename ')'
    9327                 :             :                     WITH FUNCTION function_with_argtypes cast_context
    9328                 :             :                 {
    9329                 :          82 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9330                 :             : 
    9331                 :          82 :                     n->sourcetype = $4;
    9332                 :          82 :                     n->targettype = $6;
    9333                 :          82 :                     n->func = $10;
    9334                 :          82 :                     n->context = (CoercionContext) $11;
    9335                 :          82 :                     n->inout = false;
    9336                 :          82 :                     $$ = (Node *) n;
    9337                 :             :                 }
    9338                 :             :             | CREATE CAST '(' Typename AS Typename ')'
    9339                 :             :                     WITHOUT FUNCTION cast_context
    9340                 :             :                 {
    9341                 :         101 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9342                 :             : 
    9343                 :         101 :                     n->sourcetype = $4;
    9344                 :         101 :                     n->targettype = $6;
    9345                 :         101 :                     n->func = NULL;
    9346                 :         101 :                     n->context = (CoercionContext) $10;
    9347                 :         101 :                     n->inout = false;
    9348                 :         101 :                     $$ = (Node *) n;
    9349                 :             :                 }
    9350                 :             :             | CREATE CAST '(' Typename AS Typename ')'
    9351                 :             :                     WITH INOUT cast_context
    9352                 :             :                 {
    9353                 :           5 :                     CreateCastStmt *n = makeNode(CreateCastStmt);
    9354                 :             : 
    9355                 :           5 :                     n->sourcetype = $4;
    9356                 :           5 :                     n->targettype = $6;
    9357                 :           5 :                     n->func = NULL;
    9358                 :           5 :                     n->context = (CoercionContext) $10;
    9359                 :           5 :                     n->inout = true;
    9360                 :           5 :                     $$ = (Node *) n;
    9361                 :             :                 }
    9362                 :             :         ;
    9363                 :             : 
    9364                 :          47 : cast_context:  AS IMPLICIT_P                    { $$ = COERCION_IMPLICIT; }
    9365                 :          30 :         | AS ASSIGNMENT                         { $$ = COERCION_ASSIGNMENT; }
    9366                 :         111 :         | /*EMPTY*/                             { $$ = COERCION_EXPLICIT; }
    9367                 :             :         ;
    9368                 :             : 
    9369                 :             : 
    9370                 :             : DropCastStmt: DROP CAST opt_if_exists '(' Typename AS Typename ')' opt_drop_behavior
    9371                 :             :                 {
    9372                 :          54 :                     DropStmt *n = makeNode(DropStmt);
    9373                 :             : 
    9374                 :          54 :                     n->removeType = OBJECT_CAST;
    9375                 :          54 :                     n->objects = list_make1(list_make2($5, $7));
    9376                 :          54 :                     n->behavior = $9;
    9377                 :          54 :                     n->missing_ok = $3;
    9378                 :          54 :                     n->concurrent = false;
    9379                 :          54 :                     $$ = (Node *) n;
    9380                 :             :                 }
    9381                 :             :         ;
    9382                 :             : 
    9383                 :          23 : opt_if_exists: IF_P EXISTS                      { $$ = true; }
    9384                 :          38 :         | /*EMPTY*/                             { $$ = false; }
    9385                 :             :         ;
    9386                 :             : 
    9387                 :             : 
    9388                 :             : /*****************************************************************************
    9389                 :             :  *
    9390                 :             :  *      CREATE TRANSFORM / DROP TRANSFORM
    9391                 :             :  *
    9392                 :             :  *****************************************************************************/
    9393                 :             : 
    9394                 :             : CreateTransformStmt: CREATE opt_or_replace TRANSFORM FOR Typename LANGUAGE name '(' transform_element_list ')'
    9395                 :             :                 {
    9396                 :          26 :                     CreateTransformStmt *n = makeNode(CreateTransformStmt);
    9397                 :             : 
    9398                 :          26 :                     n->replace = $2;
    9399                 :          26 :                     n->type_name = $5;
    9400                 :          26 :                     n->lang = $7;
    9401                 :          26 :                     n->fromsql = linitial($9);
    9402                 :          26 :                     n->tosql = lsecond($9);
    9403                 :          26 :                     $$ = (Node *) n;
    9404                 :             :                 }
    9405                 :             :         ;
    9406                 :             : 
    9407                 :             : transform_element_list: FROM SQL_P WITH FUNCTION function_with_argtypes ',' TO SQL_P WITH FUNCTION function_with_argtypes
    9408                 :             :                 {
    9409                 :          23 :                     $$ = list_make2($5, $11);
    9410                 :             :                 }
    9411                 :             :                 | TO SQL_P WITH FUNCTION function_with_argtypes ',' FROM SQL_P WITH FUNCTION function_with_argtypes
    9412                 :             :                 {
    9413                 :           0 :                     $$ = list_make2($11, $5);
    9414                 :             :                 }
    9415                 :             :                 | FROM SQL_P WITH FUNCTION function_with_argtypes
    9416                 :             :                 {
    9417                 :           2 :                     $$ = list_make2($5, NULL);
    9418                 :             :                 }
    9419                 :             :                 | TO SQL_P WITH FUNCTION function_with_argtypes
    9420                 :             :                 {
    9421                 :           1 :                     $$ = list_make2(NULL, $5);
    9422                 :             :                 }
    9423                 :             :         ;
    9424                 :             : 
    9425                 :             : 
    9426                 :             : DropTransformStmt: DROP TRANSFORM opt_if_exists FOR Typename LANGUAGE name opt_drop_behavior
    9427                 :             :                 {
    9428                 :           7 :                     DropStmt *n = makeNode(DropStmt);
    9429                 :             : 
    9430                 :           7 :                     n->removeType = OBJECT_TRANSFORM;
    9431                 :           7 :                     n->objects = list_make1(list_make2($5, makeString($7)));
    9432                 :           7 :                     n->behavior = $8;
    9433                 :           7 :                     n->missing_ok = $3;
    9434                 :           7 :                     $$ = (Node *) n;
    9435                 :             :                 }
    9436                 :             :         ;
    9437                 :             : 
    9438                 :             : 
    9439                 :             : /*****************************************************************************
    9440                 :             :  *
    9441                 :             :  *      QUERY:
    9442                 :             :  *
    9443                 :             :  *      REINDEX [ (options) ] {INDEX | TABLE | SCHEMA} [CONCURRENTLY] <name>
    9444                 :             :  *      REINDEX [ (options) ] {DATABASE | SYSTEM} [CONCURRENTLY] [<name>]
    9445                 :             :  *****************************************************************************/
    9446                 :             : 
    9447                 :             : ReindexStmt:
    9448                 :             :             REINDEX opt_utility_option_list reindex_target_relation opt_concurrently qualified_name
    9449                 :             :                 {
    9450                 :         606 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9451                 :             : 
    9452                 :         606 :                     n->kind = $3;
    9453                 :         606 :                     n->relation = $5;
    9454                 :         606 :                     n->name = NULL;
    9455                 :         606 :                     n->params = $2;
    9456         [ +  + ]:         606 :                     if ($4)
    9457                 :         350 :                         n->params = lappend(n->params,
    9458                 :         350 :                                             makeDefElem("concurrently", NULL, @4));
    9459                 :         606 :                     $$ = (Node *) n;
    9460                 :             :                 }
    9461                 :             :             | REINDEX opt_utility_option_list SCHEMA opt_concurrently name
    9462                 :             :                 {
    9463                 :          75 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9464                 :             : 
    9465                 :          75 :                     n->kind = REINDEX_OBJECT_SCHEMA;
    9466                 :          75 :                     n->relation = NULL;
    9467                 :          75 :                     n->name = $5;
    9468                 :          75 :                     n->params = $2;
    9469         [ +  + ]:          75 :                     if ($4)
    9470                 :          26 :                         n->params = lappend(n->params,
    9471                 :          26 :                                             makeDefElem("concurrently", NULL, @4));
    9472                 :          75 :                     $$ = (Node *) n;
    9473                 :             :                 }
    9474                 :             :             | REINDEX opt_utility_option_list reindex_target_all opt_concurrently opt_single_name
    9475                 :             :                 {
    9476                 :          36 :                     ReindexStmt *n = makeNode(ReindexStmt);
    9477                 :             : 
    9478                 :          36 :                     n->kind = $3;
    9479                 :          36 :                     n->relation = NULL;
    9480                 :          36 :                     n->name = $5;
    9481                 :          36 :                     n->params = $2;
    9482         [ +  + ]:          36 :                     if ($4)
    9483                 :           6 :                         n->params = lappend(n->params,
    9484                 :           6 :                                             makeDefElem("concurrently", NULL, @4));
    9485                 :          36 :                     $$ = (Node *) n;
    9486                 :             :                 }
    9487                 :             :         ;
    9488                 :             : reindex_target_relation:
    9489                 :         280 :             INDEX                   { $$ = REINDEX_OBJECT_INDEX; }
    9490                 :         326 :             | TABLE                 { $$ = REINDEX_OBJECT_TABLE; }
    9491                 :             :         ;
    9492                 :             : reindex_target_all:
    9493                 :          20 :             SYSTEM_P                { $$ = REINDEX_OBJECT_SYSTEM; }
    9494                 :          16 :             | DATABASE              { $$ = REINDEX_OBJECT_DATABASE; }
    9495                 :             :         ;
    9496                 :             : 
    9497                 :             : /*****************************************************************************
    9498                 :             :  *
    9499                 :             :  * ALTER TABLESPACE
    9500                 :             :  *
    9501                 :             :  *****************************************************************************/
    9502                 :             : 
    9503                 :             : AlterTblSpcStmt:
    9504                 :             :             ALTER TABLESPACE name SET reloptions
    9505                 :             :                 {
    9506                 :             :                     AlterTableSpaceOptionsStmt *n =
    9507                 :          11 :                         makeNode(AlterTableSpaceOptionsStmt);
    9508                 :             : 
    9509                 :          11 :                     n->tablespacename = $3;
    9510                 :          11 :                     n->options = $5;
    9511                 :          11 :                     n->isReset = false;
    9512                 :          11 :                     $$ = (Node *) n;
    9513                 :             :                 }
    9514                 :             :             | ALTER TABLESPACE name RESET reloptions
    9515                 :             :                 {
    9516                 :             :                     AlterTableSpaceOptionsStmt *n =
    9517                 :           8 :                         makeNode(AlterTableSpaceOptionsStmt);
    9518                 :             : 
    9519                 :           8 :                     n->tablespacename = $3;
    9520                 :           8 :                     n->options = $5;
    9521                 :           8 :                     n->isReset = true;
    9522                 :           8 :                     $$ = (Node *) n;
    9523                 :             :                 }
    9524                 :             :         ;
    9525                 :             : 
    9526                 :             : /*****************************************************************************
    9527                 :             :  *
    9528                 :             :  * ALTER THING name RENAME TO newname
    9529                 :             :  *
    9530                 :             :  *****************************************************************************/
    9531                 :             : 
    9532                 :             : RenameStmt: ALTER AGGREGATE aggregate_with_argtypes RENAME TO name
    9533                 :             :                 {
    9534                 :          28 :                     RenameStmt *n = makeNode(RenameStmt);
    9535                 :             : 
    9536                 :          28 :                     n->renameType = OBJECT_AGGREGATE;
    9537                 :          28 :                     n->object = (Node *) $3;
    9538                 :          28 :                     n->newname = $6;
    9539                 :          28 :                     n->missing_ok = false;
    9540                 :          28 :                     $$ = (Node *) n;
    9541                 :             :                 }
    9542                 :             :             | ALTER COLLATION any_name RENAME TO name
    9543                 :             :                 {
    9544                 :          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9545                 :             : 
    9546                 :          12 :                     n->renameType = OBJECT_COLLATION;
    9547                 :          12 :                     n->object = (Node *) $3;
    9548                 :          12 :                     n->newname = $6;
    9549                 :          12 :                     n->missing_ok = false;
    9550                 :          12 :                     $$ = (Node *) n;
    9551                 :             :                 }
    9552                 :             :             | ALTER CONVERSION_P any_name RENAME TO name
    9553                 :             :                 {
    9554                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
    9555                 :             : 
    9556                 :          16 :                     n->renameType = OBJECT_CONVERSION;
    9557                 :          16 :                     n->object = (Node *) $3;
    9558                 :          16 :                     n->newname = $6;
    9559                 :          16 :                     n->missing_ok = false;
    9560                 :          16 :                     $$ = (Node *) n;
    9561                 :             :                 }
    9562                 :             :             | ALTER DATABASE name RENAME TO name
    9563                 :             :                 {
    9564                 :           9 :                     RenameStmt *n = makeNode(RenameStmt);
    9565                 :             : 
    9566                 :           9 :                     n->renameType = OBJECT_DATABASE;
    9567                 :           9 :                     n->subname = $3;
    9568                 :           9 :                     n->newname = $6;
    9569                 :           9 :                     n->missing_ok = false;
    9570                 :           9 :                     $$ = (Node *) n;
    9571                 :             :                 }
    9572                 :             :             | ALTER DOMAIN_P any_name RENAME TO name
    9573                 :             :                 {
    9574                 :           4 :                     RenameStmt *n = makeNode(RenameStmt);
    9575                 :             : 
    9576                 :           4 :                     n->renameType = OBJECT_DOMAIN;
    9577                 :           4 :                     n->object = (Node *) $3;
    9578                 :           4 :                     n->newname = $6;
    9579                 :           4 :                     n->missing_ok = false;
    9580                 :           4 :                     $$ = (Node *) n;
    9581                 :             :                 }
    9582                 :             :             | ALTER DOMAIN_P any_name RENAME CONSTRAINT name TO name
    9583                 :             :                 {
    9584                 :           4 :                     RenameStmt *n = makeNode(RenameStmt);
    9585                 :             : 
    9586                 :           4 :                     n->renameType = OBJECT_DOMCONSTRAINT;
    9587                 :           4 :                     n->object = (Node *) $3;
    9588                 :           4 :                     n->subname = $6;
    9589                 :           4 :                     n->newname = $8;
    9590                 :           4 :                     $$ = (Node *) n;
    9591                 :             :                 }
    9592                 :             :             | ALTER FOREIGN DATA_P WRAPPER name RENAME TO name
    9593                 :             :                 {
    9594                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
    9595                 :             : 
    9596                 :          16 :                     n->renameType = OBJECT_FDW;
    9597                 :          16 :                     n->object = (Node *) makeString($5);
    9598                 :          16 :                     n->newname = $8;
    9599                 :          16 :                     n->missing_ok = false;
    9600                 :          16 :                     $$ = (Node *) n;
    9601                 :             :                 }
    9602                 :             :             | ALTER FUNCTION function_with_argtypes RENAME TO name
    9603                 :             :                 {
    9604                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
    9605                 :             : 
    9606                 :          16 :                     n->renameType = OBJECT_FUNCTION;
    9607                 :          16 :                     n->object = (Node *) $3;
    9608                 :          16 :                     n->newname = $6;
    9609                 :          16 :                     n->missing_ok = false;
    9610                 :          16 :                     $$ = (Node *) n;
    9611                 :             :                 }
    9612                 :             :             | ALTER GROUP_P RoleId RENAME TO RoleId
    9613                 :             :                 {
    9614                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9615                 :             : 
    9616                 :           0 :                     n->renameType = OBJECT_ROLE;
    9617                 :           0 :                     n->subname = $3;
    9618                 :           0 :                     n->newname = $6;
    9619                 :           0 :                     n->missing_ok = false;
    9620                 :           0 :                     $$ = (Node *) n;
    9621                 :             :                 }
    9622                 :             :             | ALTER opt_procedural LANGUAGE name RENAME TO name
    9623                 :             :                 {
    9624                 :          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9625                 :             : 
    9626                 :          12 :                     n->renameType = OBJECT_LANGUAGE;
    9627                 :          12 :                     n->object = (Node *) makeString($4);
    9628                 :          12 :                     n->newname = $7;
    9629                 :          12 :                     n->missing_ok = false;
    9630                 :          12 :                     $$ = (Node *) n;
    9631                 :             :                 }
    9632                 :             :             | ALTER OPERATOR CLASS any_name USING name RENAME TO name
    9633                 :             :                 {
    9634                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
    9635                 :             : 
    9636                 :          16 :                     n->renameType = OBJECT_OPCLASS;
    9637                 :          16 :                     n->object = (Node *) lcons(makeString($6), $4);
    9638                 :          16 :                     n->newname = $9;
    9639                 :          16 :                     n->missing_ok = false;
    9640                 :          16 :                     $$ = (Node *) n;
    9641                 :             :                 }
    9642                 :             :             | ALTER OPERATOR FAMILY any_name USING name RENAME TO name
    9643                 :             :                 {
    9644                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
    9645                 :             : 
    9646                 :          16 :                     n->renameType = OBJECT_OPFAMILY;
    9647                 :          16 :                     n->object = (Node *) lcons(makeString($6), $4);
    9648                 :          16 :                     n->newname = $9;
    9649                 :          16 :                     n->missing_ok = false;
    9650                 :          16 :                     $$ = (Node *) n;
    9651                 :             :                 }
    9652                 :             :             | ALTER POLICY name ON qualified_name RENAME TO name
    9653                 :             :                 {
    9654                 :          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9655                 :             : 
    9656                 :          12 :                     n->renameType = OBJECT_POLICY;
    9657                 :          12 :                     n->relation = $5;
    9658                 :          12 :                     n->subname = $3;
    9659                 :          12 :                     n->newname = $8;
    9660                 :          12 :                     n->missing_ok = false;
    9661                 :          12 :                     $$ = (Node *) n;
    9662                 :             :                 }
    9663                 :             :             | ALTER POLICY IF_P EXISTS name ON qualified_name RENAME TO name
    9664                 :             :                 {
    9665                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9666                 :             : 
    9667                 :           0 :                     n->renameType = OBJECT_POLICY;
    9668                 :           0 :                     n->relation = $7;
    9669                 :           0 :                     n->subname = $5;
    9670                 :           0 :                     n->newname = $10;
    9671                 :           0 :                     n->missing_ok = true;
    9672                 :           0 :                     $$ = (Node *) n;
    9673                 :             :                 }
    9674                 :             :             | ALTER PROCEDURE function_with_argtypes RENAME TO name
    9675                 :             :                 {
    9676                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9677                 :             : 
    9678                 :           0 :                     n->renameType = OBJECT_PROCEDURE;
    9679                 :           0 :                     n->object = (Node *) $3;
    9680                 :           0 :                     n->newname = $6;
    9681                 :           0 :                     n->missing_ok = false;
    9682                 :           0 :                     $$ = (Node *) n;
    9683                 :             :                 }
    9684                 :             :             | ALTER PUBLICATION name RENAME TO name
    9685                 :             :                 {
    9686                 :          24 :                     RenameStmt *n = makeNode(RenameStmt);
    9687                 :             : 
    9688                 :          24 :                     n->renameType = OBJECT_PUBLICATION;
    9689                 :          24 :                     n->object = (Node *) makeString($3);
    9690                 :          24 :                     n->newname = $6;
    9691                 :          24 :                     n->missing_ok = false;
    9692                 :          24 :                     $$ = (Node *) n;
    9693                 :             :                 }
    9694                 :             :             | ALTER ROUTINE function_with_argtypes RENAME TO name
    9695                 :             :                 {
    9696                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
    9697                 :             : 
    9698                 :          16 :                     n->renameType = OBJECT_ROUTINE;
    9699                 :          16 :                     n->object = (Node *) $3;
    9700                 :          16 :                     n->newname = $6;
    9701                 :          16 :                     n->missing_ok = false;
    9702                 :          16 :                     $$ = (Node *) n;
    9703                 :             :                 }
    9704                 :             :             | ALTER SCHEMA name RENAME TO name
    9705                 :             :                 {
    9706                 :          13 :                     RenameStmt *n = makeNode(RenameStmt);
    9707                 :             : 
    9708                 :          13 :                     n->renameType = OBJECT_SCHEMA;
    9709                 :          13 :                     n->subname = $3;
    9710                 :          13 :                     n->newname = $6;
    9711                 :          13 :                     n->missing_ok = false;
    9712                 :          13 :                     $$ = (Node *) n;
    9713                 :             :                 }
    9714                 :             :             | ALTER SERVER name RENAME TO name
    9715                 :             :                 {
    9716                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
    9717                 :             : 
    9718                 :          16 :                     n->renameType = OBJECT_FOREIGN_SERVER;
    9719                 :          16 :                     n->object = (Node *) makeString($3);
    9720                 :          16 :                     n->newname = $6;
    9721                 :          16 :                     n->missing_ok = false;
    9722                 :          16 :                     $$ = (Node *) n;
    9723                 :             :                 }
    9724                 :             :             | ALTER SUBSCRIPTION name RENAME TO name
    9725                 :             :                 {
    9726                 :          25 :                     RenameStmt *n = makeNode(RenameStmt);
    9727                 :             : 
    9728                 :          25 :                     n->renameType = OBJECT_SUBSCRIPTION;
    9729                 :          25 :                     n->object = (Node *) makeString($3);
    9730                 :          25 :                     n->newname = $6;
    9731                 :          25 :                     n->missing_ok = false;
    9732                 :          25 :                     $$ = (Node *) n;
    9733                 :             :                 }
    9734                 :             :             | ALTER TABLE relation_expr RENAME TO name
    9735                 :             :                 {
    9736                 :         174 :                     RenameStmt *n = makeNode(RenameStmt);
    9737                 :             : 
    9738                 :         174 :                     n->renameType = OBJECT_TABLE;
    9739                 :         174 :                     n->relation = $3;
    9740                 :         174 :                     n->subname = NULL;
    9741                 :         174 :                     n->newname = $6;
    9742                 :         174 :                     n->missing_ok = false;
    9743                 :         174 :                     $$ = (Node *) n;
    9744                 :             :                 }
    9745                 :             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME TO name
    9746                 :             :                 {
    9747                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9748                 :             : 
    9749                 :           0 :                     n->renameType = OBJECT_TABLE;
    9750                 :           0 :                     n->relation = $5;
    9751                 :           0 :                     n->subname = NULL;
    9752                 :           0 :                     n->newname = $8;
    9753                 :           0 :                     n->missing_ok = true;
    9754                 :           0 :                     $$ = (Node *) n;
    9755                 :             :                 }
    9756                 :             :             | ALTER SEQUENCE qualified_name RENAME TO name
    9757                 :             :                 {
    9758                 :           1 :                     RenameStmt *n = makeNode(RenameStmt);
    9759                 :             : 
    9760                 :           1 :                     n->renameType = OBJECT_SEQUENCE;
    9761                 :           1 :                     n->relation = $3;
    9762                 :           1 :                     n->subname = NULL;
    9763                 :           1 :                     n->newname = $6;
    9764                 :           1 :                     n->missing_ok = false;
    9765                 :           1 :                     $$ = (Node *) n;
    9766                 :             :                 }
    9767                 :             :             | ALTER SEQUENCE IF_P EXISTS qualified_name RENAME TO name
    9768                 :             :                 {
    9769                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9770                 :             : 
    9771                 :           0 :                     n->renameType = OBJECT_SEQUENCE;
    9772                 :           0 :                     n->relation = $5;
    9773                 :           0 :                     n->subname = NULL;
    9774                 :           0 :                     n->newname = $8;
    9775                 :           0 :                     n->missing_ok = true;
    9776                 :           0 :                     $$ = (Node *) n;
    9777                 :             :                 }
    9778                 :             :             | ALTER VIEW qualified_name RENAME TO name
    9779                 :             :                 {
    9780                 :           4 :                     RenameStmt *n = makeNode(RenameStmt);
    9781                 :             : 
    9782                 :           4 :                     n->renameType = OBJECT_VIEW;
    9783                 :           4 :                     n->relation = $3;
    9784                 :           4 :                     n->subname = NULL;
    9785                 :           4 :                     n->newname = $6;
    9786                 :           4 :                     n->missing_ok = false;
    9787                 :           4 :                     $$ = (Node *) n;
    9788                 :             :                 }
    9789                 :             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME TO name
    9790                 :             :                 {
    9791                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9792                 :             : 
    9793                 :           0 :                     n->renameType = OBJECT_VIEW;
    9794                 :           0 :                     n->relation = $5;
    9795                 :           0 :                     n->subname = NULL;
    9796                 :           0 :                     n->newname = $8;
    9797                 :           0 :                     n->missing_ok = true;
    9798                 :           0 :                     $$ = (Node *) n;
    9799                 :             :                 }
    9800                 :             :             | ALTER MATERIALIZED VIEW qualified_name RENAME TO name
    9801                 :             :                 {
    9802                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9803                 :             : 
    9804                 :           0 :                     n->renameType = OBJECT_MATVIEW;
    9805                 :           0 :                     n->relation = $4;
    9806                 :           0 :                     n->subname = NULL;
    9807                 :           0 :                     n->newname = $7;
    9808                 :           0 :                     n->missing_ok = false;
    9809                 :           0 :                     $$ = (Node *) n;
    9810                 :             :                 }
    9811                 :             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME TO name
    9812                 :             :                 {
    9813                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9814                 :             : 
    9815                 :           0 :                     n->renameType = OBJECT_MATVIEW;
    9816                 :           0 :                     n->relation = $6;
    9817                 :           0 :                     n->subname = NULL;
    9818                 :           0 :                     n->newname = $9;
    9819                 :           0 :                     n->missing_ok = true;
    9820                 :           0 :                     $$ = (Node *) n;
    9821                 :             :                 }
    9822                 :             :             | ALTER INDEX qualified_name RENAME TO name
    9823                 :             :                 {
    9824                 :         108 :                     RenameStmt *n = makeNode(RenameStmt);
    9825                 :             : 
    9826                 :         108 :                     n->renameType = OBJECT_INDEX;
    9827                 :         108 :                     n->relation = $3;
    9828                 :         108 :                     n->subname = NULL;
    9829                 :         108 :                     n->newname = $6;
    9830                 :         108 :                     n->missing_ok = false;
    9831                 :         108 :                     $$ = (Node *) n;
    9832                 :             :                 }
    9833                 :             :             | ALTER INDEX IF_P EXISTS qualified_name RENAME TO name
    9834                 :             :                 {
    9835                 :           8 :                     RenameStmt *n = makeNode(RenameStmt);
    9836                 :             : 
    9837                 :           8 :                     n->renameType = OBJECT_INDEX;
    9838                 :           8 :                     n->relation = $5;
    9839                 :           8 :                     n->subname = NULL;
    9840                 :           8 :                     n->newname = $8;
    9841                 :           8 :                     n->missing_ok = true;
    9842                 :           8 :                     $$ = (Node *) n;
    9843                 :             :                 }
    9844                 :             :             | ALTER FOREIGN TABLE relation_expr RENAME TO name
    9845                 :             :                 {
    9846                 :           4 :                     RenameStmt *n = makeNode(RenameStmt);
    9847                 :             : 
    9848                 :           4 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9849                 :           4 :                     n->relation = $4;
    9850                 :           4 :                     n->subname = NULL;
    9851                 :           4 :                     n->newname = $7;
    9852                 :           4 :                     n->missing_ok = false;
    9853                 :           4 :                     $$ = (Node *) n;
    9854                 :             :                 }
    9855                 :             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME TO name
    9856                 :             :                 {
    9857                 :           4 :                     RenameStmt *n = makeNode(RenameStmt);
    9858                 :             : 
    9859                 :           4 :                     n->renameType = OBJECT_FOREIGN_TABLE;
    9860                 :           4 :                     n->relation = $6;
    9861                 :           4 :                     n->subname = NULL;
    9862                 :           4 :                     n->newname = $9;
    9863                 :           4 :                     n->missing_ok = true;
    9864                 :           4 :                     $$ = (Node *) n;
    9865                 :             :                 }
    9866                 :             :             | ALTER TABLE relation_expr RENAME opt_column name TO name
    9867                 :             :                 {
    9868                 :         161 :                     RenameStmt *n = makeNode(RenameStmt);
    9869                 :             : 
    9870                 :         161 :                     n->renameType = OBJECT_COLUMN;
    9871                 :         161 :                     n->relationType = OBJECT_TABLE;
    9872                 :         161 :                     n->relation = $3;
    9873                 :         161 :                     n->subname = $6;
    9874                 :         161 :                     n->newname = $8;
    9875                 :         161 :                     n->missing_ok = false;
    9876                 :         161 :                     $$ = (Node *) n;
    9877                 :             :                 }
    9878                 :             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9879                 :             :                 {
    9880                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
    9881                 :             : 
    9882                 :          16 :                     n->renameType = OBJECT_COLUMN;
    9883                 :          16 :                     n->relationType = OBJECT_TABLE;
    9884                 :          16 :                     n->relation = $5;
    9885                 :          16 :                     n->subname = $8;
    9886                 :          16 :                     n->newname = $10;
    9887                 :          16 :                     n->missing_ok = true;
    9888                 :          16 :                     $$ = (Node *) n;
    9889                 :             :                 }
    9890                 :             :             | ALTER VIEW qualified_name RENAME opt_column name TO name
    9891                 :             :                 {
    9892                 :          12 :                     RenameStmt *n = makeNode(RenameStmt);
    9893                 :             : 
    9894                 :          12 :                     n->renameType = OBJECT_COLUMN;
    9895                 :          12 :                     n->relationType = OBJECT_VIEW;
    9896                 :          12 :                     n->relation = $3;
    9897                 :          12 :                     n->subname = $6;
    9898                 :          12 :                     n->newname = $8;
    9899                 :          12 :                     n->missing_ok = false;
    9900                 :          12 :                     $$ = (Node *) n;
    9901                 :             :                 }
    9902                 :             :             | ALTER VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9903                 :             :                 {
    9904                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9905                 :             : 
    9906                 :           0 :                     n->renameType = OBJECT_COLUMN;
    9907                 :           0 :                     n->relationType = OBJECT_VIEW;
    9908                 :           0 :                     n->relation = $5;
    9909                 :           0 :                     n->subname = $8;
    9910                 :           0 :                     n->newname = $10;
    9911                 :           0 :                     n->missing_ok = true;
    9912                 :           0 :                     $$ = (Node *) n;
    9913                 :             :                 }
    9914                 :             :             | ALTER MATERIALIZED VIEW qualified_name RENAME opt_column name TO name
    9915                 :             :                 {
    9916                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9917                 :             : 
    9918                 :           0 :                     n->renameType = OBJECT_COLUMN;
    9919                 :           0 :                     n->relationType = OBJECT_MATVIEW;
    9920                 :           0 :                     n->relation = $4;
    9921                 :           0 :                     n->subname = $7;
    9922                 :           0 :                     n->newname = $9;
    9923                 :           0 :                     n->missing_ok = false;
    9924                 :           0 :                     $$ = (Node *) n;
    9925                 :             :                 }
    9926                 :             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name RENAME opt_column name TO name
    9927                 :             :                 {
    9928                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
    9929                 :             : 
    9930                 :           0 :                     n->renameType = OBJECT_COLUMN;
    9931                 :           0 :                     n->relationType = OBJECT_MATVIEW;
    9932                 :           0 :                     n->relation = $6;
    9933                 :           0 :                     n->subname = $9;
    9934                 :           0 :                     n->newname = $11;
    9935                 :           0 :                     n->missing_ok = true;
    9936                 :           0 :                     $$ = (Node *) n;
    9937                 :             :                 }
    9938                 :             :             | ALTER TABLE relation_expr RENAME CONSTRAINT name TO name
    9939                 :             :                 {
    9940                 :          52 :                     RenameStmt *n = makeNode(RenameStmt);
    9941                 :             : 
    9942                 :          52 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9943                 :          52 :                     n->relation = $3;
    9944                 :          52 :                     n->subname = $6;
    9945                 :          52 :                     n->newname = $8;
    9946                 :          52 :                     n->missing_ok = false;
    9947                 :          52 :                     $$ = (Node *) n;
    9948                 :             :                 }
    9949                 :             :             | ALTER TABLE IF_P EXISTS relation_expr RENAME CONSTRAINT name TO name
    9950                 :             :                 {
    9951                 :           4 :                     RenameStmt *n = makeNode(RenameStmt);
    9952                 :             : 
    9953                 :           4 :                     n->renameType = OBJECT_TABCONSTRAINT;
    9954                 :           4 :                     n->relation = $5;
    9955                 :           4 :                     n->subname = $8;
    9956                 :           4 :                     n->newname = $10;
    9957                 :           4 :                     n->missing_ok = true;
    9958                 :           4 :                     $$ = (Node *) n;
    9959                 :             :                 }
    9960                 :             :             | ALTER FOREIGN TABLE relation_expr RENAME opt_column name TO name
    9961                 :             :                 {
    9962                 :           4 :                     RenameStmt *n = makeNode(RenameStmt);
    9963                 :             : 
    9964                 :           4 :                     n->renameType = OBJECT_COLUMN;
    9965                 :           4 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9966                 :           4 :                     n->relation = $4;
    9967                 :           4 :                     n->subname = $7;
    9968                 :           4 :                     n->newname = $9;
    9969                 :           4 :                     n->missing_ok = false;
    9970                 :           4 :                     $$ = (Node *) n;
    9971                 :             :                 }
    9972                 :             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr RENAME opt_column name TO name
    9973                 :             :                 {
    9974                 :           4 :                     RenameStmt *n = makeNode(RenameStmt);
    9975                 :             : 
    9976                 :           4 :                     n->renameType = OBJECT_COLUMN;
    9977                 :           4 :                     n->relationType = OBJECT_FOREIGN_TABLE;
    9978                 :           4 :                     n->relation = $6;
    9979                 :           4 :                     n->subname = $9;
    9980                 :           4 :                     n->newname = $11;
    9981                 :           4 :                     n->missing_ok = true;
    9982                 :           4 :                     $$ = (Node *) n;
    9983                 :             :                 }
    9984                 :             :             | ALTER RULE name ON qualified_name RENAME TO name
    9985                 :             :                 {
    9986                 :          30 :                     RenameStmt *n = makeNode(RenameStmt);
    9987                 :             : 
    9988                 :          30 :                     n->renameType = OBJECT_RULE;
    9989                 :          30 :                     n->relation = $5;
    9990                 :          30 :                     n->subname = $3;
    9991                 :          30 :                     n->newname = $8;
    9992                 :          30 :                     n->missing_ok = false;
    9993                 :          30 :                     $$ = (Node *) n;
    9994                 :             :                 }
    9995                 :             :             | ALTER TRIGGER name ON qualified_name RENAME TO name
    9996                 :             :                 {
    9997                 :          38 :                     RenameStmt *n = makeNode(RenameStmt);
    9998                 :             : 
    9999                 :          38 :                     n->renameType = OBJECT_TRIGGER;
   10000                 :          38 :                     n->relation = $5;
   10001                 :          38 :                     n->subname = $3;
   10002                 :          38 :                     n->newname = $8;
   10003                 :          38 :                     n->missing_ok = false;
   10004                 :          38 :                     $$ = (Node *) n;
   10005                 :             :                 }
   10006                 :             :             | ALTER EVENT TRIGGER name RENAME TO name
   10007                 :             :                 {
   10008                 :           8 :                     RenameStmt *n = makeNode(RenameStmt);
   10009                 :             : 
   10010                 :           8 :                     n->renameType = OBJECT_EVENT_TRIGGER;
   10011                 :           8 :                     n->object = (Node *) makeString($4);
   10012                 :           8 :                     n->newname = $7;
   10013                 :           8 :                     $$ = (Node *) n;
   10014                 :             :                 }
   10015                 :             :             | ALTER ROLE RoleId RENAME TO RoleId
   10016                 :             :                 {
   10017                 :          20 :                     RenameStmt *n = makeNode(RenameStmt);
   10018                 :             : 
   10019                 :          20 :                     n->renameType = OBJECT_ROLE;
   10020                 :          20 :                     n->subname = $3;
   10021                 :          20 :                     n->newname = $6;
   10022                 :          20 :                     n->missing_ok = false;
   10023                 :          20 :                     $$ = (Node *) n;
   10024                 :             :                 }
   10025                 :             :             | ALTER USER RoleId RENAME TO RoleId
   10026                 :             :                 {
   10027                 :           0 :                     RenameStmt *n = makeNode(RenameStmt);
   10028                 :             : 
   10029                 :           0 :                     n->renameType = OBJECT_ROLE;
   10030                 :           0 :                     n->subname = $3;
   10031                 :           0 :                     n->newname = $6;
   10032                 :           0 :                     n->missing_ok = false;
   10033                 :           0 :                     $$ = (Node *) n;
   10034                 :             :                 }
   10035                 :             :             | ALTER TABLESPACE name RENAME TO name
   10036                 :             :                 {
   10037                 :          15 :                     RenameStmt *n = makeNode(RenameStmt);
   10038                 :             : 
   10039                 :          15 :                     n->renameType = OBJECT_TABLESPACE;
   10040                 :          15 :                     n->subname = $3;
   10041                 :          15 :                     n->newname = $6;
   10042                 :          15 :                     n->missing_ok = false;
   10043                 :          15 :                     $$ = (Node *) n;
   10044                 :             :                 }
   10045                 :             :             | ALTER STATISTICS any_name RENAME TO name
   10046                 :             :                 {
   10047                 :          20 :                     RenameStmt *n = makeNode(RenameStmt);
   10048                 :             : 
   10049                 :          20 :                     n->renameType = OBJECT_STATISTIC_EXT;
   10050                 :          20 :                     n->object = (Node *) $3;
   10051                 :          20 :                     n->newname = $6;
   10052                 :          20 :                     n->missing_ok = false;
   10053                 :          20 :                     $$ = (Node *) n;
   10054                 :             :                 }
   10055                 :             :             | ALTER TEXT_P SEARCH PARSER any_name RENAME TO name
   10056                 :             :                 {
   10057                 :           8 :                     RenameStmt *n = makeNode(RenameStmt);
   10058                 :             : 
   10059                 :           8 :                     n->renameType = OBJECT_TSPARSER;
   10060                 :           8 :                     n->object = (Node *) $5;
   10061                 :           8 :                     n->newname = $8;
   10062                 :           8 :                     n->missing_ok = false;
   10063                 :           8 :                     $$ = (Node *) n;
   10064                 :             :                 }
   10065                 :             :             | ALTER TEXT_P SEARCH DICTIONARY any_name RENAME TO name
   10066                 :             :                 {
   10067                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
   10068                 :             : 
   10069                 :          16 :                     n->renameType = OBJECT_TSDICTIONARY;
   10070                 :          16 :                     n->object = (Node *) $5;
   10071                 :          16 :                     n->newname = $8;
   10072                 :          16 :                     n->missing_ok = false;
   10073                 :          16 :                     $$ = (Node *) n;
   10074                 :             :                 }
   10075                 :             :             | ALTER TEXT_P SEARCH TEMPLATE any_name RENAME TO name
   10076                 :             :                 {
   10077                 :           8 :                     RenameStmt *n = makeNode(RenameStmt);
   10078                 :             : 
   10079                 :           8 :                     n->renameType = OBJECT_TSTEMPLATE;
   10080                 :           8 :                     n->object = (Node *) $5;
   10081                 :           8 :                     n->newname = $8;
   10082                 :           8 :                     n->missing_ok = false;
   10083                 :           8 :                     $$ = (Node *) n;
   10084                 :             :                 }
   10085                 :             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name RENAME TO name
   10086                 :             :                 {
   10087                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
   10088                 :             : 
   10089                 :          16 :                     n->renameType = OBJECT_TSCONFIGURATION;
   10090                 :          16 :                     n->object = (Node *) $5;
   10091                 :          16 :                     n->newname = $8;
   10092                 :          16 :                     n->missing_ok = false;
   10093                 :          16 :                     $$ = (Node *) n;
   10094                 :             :                 }
   10095                 :             :             | ALTER TYPE_P any_name RENAME TO name
   10096                 :             :                 {
   10097                 :          17 :                     RenameStmt *n = makeNode(RenameStmt);
   10098                 :             : 
   10099                 :          17 :                     n->renameType = OBJECT_TYPE;
   10100                 :          17 :                     n->object = (Node *) $3;
   10101                 :          17 :                     n->newname = $6;
   10102                 :          17 :                     n->missing_ok = false;
   10103                 :          17 :                     $$ = (Node *) n;
   10104                 :             :                 }
   10105                 :             :             | ALTER TYPE_P any_name RENAME ATTRIBUTE name TO name opt_drop_behavior
   10106                 :             :                 {
   10107                 :          16 :                     RenameStmt *n = makeNode(RenameStmt);
   10108                 :             : 
   10109                 :          16 :                     n->renameType = OBJECT_ATTRIBUTE;
   10110                 :          16 :                     n->relationType = OBJECT_TYPE;
   10111                 :          16 :                     n->relation = makeRangeVarFromAnyName($3, @3, yyscanner);
   10112                 :          16 :                     n->subname = $6;
   10113                 :          16 :                     n->newname = $8;
   10114                 :          16 :                     n->behavior = $9;
   10115                 :          16 :                     n->missing_ok = false;
   10116                 :          16 :                     $$ = (Node *) n;
   10117                 :             :                 }
   10118                 :             :         ;
   10119                 :             : 
   10120                 :             : opt_column: COLUMN
   10121                 :             :             | /*EMPTY*/
   10122                 :             :         ;
   10123                 :             : 
   10124                 :         122 : opt_set_data: SET DATA_P                            { $$ = 1; }
   10125                 :         697 :             | /*EMPTY*/                             { $$ = 0; }
   10126                 :             :         ;
   10127                 :             : 
   10128                 :             : /*****************************************************************************
   10129                 :             :  *
   10130                 :             :  * ALTER THING name DEPENDS ON EXTENSION name
   10131                 :             :  *
   10132                 :             :  *****************************************************************************/
   10133                 :             : 
   10134                 :             : AlterObjectDependsStmt:
   10135                 :             :             ALTER FUNCTION function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10136                 :             :                 {
   10137                 :           6 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10138                 :             : 
   10139                 :           6 :                     n->objectType = OBJECT_FUNCTION;
   10140                 :           6 :                     n->object = (Node *) $3;
   10141                 :           6 :                     n->extname = makeString($8);
   10142                 :           6 :                     n->remove = $4;
   10143                 :           6 :                     $$ = (Node *) n;
   10144                 :             :                 }
   10145                 :             :             | ALTER PROCEDURE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10146                 :             :                 {
   10147                 :           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10148                 :             : 
   10149                 :           0 :                     n->objectType = OBJECT_PROCEDURE;
   10150                 :           0 :                     n->object = (Node *) $3;
   10151                 :           0 :                     n->extname = makeString($8);
   10152                 :           0 :                     n->remove = $4;
   10153                 :           0 :                     $$ = (Node *) n;
   10154                 :             :                 }
   10155                 :             :             | ALTER ROUTINE function_with_argtypes opt_no DEPENDS ON EXTENSION name
   10156                 :             :                 {
   10157                 :           0 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10158                 :             : 
   10159                 :           0 :                     n->objectType = OBJECT_ROUTINE;
   10160                 :           0 :                     n->object = (Node *) $3;
   10161                 :           0 :                     n->extname = makeString($8);
   10162                 :           0 :                     n->remove = $4;
   10163                 :           0 :                     $$ = (Node *) n;
   10164                 :             :                 }
   10165                 :             :             | ALTER TRIGGER name ON qualified_name opt_no DEPENDS ON EXTENSION name
   10166                 :             :                 {
   10167                 :           5 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10168                 :             : 
   10169                 :           5 :                     n->objectType = OBJECT_TRIGGER;
   10170                 :           5 :                     n->relation = $5;
   10171                 :           5 :                     n->object = (Node *) list_make1(makeString($3));
   10172                 :           5 :                     n->extname = makeString($10);
   10173                 :           5 :                     n->remove = $6;
   10174                 :           5 :                     $$ = (Node *) n;
   10175                 :             :                 }
   10176                 :             :             | ALTER MATERIALIZED VIEW qualified_name opt_no DEPENDS ON EXTENSION name
   10177                 :             :                 {
   10178                 :           5 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10179                 :             : 
   10180                 :           5 :                     n->objectType = OBJECT_MATVIEW;
   10181                 :           5 :                     n->relation = $4;
   10182                 :           5 :                     n->extname = makeString($9);
   10183                 :           5 :                     n->remove = $5;
   10184                 :           5 :                     $$ = (Node *) n;
   10185                 :             :                 }
   10186                 :             :             | ALTER INDEX qualified_name opt_no DEPENDS ON EXTENSION name
   10187                 :             :                 {
   10188                 :           7 :                     AlterObjectDependsStmt *n = makeNode(AlterObjectDependsStmt);
   10189                 :             : 
   10190                 :           7 :                     n->objectType = OBJECT_INDEX;
   10191                 :           7 :                     n->relation = $3;
   10192                 :           7 :                     n->extname = makeString($8);
   10193                 :           7 :                     n->remove = $4;
   10194                 :           7 :                     $$ = (Node *) n;
   10195                 :             :                 }
   10196                 :             :         ;
   10197                 :             : 
   10198                 :           4 : opt_no:     NO              { $$ = true; }
   10199                 :          19 :             | /* EMPTY */   { $$ = false;   }
   10200                 :             :         ;
   10201                 :             : 
   10202                 :             : /*****************************************************************************
   10203                 :             :  *
   10204                 :             :  * ALTER THING name SET SCHEMA name
   10205                 :             :  *
   10206                 :             :  *****************************************************************************/
   10207                 :             : 
   10208                 :             : AlterObjectSchemaStmt:
   10209                 :             :             ALTER AGGREGATE aggregate_with_argtypes SET SCHEMA name
   10210                 :             :                 {
   10211                 :          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10212                 :             : 
   10213                 :          16 :                     n->objectType = OBJECT_AGGREGATE;
   10214                 :          16 :                     n->object = (Node *) $3;
   10215                 :          16 :                     n->newschema = $6;
   10216                 :          16 :                     n->missing_ok = false;
   10217                 :          16 :                     $$ = (Node *) n;
   10218                 :             :                 }
   10219                 :             :             | ALTER COLLATION any_name SET SCHEMA name
   10220                 :             :                 {
   10221                 :           4 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10222                 :             : 
   10223                 :           4 :                     n->objectType = OBJECT_COLLATION;
   10224                 :           4 :                     n->object = (Node *) $3;
   10225                 :           4 :                     n->newschema = $6;
   10226                 :           4 :                     n->missing_ok = false;
   10227                 :           4 :                     $$ = (Node *) n;
   10228                 :             :                 }
   10229                 :             :             | ALTER CONVERSION_P any_name SET SCHEMA name
   10230                 :             :                 {
   10231                 :          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10232                 :             : 
   10233                 :          16 :                     n->objectType = OBJECT_CONVERSION;
   10234                 :          16 :                     n->object = (Node *) $3;
   10235                 :          16 :                     n->newschema = $6;
   10236                 :          16 :                     n->missing_ok = false;
   10237                 :          16 :                     $$ = (Node *) n;
   10238                 :             :                 }
   10239                 :             :             | ALTER DOMAIN_P any_name SET SCHEMA name
   10240                 :             :                 {
   10241                 :           4 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10242                 :             : 
   10243                 :           4 :                     n->objectType = OBJECT_DOMAIN;
   10244                 :           4 :                     n->object = (Node *) $3;
   10245                 :           4 :                     n->newschema = $6;
   10246                 :           4 :                     n->missing_ok = false;
   10247                 :           4 :                     $$ = (Node *) n;
   10248                 :             :                 }
   10249                 :             :             | ALTER EXTENSION name SET SCHEMA name
   10250                 :             :                 {
   10251                 :           6 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10252                 :             : 
   10253                 :           6 :                     n->objectType = OBJECT_EXTENSION;
   10254                 :           6 :                     n->object = (Node *) makeString($3);
   10255                 :           6 :                     n->newschema = $6;
   10256                 :           6 :                     n->missing_ok = false;
   10257                 :           6 :                     $$ = (Node *) n;
   10258                 :             :                 }
   10259                 :             :             | ALTER FUNCTION function_with_argtypes SET SCHEMA name
   10260                 :             :                 {
   10261                 :          29 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10262                 :             : 
   10263                 :          29 :                     n->objectType = OBJECT_FUNCTION;
   10264                 :          29 :                     n->object = (Node *) $3;
   10265                 :          29 :                     n->newschema = $6;
   10266                 :          29 :                     n->missing_ok = false;
   10267                 :          29 :                     $$ = (Node *) n;
   10268                 :             :                 }
   10269                 :             :             | ALTER OPERATOR operator_with_argtypes SET SCHEMA name
   10270                 :             :                 {
   10271                 :          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10272                 :             : 
   10273                 :          12 :                     n->objectType = OBJECT_OPERATOR;
   10274                 :          12 :                     n->object = (Node *) $3;
   10275                 :          12 :                     n->newschema = $6;
   10276                 :          12 :                     n->missing_ok = false;
   10277                 :          12 :                     $$ = (Node *) n;
   10278                 :             :                 }
   10279                 :             :             | ALTER OPERATOR CLASS any_name USING name SET SCHEMA name
   10280                 :             :                 {
   10281                 :          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10282                 :             : 
   10283                 :          16 :                     n->objectType = OBJECT_OPCLASS;
   10284                 :          16 :                     n->object = (Node *) lcons(makeString($6), $4);
   10285                 :          16 :                     n->newschema = $9;
   10286                 :          16 :                     n->missing_ok = false;
   10287                 :          16 :                     $$ = (Node *) n;
   10288                 :             :                 }
   10289                 :             :             | ALTER OPERATOR FAMILY any_name USING name SET SCHEMA name
   10290                 :             :                 {
   10291                 :          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10292                 :             : 
   10293                 :          16 :                     n->objectType = OBJECT_OPFAMILY;
   10294                 :          16 :                     n->object = (Node *) lcons(makeString($6), $4);
   10295                 :          16 :                     n->newschema = $9;
   10296                 :          16 :                     n->missing_ok = false;
   10297                 :          16 :                     $$ = (Node *) n;
   10298                 :             :                 }
   10299                 :             :             | ALTER PROCEDURE function_with_argtypes SET SCHEMA name
   10300                 :             :                 {
   10301                 :           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10302                 :             : 
   10303                 :           0 :                     n->objectType = OBJECT_PROCEDURE;
   10304                 :           0 :                     n->object = (Node *) $3;
   10305                 :           0 :                     n->newschema = $6;
   10306                 :           0 :                     n->missing_ok = false;
   10307                 :           0 :                     $$ = (Node *) n;
   10308                 :             :                 }
   10309                 :             :             | ALTER ROUTINE function_with_argtypes SET SCHEMA name
   10310                 :             :                 {
   10311                 :           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10312                 :             : 
   10313                 :           0 :                     n->objectType = OBJECT_ROUTINE;
   10314                 :           0 :                     n->object = (Node *) $3;
   10315                 :           0 :                     n->newschema = $6;
   10316                 :           0 :                     n->missing_ok = false;
   10317                 :           0 :                     $$ = (Node *) n;
   10318                 :             :                 }
   10319                 :             :             | ALTER TABLE relation_expr SET SCHEMA name
   10320                 :             :                 {
   10321                 :          51 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10322                 :             : 
   10323                 :          51 :                     n->objectType = OBJECT_TABLE;
   10324                 :          51 :                     n->relation = $3;
   10325                 :          51 :                     n->newschema = $6;
   10326                 :          51 :                     n->missing_ok = false;
   10327                 :          51 :                     $$ = (Node *) n;
   10328                 :             :                 }
   10329                 :             :             | ALTER TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10330                 :             :                 {
   10331                 :           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10332                 :             : 
   10333                 :           8 :                     n->objectType = OBJECT_TABLE;
   10334                 :           8 :                     n->relation = $5;
   10335                 :           8 :                     n->newschema = $8;
   10336                 :           8 :                     n->missing_ok = true;
   10337                 :           8 :                     $$ = (Node *) n;
   10338                 :             :                 }
   10339                 :             :             | ALTER STATISTICS any_name SET SCHEMA name
   10340                 :             :                 {
   10341                 :          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10342                 :             : 
   10343                 :          12 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10344                 :          12 :                     n->object = (Node *) $3;
   10345                 :          12 :                     n->newschema = $6;
   10346                 :          12 :                     n->missing_ok = false;
   10347                 :          12 :                     $$ = (Node *) n;
   10348                 :             :                 }
   10349                 :             :             | ALTER TEXT_P SEARCH PARSER any_name SET SCHEMA name
   10350                 :             :                 {
   10351                 :          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10352                 :             : 
   10353                 :          12 :                     n->objectType = OBJECT_TSPARSER;
   10354                 :          12 :                     n->object = (Node *) $5;
   10355                 :          12 :                     n->newschema = $8;
   10356                 :          12 :                     n->missing_ok = false;
   10357                 :          12 :                     $$ = (Node *) n;
   10358                 :             :                 }
   10359                 :             :             | ALTER TEXT_P SEARCH DICTIONARY any_name SET SCHEMA name
   10360                 :             :                 {
   10361                 :          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10362                 :             : 
   10363                 :          16 :                     n->objectType = OBJECT_TSDICTIONARY;
   10364                 :          16 :                     n->object = (Node *) $5;
   10365                 :          16 :                     n->newschema = $8;
   10366                 :          16 :                     n->missing_ok = false;
   10367                 :          16 :                     $$ = (Node *) n;
   10368                 :             :                 }
   10369                 :             :             | ALTER TEXT_P SEARCH TEMPLATE any_name SET SCHEMA name
   10370                 :             :                 {
   10371                 :          12 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10372                 :             : 
   10373                 :          12 :                     n->objectType = OBJECT_TSTEMPLATE;
   10374                 :          12 :                     n->object = (Node *) $5;
   10375                 :          12 :                     n->newschema = $8;
   10376                 :          12 :                     n->missing_ok = false;
   10377                 :          12 :                     $$ = (Node *) n;
   10378                 :             :                 }
   10379                 :             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name SET SCHEMA name
   10380                 :             :                 {
   10381                 :          16 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10382                 :             : 
   10383                 :          16 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10384                 :          16 :                     n->object = (Node *) $5;
   10385                 :          16 :                     n->newschema = $8;
   10386                 :          16 :                     n->missing_ok = false;
   10387                 :          16 :                     $$ = (Node *) n;
   10388                 :             :                 }
   10389                 :             :             | ALTER SEQUENCE qualified_name SET SCHEMA name
   10390                 :             :                 {
   10391                 :           5 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10392                 :             : 
   10393                 :           5 :                     n->objectType = OBJECT_SEQUENCE;
   10394                 :           5 :                     n->relation = $3;
   10395                 :           5 :                     n->newschema = $6;
   10396                 :           5 :                     n->missing_ok = false;
   10397                 :           5 :                     $$ = (Node *) n;
   10398                 :             :                 }
   10399                 :             :             | ALTER SEQUENCE IF_P EXISTS qualified_name SET SCHEMA name
   10400                 :             :                 {
   10401                 :           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10402                 :             : 
   10403                 :           0 :                     n->objectType = OBJECT_SEQUENCE;
   10404                 :           0 :                     n->relation = $5;
   10405                 :           0 :                     n->newschema = $8;
   10406                 :           0 :                     n->missing_ok = true;
   10407                 :           0 :                     $$ = (Node *) n;
   10408                 :             :                 }
   10409                 :             :             | ALTER VIEW qualified_name SET SCHEMA name
   10410                 :             :                 {
   10411                 :           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10412                 :             : 
   10413                 :           0 :                     n->objectType = OBJECT_VIEW;
   10414                 :           0 :                     n->relation = $3;
   10415                 :           0 :                     n->newschema = $6;
   10416                 :           0 :                     n->missing_ok = false;
   10417                 :           0 :                     $$ = (Node *) n;
   10418                 :             :                 }
   10419                 :             :             | ALTER VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10420                 :             :                 {
   10421                 :           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10422                 :             : 
   10423                 :           0 :                     n->objectType = OBJECT_VIEW;
   10424                 :           0 :                     n->relation = $5;
   10425                 :           0 :                     n->newschema = $8;
   10426                 :           0 :                     n->missing_ok = true;
   10427                 :           0 :                     $$ = (Node *) n;
   10428                 :             :                 }
   10429                 :             :             | ALTER MATERIALIZED VIEW qualified_name SET SCHEMA name
   10430                 :             :                 {
   10431                 :           4 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10432                 :             : 
   10433                 :           4 :                     n->objectType = OBJECT_MATVIEW;
   10434                 :           4 :                     n->relation = $4;
   10435                 :           4 :                     n->newschema = $7;
   10436                 :           4 :                     n->missing_ok = false;
   10437                 :           4 :                     $$ = (Node *) n;
   10438                 :             :                 }
   10439                 :             :             | ALTER MATERIALIZED VIEW IF_P EXISTS qualified_name SET SCHEMA name
   10440                 :             :                 {
   10441                 :           0 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10442                 :             : 
   10443                 :           0 :                     n->objectType = OBJECT_MATVIEW;
   10444                 :           0 :                     n->relation = $6;
   10445                 :           0 :                     n->newschema = $9;
   10446                 :           0 :                     n->missing_ok = true;
   10447                 :           0 :                     $$ = (Node *) n;
   10448                 :             :                 }
   10449                 :             :             | ALTER FOREIGN TABLE relation_expr SET SCHEMA name
   10450                 :             :                 {
   10451                 :           4 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10452                 :             : 
   10453                 :           4 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10454                 :           4 :                     n->relation = $4;
   10455                 :           4 :                     n->newschema = $7;
   10456                 :           4 :                     n->missing_ok = false;
   10457                 :           4 :                     $$ = (Node *) n;
   10458                 :             :                 }
   10459                 :             :             | ALTER FOREIGN TABLE IF_P EXISTS relation_expr SET SCHEMA name
   10460                 :             :                 {
   10461                 :           4 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10462                 :             : 
   10463                 :           4 :                     n->objectType = OBJECT_FOREIGN_TABLE;
   10464                 :           4 :                     n->relation = $6;
   10465                 :           4 :                     n->newschema = $9;
   10466                 :           4 :                     n->missing_ok = true;
   10467                 :           4 :                     $$ = (Node *) n;
   10468                 :             :                 }
   10469                 :             :             | ALTER TYPE_P any_name SET SCHEMA name
   10470                 :             :                 {
   10471                 :           8 :                     AlterObjectSchemaStmt *n = makeNode(AlterObjectSchemaStmt);
   10472                 :             : 
   10473                 :           8 :                     n->objectType = OBJECT_TYPE;
   10474                 :           8 :                     n->object = (Node *) $3;
   10475                 :           8 :                     n->newschema = $6;
   10476                 :           8 :                     n->missing_ok = false;
   10477                 :           8 :                     $$ = (Node *) n;
   10478                 :             :                 }
   10479                 :             :         ;
   10480                 :             : 
   10481                 :             : /*****************************************************************************
   10482                 :             :  *
   10483                 :             :  * ALTER OPERATOR name SET define
   10484                 :             :  *
   10485                 :             :  *****************************************************************************/
   10486                 :             : 
   10487                 :             : AlterOperatorStmt:
   10488                 :             :             ALTER OPERATOR operator_with_argtypes SET '(' operator_def_list ')'
   10489                 :             :                 {
   10490                 :         332 :                     AlterOperatorStmt *n = makeNode(AlterOperatorStmt);
   10491                 :             : 
   10492                 :         332 :                     n->opername = $3;
   10493                 :         332 :                     n->options = $6;
   10494                 :         332 :                     $$ = (Node *) n;
   10495                 :             :                 }
   10496                 :             :         ;
   10497                 :             : 
   10498                 :         368 : operator_def_list:  operator_def_elem                               { $$ = list_make1($1); }
   10499                 :         261 :             | operator_def_list ',' operator_def_elem               { $$ = lappend($1, $3); }
   10500                 :             :         ;
   10501                 :             : 
   10502                 :             : operator_def_elem: ColLabel '=' NONE
   10503                 :          20 :                         { $$ = makeDefElem($1, NULL, @1); }
   10504                 :             :                    | ColLabel '=' operator_def_arg
   10505                 :         587 :                         { $$ = makeDefElem($1, (Node *) $3, @1); }
   10506                 :             :                    | ColLabel
   10507                 :          22 :                         { $$ = makeDefElem($1, NULL, @1); }
   10508                 :             :         ;
   10509                 :             : 
   10510                 :             : /* must be similar enough to def_arg to avoid reduce/reduce conflicts */
   10511                 :             : operator_def_arg:
   10512                 :         535 :             func_type                       { $$ = (Node *) $1; }
   10513                 :          16 :             | reserved_keyword              { $$ = (Node *) makeString(pstrdup($1)); }
   10514                 :          36 :             | qual_all_Op                   { $$ = (Node *) $1; }
   10515                 :           0 :             | NumericOnly                   { $$ = (Node *) $1; }
   10516                 :           0 :             | Sconst                        { $$ = (Node *) makeString($1); }
   10517                 :             :         ;
   10518                 :             : 
   10519                 :             : /*****************************************************************************
   10520                 :             :  *
   10521                 :             :  * ALTER TYPE name SET define
   10522                 :             :  *
   10523                 :             :  * We repurpose ALTER OPERATOR's version of "definition" here
   10524                 :             :  *
   10525                 :             :  *****************************************************************************/
   10526                 :             : 
   10527                 :             : AlterTypeStmt:
   10528                 :             :             ALTER TYPE_P any_name SET '(' operator_def_list ')'
   10529                 :             :                 {
   10530                 :          36 :                     AlterTypeStmt *n = makeNode(AlterTypeStmt);
   10531                 :             : 
   10532                 :          36 :                     n->typeName = $3;
   10533                 :          36 :                     n->options = $6;
   10534                 :          36 :                     $$ = (Node *) n;
   10535                 :             :                 }
   10536                 :             :         ;
   10537                 :             : 
   10538                 :             : /*****************************************************************************
   10539                 :             :  *
   10540                 :             :  * ALTER THING name OWNER TO newname
   10541                 :             :  *
   10542                 :             :  *****************************************************************************/
   10543                 :             : 
   10544                 :             : AlterOwnerStmt: ALTER AGGREGATE aggregate_with_argtypes OWNER TO RoleSpec
   10545                 :             :                 {
   10546                 :          76 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10547                 :             : 
   10548                 :          76 :                     n->objectType = OBJECT_AGGREGATE;
   10549                 :          76 :                     n->object = (Node *) $3;
   10550                 :          76 :                     n->newowner = $6;
   10551                 :          76 :                     $$ = (Node *) n;
   10552                 :             :                 }
   10553                 :             :             | ALTER COLLATION any_name OWNER TO RoleSpec
   10554                 :             :                 {
   10555                 :          11 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10556                 :             : 
   10557                 :          11 :                     n->objectType = OBJECT_COLLATION;
   10558                 :          11 :                     n->object = (Node *) $3;
   10559                 :          11 :                     n->newowner = $6;
   10560                 :          11 :                     $$ = (Node *) n;
   10561                 :             :                 }
   10562                 :             :             | ALTER CONVERSION_P any_name OWNER TO RoleSpec
   10563                 :             :                 {
   10564                 :          16 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10565                 :             : 
   10566                 :          16 :                     n->objectType = OBJECT_CONVERSION;
   10567                 :          16 :                     n->object = (Node *) $3;
   10568                 :          16 :                     n->newowner = $6;
   10569                 :          16 :                     $$ = (Node *) n;
   10570                 :             :                 }
   10571                 :             :             | ALTER DATABASE name OWNER TO RoleSpec
   10572                 :             :                 {
   10573                 :          50 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10574                 :             : 
   10575                 :          50 :                     n->objectType = OBJECT_DATABASE;
   10576                 :          50 :                     n->object = (Node *) makeString($3);
   10577                 :          50 :                     n->newowner = $6;
   10578                 :          50 :                     $$ = (Node *) n;
   10579                 :             :                 }
   10580                 :             :             | ALTER DOMAIN_P any_name OWNER TO RoleSpec
   10581                 :             :                 {
   10582                 :          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10583                 :             : 
   10584                 :          26 :                     n->objectType = OBJECT_DOMAIN;
   10585                 :          26 :                     n->object = (Node *) $3;
   10586                 :          26 :                     n->newowner = $6;
   10587                 :          26 :                     $$ = (Node *) n;
   10588                 :             :                 }
   10589                 :             :             | ALTER FUNCTION function_with_argtypes OWNER TO RoleSpec
   10590                 :             :                 {
   10591                 :         314 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10592                 :             : 
   10593                 :         314 :                     n->objectType = OBJECT_FUNCTION;
   10594                 :         314 :                     n->object = (Node *) $3;
   10595                 :         314 :                     n->newowner = $6;
   10596                 :         314 :                     $$ = (Node *) n;
   10597                 :             :                 }
   10598                 :             :             | ALTER opt_procedural LANGUAGE name OWNER TO RoleSpec
   10599                 :             :                 {
   10600                 :          85 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10601                 :             : 
   10602                 :          85 :                     n->objectType = OBJECT_LANGUAGE;
   10603                 :          85 :                     n->object = (Node *) makeString($4);
   10604                 :          85 :                     n->newowner = $7;
   10605                 :          85 :                     $$ = (Node *) n;
   10606                 :             :                 }
   10607                 :             :             | ALTER LARGE_P OBJECT_P NumericOnly OWNER TO RoleSpec
   10608                 :             :                 {
   10609                 :           9 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10610                 :             : 
   10611                 :           9 :                     n->objectType = OBJECT_LARGEOBJECT;
   10612                 :           9 :                     n->object = (Node *) $4;
   10613                 :           9 :                     n->newowner = $7;
   10614                 :           9 :                     $$ = (Node *) n;
   10615                 :             :                 }
   10616                 :             :             | ALTER OPERATOR operator_with_argtypes OWNER TO RoleSpec
   10617                 :             :                 {
   10618                 :          27 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10619                 :             : 
   10620                 :          27 :                     n->objectType = OBJECT_OPERATOR;
   10621                 :          27 :                     n->object = (Node *) $3;
   10622                 :          27 :                     n->newowner = $6;
   10623                 :          27 :                     $$ = (Node *) n;
   10624                 :             :                 }
   10625                 :             :             | ALTER OPERATOR CLASS any_name USING name OWNER TO RoleSpec
   10626                 :             :                 {
   10627                 :          35 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10628                 :             : 
   10629                 :          35 :                     n->objectType = OBJECT_OPCLASS;
   10630                 :          35 :                     n->object = (Node *) lcons(makeString($6), $4);
   10631                 :          35 :                     n->newowner = $9;
   10632                 :          35 :                     $$ = (Node *) n;
   10633                 :             :                 }
   10634                 :             :             | ALTER OPERATOR FAMILY any_name USING name OWNER TO RoleSpec
   10635                 :             :                 {
   10636                 :          39 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10637                 :             : 
   10638                 :          39 :                     n->objectType = OBJECT_OPFAMILY;
   10639                 :          39 :                     n->object = (Node *) lcons(makeString($6), $4);
   10640                 :          39 :                     n->newowner = $9;
   10641                 :          39 :                     $$ = (Node *) n;
   10642                 :             :                 }
   10643                 :             :             | ALTER PROCEDURE function_with_argtypes OWNER TO RoleSpec
   10644                 :             :                 {
   10645                 :          12 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10646                 :             : 
   10647                 :          12 :                     n->objectType = OBJECT_PROCEDURE;
   10648                 :          12 :                     n->object = (Node *) $3;
   10649                 :          12 :                     n->newowner = $6;
   10650                 :          12 :                     $$ = (Node *) n;
   10651                 :             :                 }
   10652                 :             :             | ALTER ROUTINE function_with_argtypes OWNER TO RoleSpec
   10653                 :             :                 {
   10654                 :           0 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10655                 :             : 
   10656                 :           0 :                     n->objectType = OBJECT_ROUTINE;
   10657                 :           0 :                     n->object = (Node *) $3;
   10658                 :           0 :                     n->newowner = $6;
   10659                 :           0 :                     $$ = (Node *) n;
   10660                 :             :                 }
   10661                 :             :             | ALTER SCHEMA name OWNER TO RoleSpec
   10662                 :             :                 {
   10663                 :          37 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10664                 :             : 
   10665                 :          37 :                     n->objectType = OBJECT_SCHEMA;
   10666                 :          37 :                     n->object = (Node *) makeString($3);
   10667                 :          37 :                     n->newowner = $6;
   10668                 :          37 :                     $$ = (Node *) n;
   10669                 :             :                 }
   10670                 :             :             | ALTER TYPE_P any_name OWNER TO RoleSpec
   10671                 :             :                 {
   10672                 :          45 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10673                 :             : 
   10674                 :          45 :                     n->objectType = OBJECT_TYPE;
   10675                 :          45 :                     n->object = (Node *) $3;
   10676                 :          45 :                     n->newowner = $6;
   10677                 :          45 :                     $$ = (Node *) n;
   10678                 :             :                 }
   10679                 :             :             | ALTER TABLESPACE name OWNER TO RoleSpec
   10680                 :             :                 {
   10681                 :           3 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10682                 :             : 
   10683                 :           3 :                     n->objectType = OBJECT_TABLESPACE;
   10684                 :           3 :                     n->object = (Node *) makeString($3);
   10685                 :           3 :                     n->newowner = $6;
   10686                 :           3 :                     $$ = (Node *) n;
   10687                 :             :                 }
   10688                 :             :             | ALTER STATISTICS any_name OWNER TO RoleSpec
   10689                 :             :                 {
   10690                 :          24 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10691                 :             : 
   10692                 :          24 :                     n->objectType = OBJECT_STATISTIC_EXT;
   10693                 :          24 :                     n->object = (Node *) $3;
   10694                 :          24 :                     n->newowner = $6;
   10695                 :          24 :                     $$ = (Node *) n;
   10696                 :             :                 }
   10697                 :             :             | ALTER TEXT_P SEARCH DICTIONARY any_name OWNER TO RoleSpec
   10698                 :             :                 {
   10699                 :          25 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10700                 :             : 
   10701                 :          25 :                     n->objectType = OBJECT_TSDICTIONARY;
   10702                 :          25 :                     n->object = (Node *) $5;
   10703                 :          25 :                     n->newowner = $8;
   10704                 :          25 :                     $$ = (Node *) n;
   10705                 :             :                 }
   10706                 :             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name OWNER TO RoleSpec
   10707                 :             :                 {
   10708                 :          20 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10709                 :             : 
   10710                 :          20 :                     n->objectType = OBJECT_TSCONFIGURATION;
   10711                 :          20 :                     n->object = (Node *) $5;
   10712                 :          20 :                     n->newowner = $8;
   10713                 :          20 :                     $$ = (Node *) n;
   10714                 :             :                 }
   10715                 :             :             | ALTER FOREIGN DATA_P WRAPPER name OWNER TO RoleSpec
   10716                 :             :                 {
   10717                 :          13 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10718                 :             : 
   10719                 :          13 :                     n->objectType = OBJECT_FDW;
   10720                 :          13 :                     n->object = (Node *) makeString($5);
   10721                 :          13 :                     n->newowner = $8;
   10722                 :          13 :                     $$ = (Node *) n;
   10723                 :             :                 }
   10724                 :             :             | ALTER SERVER name OWNER TO RoleSpec
   10725                 :             :                 {
   10726                 :          45 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10727                 :             : 
   10728                 :          45 :                     n->objectType = OBJECT_FOREIGN_SERVER;
   10729                 :          45 :                     n->object = (Node *) makeString($3);
   10730                 :          45 :                     n->newowner = $6;
   10731                 :          45 :                     $$ = (Node *) n;
   10732                 :             :                 }
   10733                 :             :             | ALTER EVENT TRIGGER name OWNER TO RoleSpec
   10734                 :             :                 {
   10735                 :           9 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10736                 :             : 
   10737                 :           9 :                     n->objectType = OBJECT_EVENT_TRIGGER;
   10738                 :           9 :                     n->object = (Node *) makeString($4);
   10739                 :           9 :                     n->newowner = $7;
   10740                 :           9 :                     $$ = (Node *) n;
   10741                 :             :                 }
   10742                 :             :             | ALTER PUBLICATION name OWNER TO RoleSpec
   10743                 :             :                 {
   10744                 :          26 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10745                 :             : 
   10746                 :          26 :                     n->objectType = OBJECT_PUBLICATION;
   10747                 :          26 :                     n->object = (Node *) makeString($3);
   10748                 :          26 :                     n->newowner = $6;
   10749                 :          26 :                     $$ = (Node *) n;
   10750                 :             :                 }
   10751                 :             :             | ALTER SUBSCRIPTION name OWNER TO RoleSpec
   10752                 :             :                 {
   10753                 :          27 :                     AlterOwnerStmt *n = makeNode(AlterOwnerStmt);
   10754                 :             : 
   10755                 :          27 :                     n->objectType = OBJECT_SUBSCRIPTION;
   10756                 :          27 :                     n->object = (Node *) makeString($3);
   10757                 :          27 :                     n->newowner = $6;
   10758                 :          27 :                     $$ = (Node *) n;
   10759                 :             :                 }
   10760                 :             :         ;
   10761                 :             : 
   10762                 :             : 
   10763                 :             : /*****************************************************************************
   10764                 :             :  *
   10765                 :             :  * CREATE PUBLICATION name [WITH options]
   10766                 :             :  *
   10767                 :             :  * CREATE PUBLICATION FOR ALL pub_all_obj_type [, ...] [WITH options]
   10768                 :             :  *
   10769                 :             :  * pub_all_obj_type is one of:
   10770                 :             :  *
   10771                 :             :  *      TABLES [EXCEPT (TABLE table [, ...] )]
   10772                 :             :  *      SEQUENCES
   10773                 :             :  *
   10774                 :             :  * CREATE PUBLICATION FOR pub_obj [, ...] [WITH options]
   10775                 :             :  *
   10776                 :             :  * pub_obj is one of:
   10777                 :             :  *
   10778                 :             :  *      TABLE table [, ...]
   10779                 :             :  *      TABLES IN SCHEMA schema [, ...]
   10780                 :             :  *
   10781                 :             :  *****************************************************************************/
   10782                 :             : 
   10783                 :             : CreatePublicationStmt:
   10784                 :             :             CREATE PUBLICATION name opt_definition
   10785                 :             :                 {
   10786                 :          94 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10787                 :             : 
   10788                 :          94 :                     n->pubname = $3;
   10789                 :          94 :                     n->options = $4;
   10790                 :          94 :                     $$ = (Node *) n;
   10791                 :             :                 }
   10792                 :             :             | CREATE PUBLICATION name FOR pub_all_obj_type_list opt_definition
   10793                 :             :                 {
   10794                 :         150 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10795                 :             : 
   10796                 :         150 :                     n->pubname = $3;
   10797                 :         150 :                     preprocess_pub_all_objtype_list($5, &n->pubobjects,
   10798                 :             :                                                     &n->for_all_tables,
   10799                 :             :                                                     &n->for_all_sequences,
   10800                 :             :                                                     yyscanner);
   10801                 :         142 :                     n->options = $6;
   10802                 :         142 :                     $$ = (Node *) n;
   10803                 :             :                 }
   10804                 :             :             | CREATE PUBLICATION name FOR pub_obj_list opt_definition
   10805                 :             :                 {
   10806                 :         444 :                     CreatePublicationStmt *n = makeNode(CreatePublicationStmt);
   10807                 :             : 
   10808                 :         444 :                     n->pubname = $3;
   10809                 :         444 :                     n->options = $6;
   10810                 :         444 :                     n->pubobjects = (List *) $5;
   10811                 :         444 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10812                 :         424 :                     $$ = (Node *) n;
   10813                 :             :                 }
   10814                 :             :         ;
   10815                 :             : 
   10816                 :             : /*
   10817                 :             :  * FOR TABLE and FOR TABLES IN SCHEMA specifications
   10818                 :             :  *
   10819                 :             :  * This rule parses publication objects with and without keyword prefixes.
   10820                 :             :  *
   10821                 :             :  * The actual type of the object without keyword prefix depends on the previous
   10822                 :             :  * one with keyword prefix. It will be preprocessed in preprocess_pubobj_list().
   10823                 :             :  *
   10824                 :             :  * For the object without keyword prefix, we cannot just use relation_expr here,
   10825                 :             :  * because some extended expressions in relation_expr cannot be used as a
   10826                 :             :  * schemaname and we cannot differentiate it. So, we extract the rules from
   10827                 :             :  * relation_expr here.
   10828                 :             :  */
   10829                 :             : PublicationObjSpec:
   10830                 :             :             TABLE relation_expr opt_column_list OptWhereClause
   10831                 :             :                 {
   10832                 :         873 :                     $$ = makeNode(PublicationObjSpec);
   10833                 :         873 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLE;
   10834                 :         873 :                     $$->pubtable = makeNode(PublicationTable);
   10835                 :         873 :                     $$->pubtable->relation = $2;
   10836                 :         873 :                     $$->pubtable->columns = $3;
   10837                 :         873 :                     $$->pubtable->whereClause = $4;
   10838                 :             :                 }
   10839                 :             :             | TABLES IN_P SCHEMA ColId
   10840                 :             :                 {
   10841                 :         249 :                     $$ = makeNode(PublicationObjSpec);
   10842                 :         249 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   10843                 :         249 :                     $$->name = $4;
   10844                 :         249 :                     $$->location = @4;
   10845                 :             :                 }
   10846                 :             :             | TABLES IN_P SCHEMA CURRENT_SCHEMA
   10847                 :             :                 {
   10848                 :          12 :                     $$ = makeNode(PublicationObjSpec);
   10849                 :          12 :                     $$->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   10850                 :          12 :                     $$->location = @4;
   10851                 :             :                 }
   10852                 :             :             | ColId opt_column_list OptWhereClause
   10853                 :             :                 {
   10854                 :          83 :                     $$ = makeNode(PublicationObjSpec);
   10855                 :          83 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10856                 :             :                     /*
   10857                 :             :                      * If either a row filter or column list is specified, create
   10858                 :             :                      * a PublicationTable object.
   10859                 :             :                      */
   10860   [ +  +  +  + ]:          83 :                     if ($2 || $3)
   10861                 :             :                     {
   10862                 :             :                         /*
   10863                 :             :                          * The OptWhereClause must be stored here but it is
   10864                 :             :                          * valid only for tables. For non-table objects, an
   10865                 :             :                          * error will be thrown later via
   10866                 :             :                          * preprocess_pubobj_list().
   10867                 :             :                          */
   10868                 :          26 :                         $$->pubtable = makeNode(PublicationTable);
   10869                 :          26 :                         $$->pubtable->relation = makeRangeVar(NULL, $1, @1);
   10870                 :          26 :                         $$->pubtable->columns = $2;
   10871                 :          26 :                         $$->pubtable->whereClause = $3;
   10872                 :             :                     }
   10873                 :             :                     else
   10874                 :             :                     {
   10875                 :          57 :                         $$->name = $1;
   10876                 :             :                     }
   10877                 :          83 :                     $$->location = @1;
   10878                 :             :                 }
   10879                 :             :             | ColId indirection opt_column_list OptWhereClause
   10880                 :             :                 {
   10881                 :          21 :                     $$ = makeNode(PublicationObjSpec);
   10882                 :          21 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10883                 :          21 :                     $$->pubtable = makeNode(PublicationTable);
   10884                 :          21 :                     $$->pubtable->relation = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   10885                 :          21 :                     $$->pubtable->columns = $3;
   10886                 :          21 :                     $$->pubtable->whereClause = $4;
   10887                 :          21 :                     $$->location = @1;
   10888                 :             :                 }
   10889                 :             :             /* grammar like tablename * , ONLY tablename, ONLY ( tablename ) */
   10890                 :             :             | extended_relation_expr opt_column_list OptWhereClause
   10891                 :             :                 {
   10892                 :           4 :                     $$ = makeNode(PublicationObjSpec);
   10893                 :           4 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10894                 :           4 :                     $$->pubtable = makeNode(PublicationTable);
   10895                 :           4 :                     $$->pubtable->relation = $1;
   10896                 :           4 :                     $$->pubtable->columns = $2;
   10897                 :           4 :                     $$->pubtable->whereClause = $3;
   10898                 :             :                 }
   10899                 :             :             | CURRENT_SCHEMA
   10900                 :             :                 {
   10901                 :          12 :                     $$ = makeNode(PublicationObjSpec);
   10902                 :          12 :                     $$->pubobjtype = PUBLICATIONOBJ_CONTINUATION;
   10903                 :          12 :                     $$->location = @1;
   10904                 :             :                 }
   10905                 :             :                 ;
   10906                 :             : 
   10907                 :             : pub_obj_list:   PublicationObjSpec
   10908                 :        1089 :                     { $$ = list_make1($1); }
   10909                 :             :             | pub_obj_list ',' PublicationObjSpec
   10910                 :         165 :                     { $$ = lappend($1, $3); }
   10911                 :             :     ;
   10912                 :             : 
   10913                 :             : opt_pub_except_clause:
   10914                 :          77 :             EXCEPT '(' TABLE pub_except_obj_list ')'    { $$ = $4; }
   10915                 :         109 :             | /*EMPTY*/                                 { $$ = NIL; }
   10916                 :             :         ;
   10917                 :             : 
   10918                 :             : PublicationAllObjSpec:
   10919                 :             :                 ALL TABLES opt_pub_except_clause
   10920                 :             :                     {
   10921                 :         186 :                         $$ = makeNode(PublicationAllObjSpec);
   10922                 :         186 :                         $$->pubobjtype = PUBLICATION_ALL_TABLES;
   10923                 :         186 :                         $$->except_tables = $3;
   10924                 :         186 :                         $$->location = @1;
   10925                 :             :                     }
   10926                 :             :                 | ALL SEQUENCES
   10927                 :             :                     {
   10928                 :          50 :                         $$ = makeNode(PublicationAllObjSpec);
   10929                 :          50 :                         $$->pubobjtype = PUBLICATION_ALL_SEQUENCES;
   10930                 :          50 :                         $$->location = @1;
   10931                 :             :                     }
   10932                 :             :                     ;
   10933                 :             : 
   10934                 :             : pub_all_obj_type_list:  PublicationAllObjSpec
   10935                 :         211 :                     { $$ = list_make1($1); }
   10936                 :             :                 | pub_all_obj_type_list ',' PublicationAllObjSpec
   10937                 :          25 :                     { $$ = lappend($1, $3); }
   10938                 :             :     ;
   10939                 :             : 
   10940                 :             : PublicationExceptObjSpec:
   10941                 :             :              relation_expr
   10942                 :             :                 {
   10943                 :         104 :                     $$ = makeNode(PublicationObjSpec);
   10944                 :         104 :                     $$->pubobjtype = PUBLICATIONOBJ_EXCEPT_TABLE;
   10945                 :         104 :                     $$->pubtable = makeNode(PublicationTable);
   10946                 :         104 :                     $$->pubtable->except = true;
   10947                 :         104 :                     $$->pubtable->relation = $1;
   10948                 :         104 :                     $$->location = @1;
   10949                 :             :                 }
   10950                 :             :     ;
   10951                 :             : 
   10952                 :             : pub_except_obj_list: PublicationExceptObjSpec
   10953                 :          77 :                     { $$ = list_make1($1); }
   10954                 :             :             | pub_except_obj_list ',' opt_table PublicationExceptObjSpec
   10955                 :          27 :                     { $$ = lappend($1, $4); }
   10956                 :             :     ;
   10957                 :             : 
   10958                 :             : /*****************************************************************************
   10959                 :             :  *
   10960                 :             :  * ALTER PUBLICATION name SET ( options )
   10961                 :             :  *
   10962                 :             :  * ALTER PUBLICATION name ADD pub_obj [, ...]
   10963                 :             :  *
   10964                 :             :  * ALTER PUBLICATION name DROP pub_obj [, ...]
   10965                 :             :  *
   10966                 :             :  * ALTER PUBLICATION name SET pub_obj [, ...]
   10967                 :             :  *
   10968                 :             :  * ALTER PUBLICATION name SET pub_all_obj_type [, ...]
   10969                 :             :  *
   10970                 :             :  * pub_obj is one of:
   10971                 :             :  *
   10972                 :             :  *      TABLE table_name [, ...]
   10973                 :             :  *      TABLES IN SCHEMA schema_name [, ...]
   10974                 :             :  *
   10975                 :             :  * pub_all_obj_type is one of:
   10976                 :             :  *
   10977                 :             :  *      ALL TABLES [ EXCEPT ( TABLE table_name [, ...] ) ]
   10978                 :             :  *      ALL SEQUENCES
   10979                 :             :  *
   10980                 :             :  *****************************************************************************/
   10981                 :             : 
   10982                 :             : AlterPublicationStmt:
   10983                 :             :             ALTER PUBLICATION name SET definition
   10984                 :             :                 {
   10985                 :          84 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10986                 :             : 
   10987                 :          84 :                     n->pubname = $3;
   10988                 :          84 :                     n->options = $5;
   10989                 :          84 :                     n->for_all_tables = false;
   10990                 :          84 :                     $$ = (Node *) n;
   10991                 :             :                 }
   10992                 :             :             | ALTER PUBLICATION name ADD_P pub_obj_list
   10993                 :             :                 {
   10994                 :         233 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   10995                 :             : 
   10996                 :         233 :                     n->pubname = $3;
   10997                 :         233 :                     n->pubobjects = $5;
   10998                 :         233 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   10999                 :         229 :                     n->action = AP_AddObjects;
   11000                 :         229 :                     n->for_all_tables = false;
   11001                 :         229 :                     $$ = (Node *) n;
   11002                 :             :                 }
   11003                 :             :             | ALTER PUBLICATION name SET pub_obj_list
   11004                 :             :                 {
   11005                 :         308 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   11006                 :             : 
   11007                 :         308 :                     n->pubname = $3;
   11008                 :         308 :                     n->pubobjects = $5;
   11009                 :         308 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   11010                 :         308 :                     n->action = AP_SetObjects;
   11011                 :         308 :                     n->for_all_tables = false;
   11012                 :         308 :                     $$ = (Node *) n;
   11013                 :             :                 }
   11014                 :             :             | ALTER PUBLICATION name SET pub_all_obj_type_list
   11015                 :             :                 {
   11016                 :          61 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   11017                 :             : 
   11018                 :          61 :                     n->pubname = $3;
   11019                 :          61 :                     n->action = AP_SetObjects;
   11020                 :          61 :                     preprocess_pub_all_objtype_list($5, &n->pubobjects,
   11021                 :             :                                                     &n->for_all_tables,
   11022                 :             :                                                     &n->for_all_sequences,
   11023                 :             :                                                     yyscanner);
   11024                 :          61 :                     $$ = (Node *) n;
   11025                 :             :                 }
   11026                 :             :             | ALTER PUBLICATION name DROP pub_obj_list
   11027                 :             :                 {
   11028                 :         104 :                     AlterPublicationStmt *n = makeNode(AlterPublicationStmt);
   11029                 :             : 
   11030                 :         104 :                     n->pubname = $3;
   11031                 :         104 :                     n->pubobjects = $5;
   11032                 :         104 :                     preprocess_pubobj_list(n->pubobjects, yyscanner);
   11033                 :         104 :                     n->action = AP_DropObjects;
   11034                 :         104 :                     n->for_all_tables = false;
   11035                 :         104 :                     $$ = (Node *) n;
   11036                 :             :                 }
   11037                 :             :         ;
   11038                 :             : 
   11039                 :             : /*****************************************************************************
   11040                 :             :  *
   11041                 :             :  * CREATE SUBSCRIPTION name ...
   11042                 :             :  *
   11043                 :             :  *****************************************************************************/
   11044                 :             : 
   11045                 :             : CreateSubscriptionStmt:
   11046                 :             :             CREATE SUBSCRIPTION name CONNECTION Sconst PUBLICATION name_list opt_definition
   11047                 :             :                 {
   11048                 :             :                     CreateSubscriptionStmt *n =
   11049                 :         318 :                         makeNode(CreateSubscriptionStmt);
   11050                 :         318 :                     n->subname = $3;
   11051                 :         318 :                     n->conninfo = $5;
   11052                 :         318 :                     n->publication = $7;
   11053                 :         318 :                     n->options = $8;
   11054                 :         318 :                     $$ = (Node *) n;
   11055                 :             :                 }
   11056                 :             :             | CREATE SUBSCRIPTION name SERVER name PUBLICATION name_list opt_definition
   11057                 :             :                 {
   11058                 :             :                     CreateSubscriptionStmt *n =
   11059                 :          20 :                         makeNode(CreateSubscriptionStmt);
   11060                 :          20 :                     n->subname = $3;
   11061                 :          20 :                     n->servername = $5;
   11062                 :          20 :                     n->publication = $7;
   11063                 :          20 :                     n->options = $8;
   11064                 :          20 :                     $$ = (Node *) n;
   11065                 :             :                 }
   11066                 :             :         ;
   11067                 :             : 
   11068                 :             : /*****************************************************************************
   11069                 :             :  *
   11070                 :             :  * ALTER SUBSCRIPTION name ...
   11071                 :             :  *
   11072                 :             :  *****************************************************************************/
   11073                 :             : 
   11074                 :             : AlterSubscriptionStmt:
   11075                 :             :             ALTER SUBSCRIPTION name SET definition
   11076                 :             :                 {
   11077                 :             :                     AlterSubscriptionStmt *n =
   11078                 :         209 :                         makeNode(AlterSubscriptionStmt);
   11079                 :             : 
   11080                 :         209 :                     n->kind = ALTER_SUBSCRIPTION_OPTIONS;
   11081                 :         209 :                     n->subname = $3;
   11082                 :         209 :                     n->options = $5;
   11083                 :         209 :                     $$ = (Node *) n;
   11084                 :             :                 }
   11085                 :             :             | ALTER SUBSCRIPTION name CONNECTION Sconst
   11086                 :             :                 {
   11087                 :             :                     AlterSubscriptionStmt *n =
   11088                 :          26 :                         makeNode(AlterSubscriptionStmt);
   11089                 :             : 
   11090                 :          26 :                     n->kind = ALTER_SUBSCRIPTION_CONNECTION;
   11091                 :          26 :                     n->subname = $3;
   11092                 :          26 :                     n->conninfo = $5;
   11093                 :          26 :                     $$ = (Node *) n;
   11094                 :             :                 }
   11095                 :             :             | ALTER SUBSCRIPTION name SERVER name
   11096                 :             :                 {
   11097                 :             :                     AlterSubscriptionStmt *n =
   11098                 :           1 :                         makeNode(AlterSubscriptionStmt);
   11099                 :             : 
   11100                 :           1 :                     n->kind = ALTER_SUBSCRIPTION_SERVER;
   11101                 :           1 :                     n->subname = $3;
   11102                 :           1 :                     n->servername = $5;
   11103                 :           1 :                     $$ = (Node *) n;
   11104                 :             :                 }
   11105                 :             :             | ALTER SUBSCRIPTION name REFRESH PUBLICATION opt_definition
   11106                 :             :                 {
   11107                 :             :                     AlterSubscriptionStmt *n =
   11108                 :          42 :                         makeNode(AlterSubscriptionStmt);
   11109                 :             : 
   11110                 :          42 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH_PUBLICATION;
   11111                 :          42 :                     n->subname = $3;
   11112                 :          42 :                     n->options = $6;
   11113                 :          42 :                     $$ = (Node *) n;
   11114                 :             :                 }
   11115                 :             :             | ALTER SUBSCRIPTION name REFRESH SEQUENCES
   11116                 :             :                 {
   11117                 :             :                     AlterSubscriptionStmt *n =
   11118                 :           5 :                         makeNode(AlterSubscriptionStmt);
   11119                 :             : 
   11120                 :           5 :                     n->kind = ALTER_SUBSCRIPTION_REFRESH_SEQUENCES;
   11121                 :           5 :                     n->subname = $3;
   11122                 :           5 :                     $$ = (Node *) n;
   11123                 :             :                 }
   11124                 :             :             | ALTER SUBSCRIPTION name ADD_P PUBLICATION name_list opt_definition
   11125                 :             :                 {
   11126                 :             :                     AlterSubscriptionStmt *n =
   11127                 :          18 :                         makeNode(AlterSubscriptionStmt);
   11128                 :             : 
   11129                 :          18 :                     n->kind = ALTER_SUBSCRIPTION_ADD_PUBLICATION;
   11130                 :          18 :                     n->subname = $3;
   11131                 :          18 :                     n->publication = $6;
   11132                 :          18 :                     n->options = $7;
   11133                 :          18 :                     $$ = (Node *) n;
   11134                 :             :                 }
   11135                 :             :             | ALTER SUBSCRIPTION name DROP PUBLICATION name_list opt_definition
   11136                 :             :                 {
   11137                 :             :                     AlterSubscriptionStmt *n =
   11138                 :          17 :                         makeNode(AlterSubscriptionStmt);
   11139                 :             : 
   11140                 :          17 :                     n->kind = ALTER_SUBSCRIPTION_DROP_PUBLICATION;
   11141                 :          17 :                     n->subname = $3;
   11142                 :          17 :                     n->publication = $6;
   11143                 :          17 :                     n->options = $7;
   11144                 :          17 :                     $$ = (Node *) n;
   11145                 :             :                 }
   11146                 :             :             | ALTER SUBSCRIPTION name SET PUBLICATION name_list opt_definition
   11147                 :             :                 {
   11148                 :             :                     AlterSubscriptionStmt *n =
   11149                 :          32 :                         makeNode(AlterSubscriptionStmt);
   11150                 :             : 
   11151                 :          32 :                     n->kind = ALTER_SUBSCRIPTION_SET_PUBLICATION;
   11152                 :          32 :                     n->subname = $3;
   11153                 :          32 :                     n->publication = $6;
   11154                 :          32 :                     n->options = $7;
   11155                 :          32 :                     $$ = (Node *) n;
   11156                 :             :                 }
   11157                 :             :             | ALTER SUBSCRIPTION name ENABLE_P
   11158                 :             :                 {
   11159                 :             :                     AlterSubscriptionStmt *n =
   11160                 :          38 :                         makeNode(AlterSubscriptionStmt);
   11161                 :             : 
   11162                 :          38 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   11163                 :          38 :                     n->subname = $3;
   11164                 :          38 :                     n->options = list_make1(makeDefElem("enabled",
   11165                 :             :                                             (Node *) makeBoolean(true), @1));
   11166                 :          38 :                     $$ = (Node *) n;
   11167                 :             :                 }
   11168                 :             :             | ALTER SUBSCRIPTION name DISABLE_P
   11169                 :             :                 {
   11170                 :             :                     AlterSubscriptionStmt *n =
   11171                 :          49 :                         makeNode(AlterSubscriptionStmt);
   11172                 :             : 
   11173                 :          49 :                     n->kind = ALTER_SUBSCRIPTION_ENABLED;
   11174                 :          49 :                     n->subname = $3;
   11175                 :          49 :                     n->options = list_make1(makeDefElem("enabled",
   11176                 :             :                                             (Node *) makeBoolean(false), @1));
   11177                 :          49 :                     $$ = (Node *) n;
   11178                 :             :                 }
   11179                 :             :             | ALTER SUBSCRIPTION name SKIP definition
   11180                 :             :                 {
   11181                 :             :                     AlterSubscriptionStmt *n =
   11182                 :          15 :                         makeNode(AlterSubscriptionStmt);
   11183                 :             : 
   11184                 :          15 :                     n->kind = ALTER_SUBSCRIPTION_SKIP;
   11185                 :          15 :                     n->subname = $3;
   11186                 :          15 :                     n->options = $5;
   11187                 :          15 :                     $$ = (Node *) n;
   11188                 :             :                 }
   11189                 :             :         ;
   11190                 :             : 
   11191                 :             : /*****************************************************************************
   11192                 :             :  *
   11193                 :             :  * DROP SUBSCRIPTION [ IF EXISTS ] name
   11194                 :             :  *
   11195                 :             :  *****************************************************************************/
   11196                 :             : 
   11197                 :             : DropSubscriptionStmt: DROP SUBSCRIPTION name opt_drop_behavior
   11198                 :             :                 {
   11199                 :         179 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11200                 :             : 
   11201                 :         179 :                     n->subname = $3;
   11202                 :         179 :                     n->missing_ok = false;
   11203                 :         179 :                     n->behavior = $4;
   11204                 :         179 :                     $$ = (Node *) n;
   11205                 :             :                 }
   11206                 :             :                 |  DROP SUBSCRIPTION IF_P EXISTS name opt_drop_behavior
   11207                 :             :                 {
   11208                 :           4 :                     DropSubscriptionStmt *n = makeNode(DropSubscriptionStmt);
   11209                 :             : 
   11210                 :           4 :                     n->subname = $5;
   11211                 :           4 :                     n->missing_ok = true;
   11212                 :           4 :                     n->behavior = $6;
   11213                 :           4 :                     $$ = (Node *) n;
   11214                 :             :                 }
   11215                 :             :         ;
   11216                 :             : 
   11217                 :             : /*****************************************************************************
   11218                 :             :  *
   11219                 :             :  *      QUERY:  Define Rewrite Rule
   11220                 :             :  *
   11221                 :             :  *****************************************************************************/
   11222                 :             : 
   11223                 :             : RuleStmt:   CREATE opt_or_replace RULE name AS
   11224                 :             :             ON event TO qualified_name where_clause
   11225                 :             :             DO opt_instead RuleActionList
   11226                 :             :                 {
   11227                 :         734 :                     RuleStmt   *n = makeNode(RuleStmt);
   11228                 :             : 
   11229                 :         734 :                     n->replace = $2;
   11230                 :         734 :                     n->relation = $9;
   11231                 :         734 :                     n->rulename = $4;
   11232                 :         734 :                     n->whereClause = $10;
   11233                 :         734 :                     n->event = $7;
   11234                 :         734 :                     n->instead = $12;
   11235                 :         734 :                     n->actions = $13;
   11236                 :         734 :                     $$ = (Node *) n;
   11237                 :             :                 }
   11238                 :             :         ;
   11239                 :             : 
   11240                 :             : RuleActionList:
   11241                 :         110 :             NOTHING                                 { $$ = NIL; }
   11242                 :         594 :             | RuleActionStmt                        { $$ = list_make1($1); }
   11243                 :          30 :             | '(' RuleActionMulti ')'               { $$ = $2; }
   11244                 :             :         ;
   11245                 :             : 
   11246                 :             : /* the thrashing around here is to discard "empty" statements... */
   11247                 :             : RuleActionMulti:
   11248                 :             :             RuleActionMulti ';' RuleActionStmtOrEmpty
   11249         [ +  + ]:          40 :                 { if ($3 != NULL)
   11250                 :          30 :                     $$ = lappend($1, $3);
   11251                 :             :                   else
   11252                 :          10 :                     $$ = $1;
   11253                 :             :                 }
   11254                 :             :             | RuleActionStmtOrEmpty
   11255         [ +  - ]:          30 :                 { if ($1 != NULL)
   11256                 :          30 :                     $$ = list_make1($1);
   11257                 :             :                   else
   11258                 :           0 :                     $$ = NIL;
   11259                 :             :                 }
   11260                 :             :         ;
   11261                 :             : 
   11262                 :             : RuleActionStmt:
   11263                 :             :             SelectStmt
   11264                 :             :             | InsertStmt
   11265                 :             :             | UpdateStmt
   11266                 :             :             | DeleteStmt
   11267                 :             :             | NotifyStmt
   11268                 :             :         ;
   11269                 :             : 
   11270                 :             : RuleActionStmtOrEmpty:
   11271                 :          60 :             RuleActionStmt                          { $$ = $1; }
   11272                 :          10 :             |   /*EMPTY*/                           { $$ = NULL; }
   11273                 :             :         ;
   11274                 :             : 
   11275                 :          12 : event:      SELECT                                  { $$ = CMD_SELECT; }
   11276                 :         286 :             | UPDATE                                { $$ = CMD_UPDATE; }
   11277                 :         106 :             | DELETE_P                              { $$ = CMD_DELETE; }
   11278                 :         330 :             | INSERT                                { $$ = CMD_INSERT; }
   11279                 :             :          ;
   11280                 :             : 
   11281                 :             : opt_instead:
   11282                 :         505 :             INSTEAD                                 { $$ = true; }
   11283                 :         119 :             | ALSO                                  { $$ = false; }
   11284                 :         110 :             | /*EMPTY*/                             { $$ = false; }
   11285                 :             :         ;
   11286                 :             : 
   11287                 :             : 
   11288                 :             : /*****************************************************************************
   11289                 :             :  *
   11290                 :             :  *      QUERY:
   11291                 :             :  *              NOTIFY <identifier> can appear both in rule bodies and
   11292                 :             :  *              as a query-level command
   11293                 :             :  *
   11294                 :             :  *****************************************************************************/
   11295                 :             : 
   11296                 :             : NotifyStmt: NOTIFY ColId notify_payload
   11297                 :             :                 {
   11298                 :          88 :                     NotifyStmt *n = makeNode(NotifyStmt);
   11299                 :             : 
   11300                 :          88 :                     n->conditionname = $2;
   11301                 :          88 :                     n->payload = $3;
   11302                 :          88 :                     $$ = (Node *) n;
   11303                 :             :                 }
   11304                 :             :         ;
   11305                 :             : 
   11306                 :             : notify_payload:
   11307                 :          47 :             ',' Sconst                          { $$ = $2; }
   11308                 :          41 :             | /*EMPTY*/                         { $$ = NULL; }
   11309                 :             :         ;
   11310                 :             : 
   11311                 :             : ListenStmt: LISTEN ColId
   11312                 :             :                 {
   11313                 :          52 :                     ListenStmt *n = makeNode(ListenStmt);
   11314                 :             : 
   11315                 :          52 :                     n->conditionname = $2;
   11316                 :          52 :                     $$ = (Node *) n;
   11317                 :             :                 }
   11318                 :             :         ;
   11319                 :             : 
   11320                 :             : UnlistenStmt:
   11321                 :             :             UNLISTEN ColId
   11322                 :             :                 {
   11323                 :           4 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11324                 :             : 
   11325                 :           4 :                     n->conditionname = $2;
   11326                 :           4 :                     $$ = (Node *) n;
   11327                 :             :                 }
   11328                 :             :             | UNLISTEN '*'
   11329                 :             :                 {
   11330                 :          58 :                     UnlistenStmt *n = makeNode(UnlistenStmt);
   11331                 :             : 
   11332                 :          58 :                     n->conditionname = NULL;
   11333                 :          58 :                     $$ = (Node *) n;
   11334                 :             :                 }
   11335                 :             :         ;
   11336                 :             : 
   11337                 :             : 
   11338                 :             : /*****************************************************************************
   11339                 :             :  *
   11340                 :             :  *      Transactions:
   11341                 :             :  *
   11342                 :             :  *      BEGIN / COMMIT / ROLLBACK
   11343                 :             :  *      (also older versions END / ABORT)
   11344                 :             :  *
   11345                 :             :  *****************************************************************************/
   11346                 :             : 
   11347                 :             : TransactionStmt:
   11348                 :             :             ABORT_P opt_transaction opt_transaction_chain
   11349                 :             :                 {
   11350                 :         419 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11351                 :             : 
   11352                 :         419 :                     n->kind = TRANS_STMT_ROLLBACK;
   11353                 :         419 :                     n->options = NIL;
   11354                 :         419 :                     n->chain = $3;
   11355                 :         419 :                     n->location = -1;
   11356                 :         419 :                     $$ = (Node *) n;
   11357                 :             :                 }
   11358                 :             :             | START TRANSACTION transaction_mode_list_or_empty
   11359                 :             :                 {
   11360                 :         902 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11361                 :             : 
   11362                 :         902 :                     n->kind = TRANS_STMT_START;
   11363                 :         902 :                     n->options = $3;
   11364                 :         902 :                     n->location = -1;
   11365                 :         902 :                     $$ = (Node *) n;
   11366                 :             :                 }
   11367                 :             :             | COMMIT opt_transaction opt_transaction_chain
   11368                 :             :                 {
   11369                 :        9393 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11370                 :             : 
   11371                 :        9393 :                     n->kind = TRANS_STMT_COMMIT;
   11372                 :        9393 :                     n->options = NIL;
   11373                 :        9393 :                     n->chain = $3;
   11374                 :        9393 :                     n->location = -1;
   11375                 :        9393 :                     $$ = (Node *) n;
   11376                 :             :                 }
   11377                 :             :             | ROLLBACK opt_transaction opt_transaction_chain
   11378                 :             :                 {
   11379                 :        1857 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11380                 :             : 
   11381                 :        1857 :                     n->kind = TRANS_STMT_ROLLBACK;
   11382                 :        1857 :                     n->options = NIL;
   11383                 :        1857 :                     n->chain = $3;
   11384                 :        1857 :                     n->location = -1;
   11385                 :        1857 :                     $$ = (Node *) n;
   11386                 :             :                 }
   11387                 :             :             | SAVEPOINT ColId
   11388                 :             :                 {
   11389                 :        1181 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11390                 :             : 
   11391                 :        1181 :                     n->kind = TRANS_STMT_SAVEPOINT;
   11392                 :        1181 :                     n->savepoint_name = $2;
   11393                 :        1181 :                     n->location = @2;
   11394                 :        1181 :                     $$ = (Node *) n;
   11395                 :             :                 }
   11396                 :             :             | RELEASE SAVEPOINT ColId
   11397                 :             :                 {
   11398                 :         137 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11399                 :             : 
   11400                 :         137 :                     n->kind = TRANS_STMT_RELEASE;
   11401                 :         137 :                     n->savepoint_name = $3;
   11402                 :         137 :                     n->location = @3;
   11403                 :         137 :                     $$ = (Node *) n;
   11404                 :             :                 }
   11405                 :             :             | RELEASE ColId
   11406                 :             :                 {
   11407                 :          56 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11408                 :             : 
   11409                 :          56 :                     n->kind = TRANS_STMT_RELEASE;
   11410                 :          56 :                     n->savepoint_name = $2;
   11411                 :          56 :                     n->location = @2;
   11412                 :          56 :                     $$ = (Node *) n;
   11413                 :             :                 }
   11414                 :             :             | ROLLBACK opt_transaction TO SAVEPOINT ColId
   11415                 :             :                 {
   11416                 :         163 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11417                 :             : 
   11418                 :         163 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11419                 :         163 :                     n->savepoint_name = $5;
   11420                 :         163 :                     n->location = @5;
   11421                 :         163 :                     $$ = (Node *) n;
   11422                 :             :                 }
   11423                 :             :             | ROLLBACK opt_transaction TO ColId
   11424                 :             :                 {
   11425                 :         329 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11426                 :             : 
   11427                 :         329 :                     n->kind = TRANS_STMT_ROLLBACK_TO;
   11428                 :         329 :                     n->savepoint_name = $4;
   11429                 :         329 :                     n->location = @4;
   11430                 :         329 :                     $$ = (Node *) n;
   11431                 :             :                 }
   11432                 :             :             | PREPARE TRANSACTION Sconst
   11433                 :             :                 {
   11434                 :         358 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11435                 :             : 
   11436                 :         358 :                     n->kind = TRANS_STMT_PREPARE;
   11437                 :         358 :                     n->gid = $3;
   11438                 :         358 :                     n->location = @3;
   11439                 :         358 :                     $$ = (Node *) n;
   11440                 :             :                 }
   11441                 :             :             | COMMIT PREPARED Sconst
   11442                 :             :                 {
   11443                 :         261 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11444                 :             : 
   11445                 :         261 :                     n->kind = TRANS_STMT_COMMIT_PREPARED;
   11446                 :         261 :                     n->gid = $3;
   11447                 :         261 :                     n->location = @3;
   11448                 :         261 :                     $$ = (Node *) n;
   11449                 :             :                 }
   11450                 :             :             | ROLLBACK PREPARED Sconst
   11451                 :             :                 {
   11452                 :          50 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11453                 :             : 
   11454                 :          50 :                     n->kind = TRANS_STMT_ROLLBACK_PREPARED;
   11455                 :          50 :                     n->gid = $3;
   11456                 :          50 :                     n->location = @3;
   11457                 :          50 :                     $$ = (Node *) n;
   11458                 :             :                 }
   11459                 :             :         ;
   11460                 :             : 
   11461                 :             : TransactionStmtLegacy:
   11462                 :             :             BEGIN_P opt_transaction transaction_mode_list_or_empty
   11463                 :             :                 {
   11464                 :       11523 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11465                 :             : 
   11466                 :       11523 :                     n->kind = TRANS_STMT_BEGIN;
   11467                 :       11523 :                     n->options = $3;
   11468                 :       11523 :                     n->location = -1;
   11469                 :       11523 :                     $$ = (Node *) n;
   11470                 :             :                 }
   11471                 :             :             | END_P opt_transaction opt_transaction_chain
   11472                 :             :                 {
   11473                 :         207 :                     TransactionStmt *n = makeNode(TransactionStmt);
   11474                 :             : 
   11475                 :         207 :                     n->kind = TRANS_STMT_COMMIT;
   11476                 :         207 :                     n->options = NIL;
   11477                 :         207 :                     n->chain = $3;
   11478                 :         207 :                     n->location = -1;
   11479                 :         207 :                     $$ = (Node *) n;
   11480                 :             :                 }
   11481                 :             :         ;
   11482                 :             : 
   11483                 :             : opt_transaction:    WORK
   11484                 :             :             | TRANSACTION
   11485                 :             :             | /*EMPTY*/
   11486                 :             :         ;
   11487                 :             : 
   11488                 :             : transaction_mode_item:
   11489                 :             :             ISOLATION LEVEL iso_level
   11490                 :        3662 :                     { $$ = makeDefElem("transaction_isolation",
   11491                 :        3662 :                                        makeStringConst($3, @3), @1); }
   11492                 :             :             | READ ONLY
   11493                 :         774 :                     { $$ = makeDefElem("transaction_read_only",
   11494                 :         774 :                                        makeIntConst(true, @1), @1); }
   11495                 :             :             | READ WRITE
   11496                 :          59 :                     { $$ = makeDefElem("transaction_read_only",
   11497                 :          59 :                                        makeIntConst(false, @1), @1); }
   11498                 :             :             | DEFERRABLE
   11499                 :          33 :                     { $$ = makeDefElem("transaction_deferrable",
   11500                 :             :                                        makeIntConst(true, @1), @1); }
   11501                 :             :             | NOT DEFERRABLE
   11502                 :           6 :                     { $$ = makeDefElem("transaction_deferrable",
   11503                 :           6 :                                        makeIntConst(false, @1), @1); }
   11504                 :             :         ;
   11505                 :             : 
   11506                 :             : /* Syntax with commas is SQL-spec, without commas is Postgres historical */
   11507                 :             : transaction_mode_list:
   11508                 :             :             transaction_mode_item
   11509                 :        3805 :                     { $$ = list_make1($1); }
   11510                 :             :             | transaction_mode_list ',' transaction_mode_item
   11511                 :         491 :                     { $$ = lappend($1, $3); }
   11512                 :             :             | transaction_mode_list transaction_mode_item
   11513                 :         238 :                     { $$ = lappend($1, $2); }
   11514                 :             :         ;
   11515                 :             : 
   11516                 :             : transaction_mode_list_or_empty:
   11517                 :             :             transaction_mode_list
   11518                 :             :             | /* EMPTY */
   11519                 :        8952 :                     { $$ = NIL; }
   11520                 :             :         ;
   11521                 :             : 
   11522                 :             : opt_transaction_chain:
   11523                 :          80 :             AND CHAIN       { $$ = true; }
   11524                 :           1 :             | AND NO CHAIN  { $$ = false; }
   11525                 :       11795 :             | /* EMPTY */   { $$ = false; }
   11526                 :             :         ;
   11527                 :             : 
   11528                 :             : 
   11529                 :             : /*****************************************************************************
   11530                 :             :  *
   11531                 :             :  *  QUERY:
   11532                 :             :  *      CREATE [ OR REPLACE ] [ TEMP ] VIEW <viewname> '('target-list ')'
   11533                 :             :  *          AS <query> [ WITH [ CASCADED | LOCAL ] CHECK OPTION ]
   11534                 :             :  *
   11535                 :             :  *****************************************************************************/
   11536                 :             : 
   11537                 :             : ViewStmt: CREATE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11538                 :             :                 AS SelectStmt opt_check_option
   11539                 :             :                 {
   11540                 :       10533 :                     ViewStmt   *n = makeNode(ViewStmt);
   11541                 :             : 
   11542                 :       10533 :                     n->view = $4;
   11543                 :       10533 :                     n->view->relpersistence = $2;
   11544                 :       10533 :                     n->aliases = $5;
   11545                 :       10533 :                     n->query = $8;
   11546                 :       10533 :                     n->replace = false;
   11547                 :       10533 :                     n->options = $6;
   11548                 :       10533 :                     n->withCheckOption = $9;
   11549                 :       10533 :                     $$ = (Node *) n;
   11550                 :             :                 }
   11551                 :             :         | CREATE OR REPLACE OptTemp VIEW qualified_name opt_column_list opt_reloptions
   11552                 :             :                 AS SelectStmt opt_check_option
   11553                 :             :                 {
   11554                 :         177 :                     ViewStmt   *n = makeNode(ViewStmt);
   11555                 :             : 
   11556                 :         177 :                     n->view = $6;
   11557                 :         177 :                     n->view->relpersistence = $4;
   11558                 :         177 :                     n->aliases = $7;
   11559                 :         177 :                     n->query = $10;
   11560                 :         177 :                     n->replace = true;
   11561                 :         177 :                     n->options = $8;
   11562                 :         177 :                     n->withCheckOption = $11;
   11563                 :         177 :                     $$ = (Node *) n;
   11564                 :             :                 }
   11565                 :             :         | CREATE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11566                 :             :                 AS SelectStmt opt_check_option
   11567                 :             :                 {
   11568                 :           5 :                     ViewStmt   *n = makeNode(ViewStmt);
   11569                 :             : 
   11570                 :           5 :                     n->view = $5;
   11571                 :           5 :                     n->view->relpersistence = $2;
   11572                 :           5 :                     n->aliases = $7;
   11573                 :           5 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $11);
   11574                 :           5 :                     n->replace = false;
   11575                 :           5 :                     n->options = $9;
   11576                 :           5 :                     n->withCheckOption = $12;
   11577         [ -  + ]:           5 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11578         [ #  # ]:           0 :                         ereport(ERROR,
   11579                 :             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11580                 :             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11581                 :             :                                  parser_errposition(@12)));
   11582                 :           5 :                     $$ = (Node *) n;
   11583                 :             :                 }
   11584                 :             :         | CREATE OR REPLACE OptTemp RECURSIVE VIEW qualified_name '(' columnList ')' opt_reloptions
   11585                 :             :                 AS SelectStmt opt_check_option
   11586                 :             :                 {
   11587                 :           4 :                     ViewStmt   *n = makeNode(ViewStmt);
   11588                 :             : 
   11589                 :           4 :                     n->view = $7;
   11590                 :           4 :                     n->view->relpersistence = $4;
   11591                 :           4 :                     n->aliases = $9;
   11592                 :           4 :                     n->query = makeRecursiveViewSelect(n->view->relname, n->aliases, $13);
   11593                 :           4 :                     n->replace = true;
   11594                 :           4 :                     n->options = $11;
   11595                 :           4 :                     n->withCheckOption = $14;
   11596         [ -  + ]:           4 :                     if (n->withCheckOption != NO_CHECK_OPTION)
   11597         [ #  # ]:           0 :                         ereport(ERROR,
   11598                 :             :                                 (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   11599                 :             :                                  errmsg("WITH CHECK OPTION not supported on recursive views"),
   11600                 :             :                                  parser_errposition(@14)));
   11601                 :           4 :                     $$ = (Node *) n;
   11602                 :             :                 }
   11603                 :             :         ;
   11604                 :             : 
   11605                 :             : opt_check_option:
   11606                 :          63 :         WITH CHECK OPTION               { $$ = CASCADED_CHECK_OPTION; }
   11607                 :           4 :         | WITH CASCADED CHECK OPTION    { $$ = CASCADED_CHECK_OPTION; }
   11608                 :          16 :         | WITH LOCAL CHECK OPTION       { $$ = LOCAL_CHECK_OPTION; }
   11609                 :       10636 :         | /* EMPTY */                   { $$ = NO_CHECK_OPTION; }
   11610                 :             :         ;
   11611                 :             : 
   11612                 :             : /*****************************************************************************
   11613                 :             :  *
   11614                 :             :  *      QUERY:
   11615                 :             :  *              LOAD "filename"
   11616                 :             :  *
   11617                 :             :  *****************************************************************************/
   11618                 :             : 
   11619                 :             : LoadStmt:   LOAD file_name
   11620                 :             :                 {
   11621                 :          50 :                     LoadStmt   *n = makeNode(LoadStmt);
   11622                 :             : 
   11623                 :          50 :                     n->filename = $2;
   11624                 :          50 :                     $$ = (Node *) n;
   11625                 :             :                 }
   11626                 :             :         ;
   11627                 :             : 
   11628                 :             : 
   11629                 :             : /*****************************************************************************
   11630                 :             :  *
   11631                 :             :  *      CREATE DATABASE
   11632                 :             :  *
   11633                 :             :  *****************************************************************************/
   11634                 :             : 
   11635                 :             : CreatedbStmt:
   11636                 :             :             CREATE DATABASE name opt_with createdb_opt_list
   11637                 :             :                 {
   11638                 :         457 :                     CreatedbStmt *n = makeNode(CreatedbStmt);
   11639                 :             : 
   11640                 :         457 :                     n->dbname = $3;
   11641                 :         457 :                     n->options = $5;
   11642                 :         457 :                     $$ = (Node *) n;
   11643                 :             :                 }
   11644                 :             :         ;
   11645                 :             : 
   11646                 :             : createdb_opt_list:
   11647                 :         376 :             createdb_opt_items                      { $$ = $1; }
   11648                 :         120 :             | /* EMPTY */                           { $$ = NIL; }
   11649                 :             :         ;
   11650                 :             : 
   11651                 :             : createdb_opt_items:
   11652                 :         376 :             createdb_opt_item                       { $$ = list_make1($1); }
   11653                 :         566 :             | createdb_opt_items createdb_opt_item  { $$ = lappend($1, $2); }
   11654                 :             :         ;
   11655                 :             : 
   11656                 :             : createdb_opt_item:
   11657                 :             :             createdb_opt_name opt_equal NumericOnly
   11658                 :             :                 {
   11659                 :         157 :                     $$ = makeDefElem($1, $3, @1);
   11660                 :             :                 }
   11661                 :             :             | createdb_opt_name opt_equal opt_boolean_or_string
   11662                 :             :                 {
   11663                 :         785 :                     $$ = makeDefElem($1, (Node *) makeString($3), @1);
   11664                 :             :                 }
   11665                 :             :             | createdb_opt_name opt_equal DEFAULT
   11666                 :             :                 {
   11667                 :           0 :                     $$ = makeDefElem($1, NULL, @1);
   11668                 :             :                 }
   11669                 :             :         ;
   11670                 :             : 
   11671                 :             : /*
   11672                 :             :  * Ideally we'd use ColId here, but that causes shift/reduce conflicts against
   11673                 :             :  * the ALTER DATABASE SET/RESET syntaxes.  Instead call out specific keywords
   11674                 :             :  * we need, and allow IDENT so that database option names don't have to be
   11675                 :             :  * parser keywords unless they are already keywords for other reasons.
   11676                 :             :  *
   11677                 :             :  * XXX this coding technique is fragile since if someone makes a formerly
   11678                 :             :  * non-keyword option name into a keyword and forgets to add it here, the
   11679                 :             :  * option will silently break.  Best defense is to provide a regression test
   11680                 :             :  * exercising every such option, at least at the syntax level.
   11681                 :             :  */
   11682                 :             : createdb_opt_name:
   11683                 :         663 :             IDENT                           { $$ = $1; }
   11684                 :           2 :             | CONNECTION LIMIT              { $$ = pstrdup("connection_limit"); }
   11685                 :          58 :             | ENCODING                      { $$ = pstrdup($1); }
   11686                 :           0 :             | LOCATION                      { $$ = pstrdup($1); }
   11687                 :           1 :             | OWNER                         { $$ = pstrdup($1); }
   11688                 :          17 :             | TABLESPACE                    { $$ = pstrdup($1); }
   11689                 :         201 :             | TEMPLATE                      { $$ = pstrdup($1); }
   11690                 :             :         ;
   11691                 :             : 
   11692                 :             : /*
   11693                 :             :  *  Though the equals sign doesn't match other WITH options, pg_dump uses
   11694                 :             :  *  equals for backward compatibility, and it doesn't seem worth removing it.
   11695                 :             :  */
   11696                 :             : opt_equal:  '='
   11697                 :             :             | /*EMPTY*/
   11698                 :             :         ;
   11699                 :             : 
   11700                 :             : 
   11701                 :             : /*****************************************************************************
   11702                 :             :  *
   11703                 :             :  *      ALTER DATABASE
   11704                 :             :  *
   11705                 :             :  *****************************************************************************/
   11706                 :             : 
   11707                 :             : AlterDatabaseStmt:
   11708                 :             :             ALTER DATABASE name WITH createdb_opt_list
   11709                 :             :                  {
   11710                 :           1 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11711                 :             : 
   11712                 :           1 :                     n->dbname = $3;
   11713                 :           1 :                     n->options = $5;
   11714                 :           1 :                     $$ = (Node *) n;
   11715                 :             :                  }
   11716                 :             :             | ALTER DATABASE name createdb_opt_list
   11717                 :             :                  {
   11718                 :          38 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11719                 :             : 
   11720                 :          38 :                     n->dbname = $3;
   11721                 :          38 :                     n->options = $4;
   11722                 :          38 :                     $$ = (Node *) n;
   11723                 :             :                  }
   11724                 :             :             | ALTER DATABASE name SET TABLESPACE name
   11725                 :             :                  {
   11726                 :          14 :                     AlterDatabaseStmt *n = makeNode(AlterDatabaseStmt);
   11727                 :             : 
   11728                 :          14 :                     n->dbname = $3;
   11729                 :          14 :                     n->options = list_make1(makeDefElem("tablespace",
   11730                 :             :                                                         (Node *) makeString($6), @6));
   11731                 :          14 :                     $$ = (Node *) n;
   11732                 :             :                  }
   11733                 :             :             | ALTER DATABASE name REFRESH COLLATION VERSION_P
   11734                 :             :                  {
   11735                 :           4 :                     AlterDatabaseRefreshCollStmt *n = makeNode(AlterDatabaseRefreshCollStmt);
   11736                 :             : 
   11737                 :           4 :                     n->dbname = $3;
   11738                 :           4 :                     $$ = (Node *) n;
   11739                 :             :                  }
   11740                 :             :         ;
   11741                 :             : 
   11742                 :             : AlterDatabaseSetStmt:
   11743                 :             :             ALTER DATABASE name SetResetClause
   11744                 :             :                 {
   11745                 :         688 :                     AlterDatabaseSetStmt *n = makeNode(AlterDatabaseSetStmt);
   11746                 :             : 
   11747                 :         688 :                     n->dbname = $3;
   11748                 :         688 :                     n->setstmt = $4;
   11749                 :         688 :                     $$ = (Node *) n;
   11750                 :             :                 }
   11751                 :             :         ;
   11752                 :             : 
   11753                 :             : 
   11754                 :             : /*****************************************************************************
   11755                 :             :  *
   11756                 :             :  *      DROP DATABASE [ IF EXISTS ] dbname [ [ WITH ] ( options ) ]
   11757                 :             :  *
   11758                 :             :  * This is implicitly CASCADE, no need for drop behavior
   11759                 :             :  *****************************************************************************/
   11760                 :             : 
   11761                 :             : DropdbStmt: DROP DATABASE name
   11762                 :             :                 {
   11763                 :          58 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11764                 :             : 
   11765                 :          58 :                     n->dbname = $3;
   11766                 :          58 :                     n->missing_ok = false;
   11767                 :          58 :                     n->options = NULL;
   11768                 :          58 :                     $$ = (Node *) n;
   11769                 :             :                 }
   11770                 :             :             | DROP DATABASE IF_P EXISTS name
   11771                 :             :                 {
   11772                 :           3 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11773                 :             : 
   11774                 :           3 :                     n->dbname = $5;
   11775                 :           3 :                     n->missing_ok = true;
   11776                 :           3 :                     n->options = NULL;
   11777                 :           3 :                     $$ = (Node *) n;
   11778                 :             :                 }
   11779                 :             :             | DROP DATABASE name opt_with '(' drop_option_list ')'
   11780                 :             :                 {
   11781                 :          10 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11782                 :             : 
   11783                 :          10 :                     n->dbname = $3;
   11784                 :          10 :                     n->missing_ok = false;
   11785                 :          10 :                     n->options = $6;
   11786                 :          10 :                     $$ = (Node *) n;
   11787                 :             :                 }
   11788                 :             :             | DROP DATABASE IF_P EXISTS name opt_with '(' drop_option_list ')'
   11789                 :             :                 {
   11790                 :           8 :                     DropdbStmt *n = makeNode(DropdbStmt);
   11791                 :             : 
   11792                 :           8 :                     n->dbname = $5;
   11793                 :           8 :                     n->missing_ok = true;
   11794                 :           8 :                     n->options = $8;
   11795                 :           8 :                     $$ = (Node *) n;
   11796                 :             :                 }
   11797                 :             :         ;
   11798                 :             : 
   11799                 :             : drop_option_list:
   11800                 :             :             drop_option
   11801                 :             :                 {
   11802                 :          18 :                     $$ = list_make1((Node *) $1);
   11803                 :             :                 }
   11804                 :             :             | drop_option_list ',' drop_option
   11805                 :             :                 {
   11806                 :           0 :                     $$ = lappend($1, (Node *) $3);
   11807                 :             :                 }
   11808                 :             :         ;
   11809                 :             : 
   11810                 :             : /*
   11811                 :             :  * Currently only the FORCE option is supported, but the syntax is designed
   11812                 :             :  * to be extensible so that we can add more options in the future if required.
   11813                 :             :  */
   11814                 :             : drop_option:
   11815                 :             :             FORCE
   11816                 :             :                 {
   11817                 :          18 :                     $$ = makeDefElem("force", NULL, @1);
   11818                 :             :                 }
   11819                 :             :         ;
   11820                 :             : 
   11821                 :             : /*****************************************************************************
   11822                 :             :  *
   11823                 :             :  *      ALTER COLLATION
   11824                 :             :  *
   11825                 :             :  *****************************************************************************/
   11826                 :             : 
   11827                 :             : AlterCollationStmt: ALTER COLLATION any_name REFRESH VERSION_P
   11828                 :             :                 {
   11829                 :           4 :                     AlterCollationStmt *n = makeNode(AlterCollationStmt);
   11830                 :             : 
   11831                 :           4 :                     n->collname = $3;
   11832                 :           4 :                     $$ = (Node *) n;
   11833                 :             :                 }
   11834                 :             :         ;
   11835                 :             : 
   11836                 :             : 
   11837                 :             : /*****************************************************************************
   11838                 :             :  *
   11839                 :             :  *      ALTER SYSTEM
   11840                 :             :  *
   11841                 :             :  * This is used to change configuration parameters persistently.
   11842                 :             :  *****************************************************************************/
   11843                 :             : 
   11844                 :             : AlterSystemStmt:
   11845                 :             :             ALTER SYSTEM_P SET generic_set
   11846                 :             :                 {
   11847                 :          99 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11848                 :             : 
   11849                 :          99 :                     n->setstmt = $4;
   11850                 :          99 :                     $$ = (Node *) n;
   11851                 :             :                 }
   11852                 :             :             | ALTER SYSTEM_P RESET generic_reset
   11853                 :             :                 {
   11854                 :          29 :                     AlterSystemStmt *n = makeNode(AlterSystemStmt);
   11855                 :             : 
   11856                 :          29 :                     n->setstmt = $4;
   11857                 :          29 :                     $$ = (Node *) n;
   11858                 :             :                 }
   11859                 :             :         ;
   11860                 :             : 
   11861                 :             : 
   11862                 :             : /*****************************************************************************
   11863                 :             :  *
   11864                 :             :  * Manipulate a domain
   11865                 :             :  *
   11866                 :             :  *****************************************************************************/
   11867                 :             : 
   11868                 :             : CreateDomainStmt:
   11869                 :             :             CREATE DOMAIN_P any_name opt_as Typename ColQualList
   11870                 :             :                 {
   11871                 :        1016 :                     CreateDomainStmt *n = makeNode(CreateDomainStmt);
   11872                 :             : 
   11873                 :        1016 :                     n->domainname = $3;
   11874                 :        1016 :                     n->typeName = $5;
   11875                 :        1016 :                     SplitColQualList($6, &n->constraints, &n->collClause,
   11876                 :             :                                      yyscanner);
   11877                 :        1016 :                     $$ = (Node *) n;
   11878                 :             :                 }
   11879                 :             :         ;
   11880                 :             : 
   11881                 :             : AlterDomainStmt:
   11882                 :             :             /* ALTER DOMAIN <domain> {SET DEFAULT <expr>|DROP DEFAULT} */
   11883                 :             :             ALTER DOMAIN_P any_name alter_column_default
   11884                 :             :                 {
   11885                 :           9 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11886                 :             : 
   11887                 :           9 :                     n->subtype = AD_AlterDefault;
   11888                 :           9 :                     n->typeName = $3;
   11889                 :           9 :                     n->def = $4;
   11890                 :           9 :                     $$ = (Node *) n;
   11891                 :             :                 }
   11892                 :             :             /* ALTER DOMAIN <domain> DROP NOT NULL */
   11893                 :             :             | ALTER DOMAIN_P any_name DROP NOT NULL_P
   11894                 :             :                 {
   11895                 :           8 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11896                 :             : 
   11897                 :           8 :                     n->subtype = AD_DropNotNull;
   11898                 :           8 :                     n->typeName = $3;
   11899                 :           8 :                     $$ = (Node *) n;
   11900                 :             :                 }
   11901                 :             :             /* ALTER DOMAIN <domain> SET NOT NULL */
   11902                 :             :             | ALTER DOMAIN_P any_name SET NOT NULL_P
   11903                 :             :                 {
   11904                 :          16 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11905                 :             : 
   11906                 :          16 :                     n->subtype = AD_SetNotNull;
   11907                 :          16 :                     n->typeName = $3;
   11908                 :          16 :                     $$ = (Node *) n;
   11909                 :             :                 }
   11910                 :             :             /* ALTER DOMAIN <domain> ADD CONSTRAINT ... */
   11911                 :             :             | ALTER DOMAIN_P any_name ADD_P DomainConstraint
   11912                 :             :                 {
   11913                 :         125 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11914                 :             : 
   11915                 :         125 :                     n->subtype = AD_AddConstraint;
   11916                 :         125 :                     n->typeName = $3;
   11917                 :         125 :                     n->def = $5;
   11918                 :         125 :                     $$ = (Node *) n;
   11919                 :             :                 }
   11920                 :             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT <name> [RESTRICT|CASCADE] */
   11921                 :             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT name opt_drop_behavior
   11922                 :             :                 {
   11923                 :          36 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11924                 :             : 
   11925                 :          36 :                     n->subtype = AD_DropConstraint;
   11926                 :          36 :                     n->typeName = $3;
   11927                 :          36 :                     n->name = $6;
   11928                 :          36 :                     n->behavior = $7;
   11929                 :          36 :                     n->missing_ok = false;
   11930                 :          36 :                     $$ = (Node *) n;
   11931                 :             :                 }
   11932                 :             :             /* ALTER DOMAIN <domain> DROP CONSTRAINT IF EXISTS <name> [RESTRICT|CASCADE] */
   11933                 :             :             | ALTER DOMAIN_P any_name DROP CONSTRAINT IF_P EXISTS name opt_drop_behavior
   11934                 :             :                 {
   11935                 :           4 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11936                 :             : 
   11937                 :           4 :                     n->subtype = AD_DropConstraint;
   11938                 :           4 :                     n->typeName = $3;
   11939                 :           4 :                     n->name = $8;
   11940                 :           4 :                     n->behavior = $9;
   11941                 :           4 :                     n->missing_ok = true;
   11942                 :           4 :                     $$ = (Node *) n;
   11943                 :             :                 }
   11944                 :             :             /* ALTER DOMAIN <domain> VALIDATE CONSTRAINT <name> */
   11945                 :             :             | ALTER DOMAIN_P any_name VALIDATE CONSTRAINT name
   11946                 :             :                 {
   11947                 :           9 :                     AlterDomainStmt *n = makeNode(AlterDomainStmt);
   11948                 :             : 
   11949                 :           9 :                     n->subtype = AD_ValidateConstraint;
   11950                 :           9 :                     n->typeName = $3;
   11951                 :           9 :                     n->name = $6;
   11952                 :           9 :                     $$ = (Node *) n;
   11953                 :             :                 }
   11954                 :             :             ;
   11955                 :             : 
   11956                 :             : opt_as:     AS
   11957                 :             :             | /* EMPTY */
   11958                 :             :         ;
   11959                 :             : 
   11960                 :             : 
   11961                 :             : /*****************************************************************************
   11962                 :             :  *
   11963                 :             :  * Manipulate a text search dictionary or configuration
   11964                 :             :  *
   11965                 :             :  *****************************************************************************/
   11966                 :             : 
   11967                 :             : AlterTSDictionaryStmt:
   11968                 :             :             ALTER TEXT_P SEARCH DICTIONARY any_name definition
   11969                 :             :                 {
   11970                 :          23 :                     AlterTSDictionaryStmt *n = makeNode(AlterTSDictionaryStmt);
   11971                 :             : 
   11972                 :          23 :                     n->dictname = $5;
   11973                 :          23 :                     n->options = $6;
   11974                 :          23 :                     $$ = (Node *) n;
   11975                 :             :                 }
   11976                 :             :         ;
   11977                 :             : 
   11978                 :             : AlterTSConfigurationStmt:
   11979                 :             :             ALTER TEXT_P SEARCH CONFIGURATION any_name ADD_P MAPPING FOR name_list any_with any_name_list
   11980                 :             :                 {
   11981                 :        5386 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11982                 :             : 
   11983                 :        5386 :                     n->kind = ALTER_TSCONFIG_ADD_MAPPING;
   11984                 :        5386 :                     n->cfgname = $5;
   11985                 :        5386 :                     n->tokentype = $9;
   11986                 :        5386 :                     n->dicts = $11;
   11987                 :        5386 :                     n->override = false;
   11988                 :        5386 :                     n->replace = false;
   11989                 :        5386 :                     $$ = (Node *) n;
   11990                 :             :                 }
   11991                 :             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list any_with any_name_list
   11992                 :             :                 {
   11993                 :          17 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   11994                 :             : 
   11995                 :          17 :                     n->kind = ALTER_TSCONFIG_ALTER_MAPPING_FOR_TOKEN;
   11996                 :          17 :                     n->cfgname = $5;
   11997                 :          17 :                     n->tokentype = $9;
   11998                 :          17 :                     n->dicts = $11;
   11999                 :          17 :                     n->override = true;
   12000                 :          17 :                     n->replace = false;
   12001                 :          17 :                     $$ = (Node *) n;
   12002                 :             :                 }
   12003                 :             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING REPLACE any_name any_with any_name
   12004                 :             :                 {
   12005                 :          12 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   12006                 :             : 
   12007                 :          12 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT;
   12008                 :          12 :                     n->cfgname = $5;
   12009                 :          12 :                     n->tokentype = NIL;
   12010                 :          12 :                     n->dicts = list_make2($9,$11);
   12011                 :          12 :                     n->override = false;
   12012                 :          12 :                     n->replace = true;
   12013                 :          12 :                     $$ = (Node *) n;
   12014                 :             :                 }
   12015                 :             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name ALTER MAPPING FOR name_list REPLACE any_name any_with any_name
   12016                 :             :                 {
   12017                 :           0 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   12018                 :             : 
   12019                 :           0 :                     n->kind = ALTER_TSCONFIG_REPLACE_DICT_FOR_TOKEN;
   12020                 :           0 :                     n->cfgname = $5;
   12021                 :           0 :                     n->tokentype = $9;
   12022                 :           0 :                     n->dicts = list_make2($11,$13);
   12023                 :           0 :                     n->override = false;
   12024                 :           0 :                     n->replace = true;
   12025                 :           0 :                     $$ = (Node *) n;
   12026                 :             :                 }
   12027                 :             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING FOR name_list
   12028                 :             :                 {
   12029                 :          13 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   12030                 :             : 
   12031                 :          13 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   12032                 :          13 :                     n->cfgname = $5;
   12033                 :          13 :                     n->tokentype = $9;
   12034                 :          13 :                     n->missing_ok = false;
   12035                 :          13 :                     $$ = (Node *) n;
   12036                 :             :                 }
   12037                 :             :             | ALTER TEXT_P SEARCH CONFIGURATION any_name DROP MAPPING IF_P EXISTS FOR name_list
   12038                 :             :                 {
   12039                 :           8 :                     AlterTSConfigurationStmt *n = makeNode(AlterTSConfigurationStmt);
   12040                 :             : 
   12041                 :           8 :                     n->kind = ALTER_TSCONFIG_DROP_MAPPING;
   12042                 :           8 :                     n->cfgname = $5;
   12043                 :           8 :                     n->tokentype = $11;
   12044                 :           8 :                     n->missing_ok = true;
   12045                 :           8 :                     $$ = (Node *) n;
   12046                 :             :                 }
   12047                 :             :         ;
   12048                 :             : 
   12049                 :             : /* Use this if TIME or ORDINALITY after WITH should be taken as an identifier */
   12050                 :             : any_with:   WITH
   12051                 :             :             | WITH_LA
   12052                 :             :         ;
   12053                 :             : 
   12054                 :             : 
   12055                 :             : /*****************************************************************************
   12056                 :             :  *
   12057                 :             :  * Manipulate a conversion
   12058                 :             :  *
   12059                 :             :  *      CREATE [DEFAULT] CONVERSION <conversion_name>
   12060                 :             :  *      FOR <encoding_name> TO <encoding_name> FROM <func_name>
   12061                 :             :  *
   12062                 :             :  *****************************************************************************/
   12063                 :             : 
   12064                 :             : CreateConversionStmt:
   12065                 :             :             CREATE opt_default CONVERSION_P any_name FOR Sconst
   12066                 :             :             TO Sconst FROM any_name
   12067                 :             :             {
   12068                 :          42 :                 CreateConversionStmt *n = makeNode(CreateConversionStmt);
   12069                 :             : 
   12070                 :          42 :                 n->conversion_name = $4;
   12071                 :          42 :                 n->for_encoding_name = $6;
   12072                 :          42 :                 n->to_encoding_name = $8;
   12073                 :          42 :                 n->func_name = $10;
   12074                 :          42 :                 n->def = $2;
   12075                 :          42 :                 $$ = (Node *) n;
   12076                 :             :             }
   12077                 :             :         ;
   12078                 :             : 
   12079                 :             : /*****************************************************************************
   12080                 :             :  *
   12081                 :             :  *      QUERY:
   12082                 :             :  *              REPACK [ (options) ] [ <qualified_name> [ <name_list> ] [ USING INDEX <index_name> ] ]
   12083                 :             :  *
   12084                 :             :  *          obsolete variants:
   12085                 :             :  *              CLUSTER (options) [ <qualified_name> [ USING <index_name> ] ]
   12086                 :             :  *              CLUSTER [VERBOSE] [ <qualified_name> [ USING <index_name> ] ]
   12087                 :             :  *              CLUSTER [VERBOSE] <index_name> ON <qualified_name> (for pre-8.3)
   12088                 :             :  *
   12089                 :             :  *****************************************************************************/
   12090                 :             : 
   12091                 :             : RepackStmt:
   12092                 :             :             REPACK opt_utility_option_list qualified_name opt_name_list USING INDEX name
   12093                 :             :                 {
   12094                 :          19 :                     RepackStmt *n = makeNode(RepackStmt);
   12095                 :             : 
   12096                 :          19 :                     n->command = REPACK_COMMAND_REPACK;
   12097                 :          19 :                     n->relation = makeVacuumRelation($3, InvalidOid, $4);
   12098                 :          19 :                     n->indexname = $7;
   12099                 :          19 :                     n->usingindex = true;
   12100                 :          19 :                     n->params = $2;
   12101                 :          19 :                     $$ = (Node *) n;
   12102                 :             :                 }
   12103                 :             :             | REPACK opt_utility_option_list qualified_name opt_name_list opt_usingindex
   12104                 :             :                 {
   12105                 :          69 :                     RepackStmt *n = makeNode(RepackStmt);
   12106                 :             : 
   12107                 :          69 :                     n->command = REPACK_COMMAND_REPACK;
   12108                 :          69 :                     n->relation = makeVacuumRelation($3, InvalidOid, $4);
   12109                 :          69 :                     n->indexname = NULL;
   12110                 :          69 :                     n->usingindex = $5;
   12111                 :          69 :                     n->params = $2;
   12112                 :          69 :                     $$ = (Node *) n;
   12113                 :             :                 }
   12114                 :             :             | REPACK opt_utility_option_list opt_usingindex
   12115                 :             :                 {
   12116                 :           4 :                     RepackStmt *n = makeNode(RepackStmt);
   12117                 :             : 
   12118                 :           4 :                     n->command = REPACK_COMMAND_REPACK;
   12119                 :           4 :                     n->relation = NULL;
   12120                 :           4 :                     n->indexname = NULL;
   12121                 :           4 :                     n->usingindex = $3;
   12122                 :           4 :                     n->params = $2;
   12123                 :           4 :                     $$ = (Node *) n;
   12124                 :             :                 }
   12125                 :             :             | CLUSTER '(' utility_option_list ')' qualified_name cluster_index_specification
   12126                 :             :                 {
   12127                 :           0 :                     RepackStmt *n = makeNode(RepackStmt);
   12128                 :             : 
   12129                 :           0 :                     n->command = REPACK_COMMAND_CLUSTER;
   12130                 :           0 :                     n->relation = makeNode(VacuumRelation);
   12131                 :           0 :                     n->relation->relation = $5;
   12132                 :           0 :                     n->indexname = $6;
   12133                 :           0 :                     n->usingindex = true;
   12134                 :           0 :                     n->params = $3;
   12135                 :           0 :                     $$ = (Node *) n;
   12136                 :             :                 }
   12137                 :             :             | CLUSTER opt_utility_option_list
   12138                 :             :                 {
   12139                 :           9 :                     RepackStmt *n = makeNode(RepackStmt);
   12140                 :             : 
   12141                 :           9 :                     n->command = REPACK_COMMAND_CLUSTER;
   12142                 :           9 :                     n->relation = NULL;
   12143                 :           9 :                     n->indexname = NULL;
   12144                 :           9 :                     n->usingindex = true;
   12145                 :           9 :                     n->params = $2;
   12146                 :           9 :                     $$ = (Node *) n;
   12147                 :             :                 }
   12148                 :             :             /* unparenthesized VERBOSE kept for pre-14 compatibility */
   12149                 :             :             | CLUSTER opt_verbose qualified_name cluster_index_specification
   12150                 :             :                 {
   12151                 :         148 :                     RepackStmt *n = makeNode(RepackStmt);
   12152                 :             : 
   12153                 :         148 :                     n->command = REPACK_COMMAND_CLUSTER;
   12154                 :         148 :                     n->relation = makeNode(VacuumRelation);
   12155                 :         148 :                     n->relation->relation = $3;
   12156                 :         148 :                     n->indexname = $4;
   12157                 :         148 :                     n->usingindex = true;
   12158         [ -  + ]:         148 :                     if ($2)
   12159                 :           0 :                         n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12160                 :         148 :                     $$ = (Node *) n;
   12161                 :             :                 }
   12162                 :             :             /* unparenthesized VERBOSE kept for pre-17 compatibility */
   12163                 :             :             | CLUSTER VERBOSE
   12164                 :             :                 {
   12165                 :           1 :                     RepackStmt *n = makeNode(RepackStmt);
   12166                 :             : 
   12167                 :           1 :                     n->command = REPACK_COMMAND_CLUSTER;
   12168                 :           1 :                     n->relation = NULL;
   12169                 :           1 :                     n->indexname = NULL;
   12170                 :           1 :                     n->usingindex = true;
   12171                 :           1 :                     n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12172                 :           1 :                     $$ = (Node *) n;
   12173                 :             :                 }
   12174                 :             :             /* kept for pre-8.3 compatibility */
   12175                 :             :             | CLUSTER opt_verbose name ON qualified_name
   12176                 :             :                 {
   12177                 :          13 :                     RepackStmt *n = makeNode(RepackStmt);
   12178                 :             : 
   12179                 :          13 :                     n->command = REPACK_COMMAND_CLUSTER;
   12180                 :          13 :                     n->relation = makeNode(VacuumRelation);
   12181                 :          13 :                     n->relation->relation = $5;
   12182                 :          13 :                     n->indexname = $3;
   12183                 :          13 :                     n->usingindex = true;
   12184         [ -  + ]:          13 :                     if ($2)
   12185                 :           0 :                         n->params = list_make1(makeDefElem("verbose", NULL, @2));
   12186                 :          13 :                     $$ = (Node *) n;
   12187                 :             :                 }
   12188                 :             :         ;
   12189                 :             : 
   12190                 :             : cluster_index_specification:
   12191                 :         123 :             USING name              { $$ = $2; }
   12192                 :          25 :             | /*EMPTY*/             { $$ = NULL; }
   12193                 :             :         ;
   12194                 :             : 
   12195                 :             : 
   12196                 :             : /*****************************************************************************
   12197                 :             :  *
   12198                 :             :  *      QUERY:
   12199                 :             :  *              VACUUM
   12200                 :             :  *              ANALYZE
   12201                 :             :  *
   12202                 :             :  *****************************************************************************/
   12203                 :             : 
   12204                 :             : VacuumStmt: VACUUM opt_full opt_freeze opt_verbose opt_analyze opt_vacuum_relation_list
   12205                 :             :                 {
   12206                 :         822 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12207                 :             : 
   12208                 :         822 :                     n->options = NIL;
   12209         [ +  + ]:         822 :                     if ($2)
   12210                 :         109 :                         n->options = lappend(n->options,
   12211                 :         109 :                                              makeDefElem("full", NULL, @2));
   12212         [ +  + ]:         822 :                     if ($3)
   12213                 :          92 :                         n->options = lappend(n->options,
   12214                 :          92 :                                              makeDefElem("freeze", NULL, @3));
   12215         [ +  + ]:         822 :                     if ($4)
   12216                 :           9 :                         n->options = lappend(n->options,
   12217                 :           9 :                                              makeDefElem("verbose", NULL, @4));
   12218         [ +  + ]:         822 :                     if ($5)
   12219                 :         224 :                         n->options = lappend(n->options,
   12220                 :         224 :                                              makeDefElem("analyze", NULL, @5));
   12221                 :         822 :                     n->rels = $6;
   12222                 :         822 :                     n->is_vacuumcmd = true;
   12223                 :         822 :                     $$ = (Node *) n;
   12224                 :             :                 }
   12225                 :             :             | VACUUM '(' utility_option_list ')' opt_vacuum_relation_list
   12226                 :             :                 {
   12227                 :        4726 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12228                 :             : 
   12229                 :        4726 :                     n->options = $3;
   12230                 :        4726 :                     n->rels = $5;
   12231                 :        4726 :                     n->is_vacuumcmd = true;
   12232                 :        4726 :                     $$ = (Node *) n;
   12233                 :             :                 }
   12234                 :             :         ;
   12235                 :             : 
   12236                 :             : AnalyzeStmt: analyze_keyword opt_utility_option_list opt_vacuum_relation_list
   12237                 :             :                 {
   12238                 :        3080 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12239                 :             : 
   12240                 :        3080 :                     n->options = $2;
   12241                 :        3080 :                     n->rels = $3;
   12242                 :        3080 :                     n->is_vacuumcmd = false;
   12243                 :        3080 :                     $$ = (Node *) n;
   12244                 :             :                 }
   12245                 :             :             | analyze_keyword VERBOSE opt_vacuum_relation_list
   12246                 :             :                 {
   12247                 :           8 :                     VacuumStmt *n = makeNode(VacuumStmt);
   12248                 :             : 
   12249                 :           8 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12250                 :           8 :                     n->rels = $3;
   12251                 :           8 :                     n->is_vacuumcmd = false;
   12252                 :           8 :                     $$ = (Node *) n;
   12253                 :             :                 }
   12254                 :             :         ;
   12255                 :             : 
   12256                 :             : analyze_keyword:
   12257                 :             :             ANALYZE
   12258                 :             :             | ANALYSE /* British */
   12259                 :             :         ;
   12260                 :             : 
   12261                 :             : opt_analyze:
   12262                 :         224 :             analyze_keyword                         { $$ = true; }
   12263                 :         598 :             | /*EMPTY*/                             { $$ = false; }
   12264                 :             :         ;
   12265                 :             : 
   12266                 :             : opt_verbose:
   12267                 :           9 :             VERBOSE                                 { $$ = true; }
   12268                 :        2550 :             | /*EMPTY*/                             { $$ = false; }
   12269                 :             :         ;
   12270                 :             : 
   12271                 :         109 : opt_full:   FULL                                    { $$ = true; }
   12272                 :         713 :             | /*EMPTY*/                             { $$ = false; }
   12273                 :             :         ;
   12274                 :             : 
   12275                 :          92 : opt_freeze: FREEZE                                  { $$ = true; }
   12276                 :         730 :             | /*EMPTY*/                             { $$ = false; }
   12277                 :             :         ;
   12278                 :             : 
   12279                 :             : opt_name_list:
   12280                 :        1841 :             '(' name_list ')'                       { $$ = $2; }
   12281                 :       10591 :             | /*EMPTY*/                             { $$ = NIL; }
   12282                 :             :         ;
   12283                 :             : 
   12284                 :             : vacuum_relation:
   12285                 :             :             relation_expr opt_name_list
   12286                 :             :                 {
   12287                 :        8549 :                     $$ = (Node *) makeVacuumRelation($1, InvalidOid, $2);
   12288                 :             :                 }
   12289                 :             :         ;
   12290                 :             : 
   12291                 :             : vacuum_relation_list:
   12292                 :             :             vacuum_relation
   12293                 :        8424 :                     { $$ = list_make1($1); }
   12294                 :             :             | vacuum_relation_list ',' vacuum_relation
   12295                 :         125 :                     { $$ = lappend($1, $3); }
   12296                 :             :         ;
   12297                 :             : 
   12298                 :             : opt_vacuum_relation_list:
   12299                 :        8424 :             vacuum_relation_list                    { $$ = $1; }
   12300                 :         212 :             | /*EMPTY*/                             { $$ = NIL; }
   12301                 :             :         ;
   12302                 :             : 
   12303                 :             : 
   12304                 :             : /*****************************************************************************
   12305                 :             :  *
   12306                 :             :  *      QUERY:
   12307                 :             :  *              EXPLAIN [ANALYZE] [VERBOSE] query
   12308                 :             :  *              EXPLAIN ( options ) query
   12309                 :             :  *
   12310                 :             :  *****************************************************************************/
   12311                 :             : 
   12312                 :             : ExplainStmt:
   12313                 :             :         EXPLAIN ExplainableStmt
   12314                 :             :                 {
   12315                 :        4751 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12316                 :             : 
   12317                 :        4751 :                     n->query = $2;
   12318                 :        4751 :                     n->options = NIL;
   12319                 :        4751 :                     $$ = (Node *) n;
   12320                 :             :                 }
   12321                 :             :         | EXPLAIN analyze_keyword opt_verbose ExplainableStmt
   12322                 :             :                 {
   12323                 :        1576 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12324                 :             : 
   12325                 :        1576 :                     n->query = $4;
   12326                 :        1576 :                     n->options = list_make1(makeDefElem("analyze", NULL, @2));
   12327         [ -  + ]:        1576 :                     if ($3)
   12328                 :           0 :                         n->options = lappend(n->options,
   12329                 :           0 :                                              makeDefElem("verbose", NULL, @3));
   12330                 :        1576 :                     $$ = (Node *) n;
   12331                 :             :                 }
   12332                 :             :         | EXPLAIN VERBOSE ExplainableStmt
   12333                 :             :                 {
   12334                 :           8 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12335                 :             : 
   12336                 :           8 :                     n->query = $3;
   12337                 :           8 :                     n->options = list_make1(makeDefElem("verbose", NULL, @2));
   12338                 :           8 :                     $$ = (Node *) n;
   12339                 :             :                 }
   12340                 :             :         | EXPLAIN '(' utility_option_list ')' ExplainableStmt
   12341                 :             :                 {
   12342                 :       10761 :                     ExplainStmt *n = makeNode(ExplainStmt);
   12343                 :             : 
   12344                 :       10761 :                     n->query = $5;
   12345                 :       10761 :                     n->options = $3;
   12346                 :       10761 :                     $$ = (Node *) n;
   12347                 :             :                 }
   12348                 :             :         ;
   12349                 :             : 
   12350                 :             : ExplainableStmt:
   12351                 :             :             SelectStmt
   12352                 :             :             | InsertStmt
   12353                 :             :             | UpdateStmt
   12354                 :             :             | DeleteStmt
   12355                 :             :             | MergeStmt
   12356                 :             :             | DeclareCursorStmt
   12357                 :             :             | CreateAsStmt
   12358                 :             :             | CreateMatViewStmt
   12359                 :             :             | RefreshMatViewStmt
   12360                 :             :             | ExecuteStmt                   /* by default all are $$=$1 */
   12361                 :             :         ;
   12362                 :             : 
   12363                 :             : /*****************************************************************************
   12364                 :             :  *
   12365                 :             :  *      QUERY:
   12366                 :             :  *              PREPARE <plan_name> [(args, ...)] AS <query>
   12367                 :             :  *
   12368                 :             :  *****************************************************************************/
   12369                 :             : 
   12370                 :             : PrepareStmt: PREPARE name prep_type_clause AS PreparableStmt
   12371                 :             :                 {
   12372                 :        1124 :                     PrepareStmt *n = makeNode(PrepareStmt);
   12373                 :             : 
   12374                 :        1124 :                     n->name = $2;
   12375                 :        1124 :                     n->argtypes = $3;
   12376                 :        1124 :                     n->query = $5;
   12377                 :        1124 :                     $$ = (Node *) n;
   12378                 :             :                 }
   12379                 :             :         ;
   12380                 :             : 
   12381                 :         909 : prep_type_clause: '(' type_list ')'         { $$ = $2; }
   12382                 :         227 :                 | /* EMPTY */               { $$ = NIL; }
   12383                 :             :         ;
   12384                 :             : 
   12385                 :             : PreparableStmt:
   12386                 :             :             SelectStmt
   12387                 :             :             | InsertStmt
   12388                 :             :             | UpdateStmt
   12389                 :             :             | DeleteStmt
   12390                 :             :             | MergeStmt                     /* by default all are $$=$1 */
   12391                 :             :         ;
   12392                 :             : 
   12393                 :             : /*****************************************************************************
   12394                 :             :  *
   12395                 :             :  * EXECUTE <plan_name> [(params, ...)]
   12396                 :             :  * CREATE TABLE <name> AS EXECUTE <plan_name> [(params, ...)]
   12397                 :             :  *
   12398                 :             :  *****************************************************************************/
   12399                 :             : 
   12400                 :             : ExecuteStmt: EXECUTE name execute_param_clause
   12401                 :             :                 {
   12402                 :        8717 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12403                 :             : 
   12404                 :        8717 :                     n->name = $2;
   12405                 :        8717 :                     n->params = $3;
   12406                 :        8717 :                     $$ = (Node *) n;
   12407                 :             :                 }
   12408                 :             :             | CREATE OptTemp TABLE create_as_target AS
   12409                 :             :                 EXECUTE name execute_param_clause opt_with_data
   12410                 :             :                 {
   12411                 :          50 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12412                 :          50 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12413                 :             : 
   12414                 :          50 :                     n->name = $7;
   12415                 :          50 :                     n->params = $8;
   12416                 :          50 :                     ctas->query = (Node *) n;
   12417                 :          50 :                     ctas->into = $4;
   12418                 :          50 :                     ctas->objtype = OBJECT_TABLE;
   12419                 :          50 :                     ctas->is_select_into = false;
   12420                 :          50 :                     ctas->if_not_exists = false;
   12421                 :             :                     /* cram additional flags into the IntoClause */
   12422                 :          50 :                     $4->rel->relpersistence = $2;
   12423                 :          50 :                     $4->skipData = !($9);
   12424                 :          50 :                     $$ = (Node *) ctas;
   12425                 :             :                 }
   12426                 :             :             | CREATE OptTemp TABLE IF_P NOT EXISTS create_as_target AS
   12427                 :             :                 EXECUTE name execute_param_clause opt_with_data
   12428                 :             :                 {
   12429                 :           8 :                     CreateTableAsStmt *ctas = makeNode(CreateTableAsStmt);
   12430                 :           8 :                     ExecuteStmt *n = makeNode(ExecuteStmt);
   12431                 :             : 
   12432                 :           8 :                     n->name = $10;
   12433                 :           8 :                     n->params = $11;
   12434                 :           8 :                     ctas->query = (Node *) n;
   12435                 :           8 :                     ctas->into = $7;
   12436                 :           8 :                     ctas->objtype = OBJECT_TABLE;
   12437                 :           8 :                     ctas->is_select_into = false;
   12438                 :           8 :                     ctas->if_not_exists = true;
   12439                 :             :                     /* cram additional flags into the IntoClause */
   12440                 :           8 :                     $7->rel->relpersistence = $2;
   12441                 :           8 :                     $7->skipData = !($12);
   12442                 :           8 :                     $$ = (Node *) ctas;
   12443                 :             :                 }
   12444                 :             :         ;
   12445                 :             : 
   12446                 :        8003 : execute_param_clause: '(' expr_list ')'             { $$ = $2; }
   12447                 :         772 :                     | /* EMPTY */                   { $$ = NIL; }
   12448                 :             :                     ;
   12449                 :             : 
   12450                 :             : /*****************************************************************************
   12451                 :             :  *
   12452                 :             :  *      QUERY:
   12453                 :             :  *              DEALLOCATE [PREPARE] <plan_name>
   12454                 :             :  *
   12455                 :             :  *****************************************************************************/
   12456                 :             : 
   12457                 :             : DeallocateStmt: DEALLOCATE name
   12458                 :             :                     {
   12459                 :        2039 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12460                 :             : 
   12461                 :        2039 :                         n->name = $2;
   12462                 :        2039 :                         n->isall = false;
   12463                 :        2039 :                         n->location = @2;
   12464                 :        2039 :                         $$ = (Node *) n;
   12465                 :             :                     }
   12466                 :             :                 | DEALLOCATE PREPARE name
   12467                 :             :                     {
   12468                 :          13 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12469                 :             : 
   12470                 :          13 :                         n->name = $3;
   12471                 :          13 :                         n->isall = false;
   12472                 :          13 :                         n->location = @3;
   12473                 :          13 :                         $$ = (Node *) n;
   12474                 :             :                     }
   12475                 :             :                 | DEALLOCATE ALL
   12476                 :             :                     {
   12477                 :          36 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12478                 :             : 
   12479                 :          36 :                         n->name = NULL;
   12480                 :          36 :                         n->isall = true;
   12481                 :          36 :                         n->location = -1;
   12482                 :          36 :                         $$ = (Node *) n;
   12483                 :             :                     }
   12484                 :             :                 | DEALLOCATE PREPARE ALL
   12485                 :             :                     {
   12486                 :           1 :                         DeallocateStmt *n = makeNode(DeallocateStmt);
   12487                 :             : 
   12488                 :           1 :                         n->name = NULL;
   12489                 :           1 :                         n->isall = true;
   12490                 :           1 :                         n->location = -1;
   12491                 :           1 :                         $$ = (Node *) n;
   12492                 :             :                     }
   12493                 :             :         ;
   12494                 :             : 
   12495                 :             : /*****************************************************************************
   12496                 :             :  *
   12497                 :             :  *      QUERY:
   12498                 :             :  *              INSERT STATEMENTS
   12499                 :             :  *
   12500                 :             :  *****************************************************************************/
   12501                 :             : 
   12502                 :             : InsertStmt:
   12503                 :             :             opt_with_clause INSERT INTO insert_target insert_rest
   12504                 :             :             opt_on_conflict returning_clause
   12505                 :             :                 {
   12506                 :       45619 :                     $5->relation = $4;
   12507                 :       45619 :                     $5->onConflictClause = $6;
   12508                 :       45619 :                     $5->returningClause = $7;
   12509                 :       45619 :                     $5->withClause = $1;
   12510                 :       45619 :                     $$ = (Node *) $5;
   12511                 :             :                 }
   12512                 :             :         ;
   12513                 :             : 
   12514                 :             : /*
   12515                 :             :  * Can't easily make AS optional here, because VALUES in insert_rest would
   12516                 :             :  * have a shift/reduce conflict with VALUES as an optional alias.  We could
   12517                 :             :  * easily allow unreserved_keywords as optional aliases, but that'd be an odd
   12518                 :             :  * divergence from other places.  So just require AS for now.
   12519                 :             :  */
   12520                 :             : insert_target:
   12521                 :             :             qualified_name
   12522                 :             :                 {
   12523                 :       45512 :                     $$ = $1;
   12524                 :             :                 }
   12525                 :             :             | qualified_name AS ColId
   12526                 :             :                 {
   12527                 :         111 :                     $1->alias = makeAlias($3, NIL);
   12528                 :         111 :                     $$ = $1;
   12529                 :             :                 }
   12530                 :             :         ;
   12531                 :             : 
   12532                 :             : insert_rest:
   12533                 :             :             SelectStmt
   12534                 :             :                 {
   12535                 :       31134 :                     $$ = makeNode(InsertStmt);
   12536                 :       31134 :                     $$->cols = NIL;
   12537                 :       31134 :                     $$->selectStmt = $1;
   12538                 :             :                 }
   12539                 :             :             | OVERRIDING override_kind VALUE_P SelectStmt
   12540                 :             :                 {
   12541                 :          64 :                     $$ = makeNode(InsertStmt);
   12542                 :          64 :                     $$->cols = NIL;
   12543                 :          64 :                     $$->override = $2;
   12544                 :          64 :                     $$->selectStmt = $4;
   12545                 :             :                 }
   12546                 :             :             | '(' insert_column_list ')' SelectStmt
   12547                 :             :                 {
   12548                 :        8858 :                     $$ = makeNode(InsertStmt);
   12549                 :        8858 :                     $$->cols = $2;
   12550                 :        8858 :                     $$->selectStmt = $4;
   12551                 :             :                 }
   12552                 :             :             | '(' insert_column_list ')' OVERRIDING override_kind VALUE_P SelectStmt
   12553                 :             :                 {
   12554                 :           0 :                     $$ = makeNode(InsertStmt);
   12555                 :           0 :                     $$->cols = $2;
   12556                 :           0 :                     $$->override = $5;
   12557                 :           0 :                     $$->selectStmt = $7;
   12558                 :             :                 }
   12559                 :             :             | DEFAULT VALUES
   12560                 :             :                 {
   12561                 :        5567 :                     $$ = makeNode(InsertStmt);
   12562                 :        5567 :                     $$->cols = NIL;
   12563                 :        5567 :                     $$->selectStmt = NULL;
   12564                 :             :                 }
   12565                 :             :         ;
   12566                 :             : 
   12567                 :             : override_kind:
   12568                 :          44 :             USER        { $$ = OVERRIDING_USER_VALUE; }
   12569                 :          40 :             | SYSTEM_P  { $$ = OVERRIDING_SYSTEM_VALUE; }
   12570                 :             :         ;
   12571                 :             : 
   12572                 :             : insert_column_list:
   12573                 :             :             insert_column_item
   12574                 :        9077 :                     { $$ = list_make1($1); }
   12575                 :             :             | insert_column_list ',' insert_column_item
   12576                 :        9702 :                     { $$ = lappend($1, $3); }
   12577                 :             :         ;
   12578                 :             : 
   12579                 :             : insert_column_item:
   12580                 :             :             ColId opt_indirection
   12581                 :             :                 {
   12582                 :       18779 :                     $$ = makeNode(ResTarget);
   12583                 :       18779 :                     $$->name = $1;
   12584                 :       18779 :                     $$->indirection = check_indirection($2, yyscanner);
   12585                 :       18779 :                     $$->val = NULL;
   12586                 :       18779 :                     $$->location = @1;
   12587                 :             :                 }
   12588                 :             :         ;
   12589                 :             : 
   12590                 :             : opt_on_conflict:
   12591                 :             :             ON CONFLICT opt_conf_expr DO SELECT opt_for_locking_strength where_clause
   12592                 :             :                 {
   12593                 :         262 :                     $$ = makeNode(OnConflictClause);
   12594                 :         262 :                     $$->action = ONCONFLICT_SELECT;
   12595                 :         262 :                     $$->infer = $3;
   12596                 :         262 :                     $$->targetList = NIL;
   12597                 :         262 :                     $$->lockStrength = $6;
   12598                 :         262 :                     $$->whereClause = $7;
   12599                 :         262 :                     $$->location = @1;
   12600                 :             :                 }
   12601                 :             :             |
   12602                 :             :             ON CONFLICT opt_conf_expr DO UPDATE SET set_clause_list where_clause
   12603                 :             :                 {
   12604                 :         959 :                     $$ = makeNode(OnConflictClause);
   12605                 :         959 :                     $$->action = ONCONFLICT_UPDATE;
   12606                 :         959 :                     $$->infer = $3;
   12607                 :         959 :                     $$->targetList = $7;
   12608                 :         959 :                     $$->lockStrength = LCS_NONE;
   12609                 :         959 :                     $$->whereClause = $8;
   12610                 :         959 :                     $$->location = @1;
   12611                 :             :                 }
   12612                 :             :             |
   12613                 :             :             ON CONFLICT opt_conf_expr DO NOTHING
   12614                 :             :                 {
   12615                 :         413 :                     $$ = makeNode(OnConflictClause);
   12616                 :         413 :                     $$->action = ONCONFLICT_NOTHING;
   12617                 :         413 :                     $$->infer = $3;
   12618                 :         413 :                     $$->targetList = NIL;
   12619                 :         413 :                     $$->lockStrength = LCS_NONE;
   12620                 :         413 :                     $$->whereClause = NULL;
   12621                 :         413 :                     $$->location = @1;
   12622                 :             :                 }
   12623                 :             :             | /*EMPTY*/
   12624                 :             :                 {
   12625                 :       43989 :                     $$ = NULL;
   12626                 :             :                 }
   12627                 :             :         ;
   12628                 :             : 
   12629                 :             : opt_conf_expr:
   12630                 :             :             '(' index_params ')' where_clause
   12631                 :             :                 {
   12632                 :        1292 :                     $$ = makeNode(InferClause);
   12633                 :        1292 :                     $$->indexElems = $2;
   12634                 :        1292 :                     $$->whereClause = $4;
   12635                 :        1292 :                     $$->conname = NULL;
   12636                 :        1292 :                     $$->location = @1;
   12637                 :             :                 }
   12638                 :             :             |
   12639                 :             :             ON CONSTRAINT name
   12640                 :             :                 {
   12641                 :         190 :                     $$ = makeNode(InferClause);
   12642                 :         190 :                     $$->indexElems = NIL;
   12643                 :         190 :                     $$->whereClause = NULL;
   12644                 :         190 :                     $$->conname = $3;
   12645                 :         190 :                     $$->location = @1;
   12646                 :             :                 }
   12647                 :             :             | /*EMPTY*/
   12648                 :             :                 {
   12649                 :         152 :                     $$ = NULL;
   12650                 :             :                 }
   12651                 :             :         ;
   12652                 :             : 
   12653                 :             : returning_clause:
   12654                 :             :             RETURNING returning_with_clause target_list
   12655                 :             :                 {
   12656                 :        2411 :                     ReturningClause *n = makeNode(ReturningClause);
   12657                 :             : 
   12658                 :        2411 :                     n->options = $2;
   12659                 :        2411 :                     n->exprs = $3;
   12660                 :        2411 :                     $$ = n;
   12661                 :             :                 }
   12662                 :             :             | /* EMPTY */
   12663                 :             :                 {
   12664                 :       56535 :                     $$ = NULL;
   12665                 :             :                 }
   12666                 :             :         ;
   12667                 :             : 
   12668                 :             : returning_with_clause:
   12669                 :          48 :             WITH '(' returning_options ')'      { $$ = $3; }
   12670                 :        2363 :             | /* EMPTY */                       { $$ = NIL; }
   12671                 :             :         ;
   12672                 :             : 
   12673                 :             : returning_options:
   12674                 :          48 :             returning_option                            { $$ = list_make1($1); }
   12675                 :          36 :             | returning_options ',' returning_option    { $$ = lappend($1, $3); }
   12676                 :             :         ;
   12677                 :             : 
   12678                 :             : returning_option:
   12679                 :             :             returning_option_kind AS ColId
   12680                 :             :                 {
   12681                 :          84 :                     ReturningOption *n = makeNode(ReturningOption);
   12682                 :             : 
   12683                 :          84 :                     n->option = $1;
   12684                 :          84 :                     n->value = $3;
   12685                 :          84 :                     n->location = @1;
   12686                 :          84 :                     $$ = (Node *) n;
   12687                 :             :                 }
   12688                 :             :         ;
   12689                 :             : 
   12690                 :             : returning_option_kind:
   12691                 :          36 :             OLD         { $$ = RETURNING_OPTION_OLD; }
   12692                 :          48 :             | NEW       { $$ = RETURNING_OPTION_NEW; }
   12693                 :             :         ;
   12694                 :             : 
   12695                 :             : 
   12696                 :             : /*****************************************************************************
   12697                 :             :  *
   12698                 :             :  *      QUERY:
   12699                 :             :  *              DELETE STATEMENTS
   12700                 :             :  *
   12701                 :             :  *****************************************************************************/
   12702                 :             : 
   12703                 :             : DeleteStmt: opt_with_clause DELETE_P FROM relation_expr_opt_alias
   12704                 :             :             using_clause where_or_current_clause returning_clause
   12705                 :             :                 {
   12706                 :        3023 :                     DeleteStmt *n = makeNode(DeleteStmt);
   12707                 :             : 
   12708                 :        3023 :                     n->relation = $4;
   12709                 :        3023 :                     n->usingClause = $5;
   12710                 :        3023 :                     n->whereClause = $6;
   12711                 :        3023 :                     n->returningClause = $7;
   12712                 :        3023 :                     n->withClause = $1;
   12713                 :        3023 :                     $$ = (Node *) n;
   12714                 :             :                 }
   12715                 :             :         ;
   12716                 :             : 
   12717                 :             : using_clause:
   12718                 :          68 :                 USING from_list                     { $$ = $2; }
   12719                 :        2955 :             | /*EMPTY*/                             { $$ = NIL; }
   12720                 :             :         ;
   12721                 :             : 
   12722                 :             : 
   12723                 :             : /*****************************************************************************
   12724                 :             :  *
   12725                 :             :  *      QUERY:
   12726                 :             :  *              LOCK TABLE
   12727                 :             :  *
   12728                 :             :  *****************************************************************************/
   12729                 :             : 
   12730                 :             : LockStmt:   LOCK_P opt_table relation_expr_list opt_lock opt_nowait
   12731                 :             :                 {
   12732                 :         597 :                     LockStmt   *n = makeNode(LockStmt);
   12733                 :             : 
   12734                 :         597 :                     n->relations = $3;
   12735                 :         597 :                     n->mode = $4;
   12736                 :         597 :                     n->nowait = $5;
   12737                 :         597 :                     $$ = (Node *) n;
   12738                 :             :                 }
   12739                 :             :         ;
   12740                 :             : 
   12741                 :         530 : opt_lock:   IN_P lock_type MODE             { $$ = $2; }
   12742                 :          67 :             | /*EMPTY*/                     { $$ = AccessExclusiveLock; }
   12743                 :             :         ;
   12744                 :             : 
   12745                 :         240 : lock_type:  ACCESS SHARE                    { $$ = AccessShareLock; }
   12746                 :           9 :             | ROW SHARE                     { $$ = RowShareLock; }
   12747                 :          52 :             | ROW EXCLUSIVE                 { $$ = RowExclusiveLock; }
   12748                 :          35 :             | SHARE UPDATE EXCLUSIVE        { $$ = ShareUpdateExclusiveLock; }
   12749                 :          42 :             | SHARE                         { $$ = ShareLock; }
   12750                 :           9 :             | SHARE ROW EXCLUSIVE           { $$ = ShareRowExclusiveLock; }
   12751                 :          63 :             | EXCLUSIVE                     { $$ = ExclusiveLock; }
   12752                 :          80 :             | ACCESS EXCLUSIVE              { $$ = AccessExclusiveLock; }
   12753                 :             :         ;
   12754                 :             : 
   12755                 :         102 : opt_nowait: NOWAIT                          { $$ = true; }
   12756                 :         511 :             | /*EMPTY*/                     { $$ = false; }
   12757                 :             :         ;
   12758                 :             : 
   12759                 :             : opt_nowait_or_skip:
   12760                 :          29 :             NOWAIT                          { $$ = LockWaitError; }
   12761                 :          96 :             | SKIP LOCKED                   { $$ = LockWaitSkip; }
   12762                 :        4871 :             | /*EMPTY*/                     { $$ = LockWaitBlock; }
   12763                 :             :         ;
   12764                 :             : 
   12765                 :             : 
   12766                 :             : /*****************************************************************************
   12767                 :             :  *
   12768                 :             :  *      QUERY:
   12769                 :             :  *              UpdateStmt (UPDATE)
   12770                 :             :  *
   12771                 :             :  *****************************************************************************/
   12772                 :             : 
   12773                 :             : UpdateStmt: opt_with_clause UPDATE relation_expr_opt_alias
   12774                 :             :             SET set_clause_list
   12775                 :             :             from_clause
   12776                 :             :             where_or_current_clause
   12777                 :             :             returning_clause
   12778                 :             :                 {
   12779                 :        8868 :                     UpdateStmt *n = makeNode(UpdateStmt);
   12780                 :             : 
   12781                 :        8868 :                     n->relation = $3;
   12782                 :        8868 :                     n->targetList = $5;
   12783                 :        8868 :                     n->fromClause = $6;
   12784                 :        8868 :                     n->whereClause = $7;
   12785                 :        8868 :                     n->returningClause = $8;
   12786                 :        8868 :                     n->withClause = $1;
   12787                 :        8868 :                     $$ = (Node *) n;
   12788                 :             :                 }
   12789                 :             :         ;
   12790                 :             : 
   12791                 :             : set_clause_list:
   12792                 :       10894 :             set_clause                          { $$ = $1; }
   12793                 :        2492 :             | set_clause_list ',' set_clause    { $$ = list_concat($1,$3); }
   12794                 :             :         ;
   12795                 :             : 
   12796                 :             : set_clause:
   12797                 :             :             set_target '=' a_expr
   12798                 :             :                 {
   12799                 :       13265 :                     $1->val = (Node *) $3;
   12800                 :       13265 :                     $$ = list_make1($1);
   12801                 :             :                 }
   12802                 :             :             | '(' set_target_list ')' '=' a_expr
   12803                 :             :                 {
   12804                 :         121 :                     int         ncolumns = list_length($2);
   12805                 :         121 :                     int         i = 1;
   12806                 :             :                     ListCell   *col_cell;
   12807                 :             : 
   12808                 :             :                     /* Create a MultiAssignRef source for each target */
   12809   [ +  -  +  +  :         374 :                     foreach(col_cell, $2)
                   +  + ]
   12810                 :             :                     {
   12811                 :         253 :                         ResTarget  *res_col = (ResTarget *) lfirst(col_cell);
   12812                 :         253 :                         MultiAssignRef *r = makeNode(MultiAssignRef);
   12813                 :             : 
   12814                 :         253 :                         r->source = (Node *) $5;
   12815                 :         253 :                         r->colno = i;
   12816                 :         253 :                         r->ncolumns = ncolumns;
   12817                 :         253 :                         res_col->val = (Node *) r;
   12818                 :         253 :                         i++;
   12819                 :             :                     }
   12820                 :             : 
   12821                 :         121 :                     $$ = $2;
   12822                 :             :                 }
   12823                 :             :         ;
   12824                 :             : 
   12825                 :             : set_target:
   12826                 :             :             ColId opt_indirection
   12827                 :             :                 {
   12828                 :       13522 :                     $$ = makeNode(ResTarget);
   12829                 :       13522 :                     $$->name = $1;
   12830                 :       13522 :                     $$->indirection = check_indirection($2, yyscanner);
   12831                 :       13522 :                     $$->val = NULL;  /* upper production sets this */
   12832                 :       13522 :                     $$->location = @1;
   12833                 :             :                 }
   12834                 :             :         ;
   12835                 :             : 
   12836                 :             : set_target_list:
   12837                 :         125 :             set_target                              { $$ = list_make1($1); }
   12838                 :         132 :             | set_target_list ',' set_target        { $$ = lappend($1,$3); }
   12839                 :             :         ;
   12840                 :             : 
   12841                 :             : 
   12842                 :             : /*****************************************************************************
   12843                 :             :  *
   12844                 :             :  *      QUERY:
   12845                 :             :  *              MERGE
   12846                 :             :  *
   12847                 :             :  *****************************************************************************/
   12848                 :             : 
   12849                 :             : MergeStmt:
   12850                 :             :             opt_with_clause MERGE INTO relation_expr_opt_alias
   12851                 :             :             USING table_ref
   12852                 :             :             ON a_expr
   12853                 :             :             merge_when_list
   12854                 :             :             returning_clause
   12855                 :             :                 {
   12856                 :        1436 :                     MergeStmt  *m = makeNode(MergeStmt);
   12857                 :             : 
   12858                 :        1436 :                     m->withClause = $1;
   12859                 :        1436 :                     m->relation = $4;
   12860                 :        1436 :                     m->sourceRelation = $6;
   12861                 :        1436 :                     m->joinCondition = $8;
   12862                 :        1436 :                     m->mergeWhenClauses = $9;
   12863                 :        1436 :                     m->returningClause = $10;
   12864                 :             : 
   12865                 :        1436 :                     $$ = (Node *) m;
   12866                 :             :                 }
   12867                 :             :         ;
   12868                 :             : 
   12869                 :             : merge_when_list:
   12870                 :        1436 :             merge_when_clause                       { $$ = list_make1($1); }
   12871                 :         811 :             | merge_when_list merge_when_clause     { $$ = lappend($1,$2); }
   12872                 :             :         ;
   12873                 :             : 
   12874                 :             : /*
   12875                 :             :  * A WHEN clause may be WHEN MATCHED, WHEN NOT MATCHED BY SOURCE, or WHEN NOT
   12876                 :             :  * MATCHED [BY TARGET]. The first two cases match target tuples, and support
   12877                 :             :  * UPDATE/DELETE/DO NOTHING actions. The third case does not match target
   12878                 :             :  * tuples, and only supports INSERT/DO NOTHING actions.
   12879                 :             :  */
   12880                 :             : merge_when_clause:
   12881                 :             :             merge_when_tgt_matched opt_merge_when_condition THEN merge_update
   12882                 :             :                 {
   12883                 :        1067 :                     $4->matchKind = $1;
   12884                 :        1067 :                     $4->condition = $2;
   12885                 :             : 
   12886                 :        1067 :                     $$ = (Node *) $4;
   12887                 :             :                 }
   12888                 :             :             | merge_when_tgt_matched opt_merge_when_condition THEN merge_delete
   12889                 :             :                 {
   12890                 :         375 :                     $4->matchKind = $1;
   12891                 :         375 :                     $4->condition = $2;
   12892                 :             : 
   12893                 :         375 :                     $$ = (Node *) $4;
   12894                 :             :                 }
   12895                 :             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN merge_insert
   12896                 :             :                 {
   12897                 :         742 :                     $4->matchKind = $1;
   12898                 :         742 :                     $4->condition = $2;
   12899                 :             : 
   12900                 :         742 :                     $$ = (Node *) $4;
   12901                 :             :                 }
   12902                 :             :             | merge_when_tgt_matched opt_merge_when_condition THEN DO NOTHING
   12903                 :             :                 {
   12904                 :          46 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12905                 :             : 
   12906                 :          46 :                     m->matchKind = $1;
   12907                 :          46 :                     m->commandType = CMD_NOTHING;
   12908                 :          46 :                     m->condition = $2;
   12909                 :             : 
   12910                 :          46 :                     $$ = (Node *) m;
   12911                 :             :                 }
   12912                 :             :             | merge_when_tgt_not_matched opt_merge_when_condition THEN DO NOTHING
   12913                 :             :                 {
   12914                 :          17 :                     MergeWhenClause *m = makeNode(MergeWhenClause);
   12915                 :             : 
   12916                 :          17 :                     m->matchKind = $1;
   12917                 :          17 :                     m->commandType = CMD_NOTHING;
   12918                 :          17 :                     m->condition = $2;
   12919                 :             : 
   12920                 :          17 :                     $$ = (Node *) m;
   12921                 :             :                 }
   12922                 :             :         ;
   12923                 :             : 
   12924                 :             : merge_when_tgt_matched:
   12925                 :        1372 :             WHEN MATCHED                    { $$ = MERGE_WHEN_MATCHED; }
   12926                 :         128 :             | WHEN NOT MATCHED BY SOURCE    { $$ = MERGE_WHEN_NOT_MATCHED_BY_SOURCE; }
   12927                 :             :         ;
   12928                 :             : 
   12929                 :             : merge_when_tgt_not_matched:
   12930                 :         763 :             WHEN NOT MATCHED                { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12931                 :          12 :             | WHEN NOT MATCHED BY TARGET    { $$ = MERGE_WHEN_NOT_MATCHED_BY_TARGET; }
   12932                 :             :         ;
   12933                 :             : 
   12934                 :             : opt_merge_when_condition:
   12935                 :         566 :             AND a_expr              { $$ = $2; }
   12936                 :        1709 :             |                       { $$ = NULL; }
   12937                 :             :         ;
   12938                 :             : 
   12939                 :             : merge_update:
   12940                 :             :             UPDATE SET set_clause_list
   12941                 :             :                 {
   12942                 :        1067 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12943                 :        1067 :                     n->commandType = CMD_UPDATE;
   12944                 :        1067 :                     n->override = OVERRIDING_NOT_SET;
   12945                 :        1067 :                     n->targetList = $3;
   12946                 :        1067 :                     n->values = NIL;
   12947                 :             : 
   12948                 :        1067 :                     $$ = n;
   12949                 :             :                 }
   12950                 :             :         ;
   12951                 :             : 
   12952                 :             : merge_delete:
   12953                 :             :             DELETE_P
   12954                 :             :                 {
   12955                 :         375 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12956                 :         375 :                     n->commandType = CMD_DELETE;
   12957                 :         375 :                     n->override = OVERRIDING_NOT_SET;
   12958                 :         375 :                     n->targetList = NIL;
   12959                 :         375 :                     n->values = NIL;
   12960                 :             : 
   12961                 :         375 :                     $$ = n;
   12962                 :             :                 }
   12963                 :             :         ;
   12964                 :             : 
   12965                 :             : merge_insert:
   12966                 :             :             INSERT merge_values_clause
   12967                 :             :                 {
   12968                 :         499 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12969                 :         499 :                     n->commandType = CMD_INSERT;
   12970                 :         499 :                     n->override = OVERRIDING_NOT_SET;
   12971                 :         499 :                     n->targetList = NIL;
   12972                 :         499 :                     n->values = $2;
   12973                 :         499 :                     $$ = n;
   12974                 :             :                 }
   12975                 :             :             | INSERT OVERRIDING override_kind VALUE_P merge_values_clause
   12976                 :             :                 {
   12977                 :           0 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12978                 :           0 :                     n->commandType = CMD_INSERT;
   12979                 :           0 :                     n->override = $3;
   12980                 :           0 :                     n->targetList = NIL;
   12981                 :           0 :                     n->values = $5;
   12982                 :           0 :                     $$ = n;
   12983                 :             :                 }
   12984                 :             :             | INSERT '(' insert_column_list ')' merge_values_clause
   12985                 :             :                 {
   12986                 :         199 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12987                 :         199 :                     n->commandType = CMD_INSERT;
   12988                 :         199 :                     n->override = OVERRIDING_NOT_SET;
   12989                 :         199 :                     n->targetList = $3;
   12990                 :         199 :                     n->values = $5;
   12991                 :         199 :                     $$ = n;
   12992                 :             :                 }
   12993                 :             :             | INSERT '(' insert_column_list ')' OVERRIDING override_kind VALUE_P merge_values_clause
   12994                 :             :                 {
   12995                 :          20 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   12996                 :          20 :                     n->commandType = CMD_INSERT;
   12997                 :          20 :                     n->override = $6;
   12998                 :          20 :                     n->targetList = $3;
   12999                 :          20 :                     n->values = $8;
   13000                 :          20 :                     $$ = n;
   13001                 :             :                 }
   13002                 :             :             | INSERT DEFAULT VALUES
   13003                 :             :                 {
   13004                 :          24 :                     MergeWhenClause *n = makeNode(MergeWhenClause);
   13005                 :          24 :                     n->commandType = CMD_INSERT;
   13006                 :          24 :                     n->override = OVERRIDING_NOT_SET;
   13007                 :          24 :                     n->targetList = NIL;
   13008                 :          24 :                     n->values = NIL;
   13009                 :          24 :                     $$ = n;
   13010                 :             :                 }
   13011                 :             :         ;
   13012                 :             : 
   13013                 :             : merge_values_clause:
   13014                 :             :             VALUES '(' expr_list ')'
   13015                 :             :                 {
   13016                 :         718 :                     $$ = $3;
   13017                 :             :                 }
   13018                 :             :         ;
   13019                 :             : 
   13020                 :             : /*****************************************************************************
   13021                 :             :  *
   13022                 :             :  *      QUERY:
   13023                 :             :  *              CURSOR STATEMENTS
   13024                 :             :  *
   13025                 :             :  *****************************************************************************/
   13026                 :             : DeclareCursorStmt: DECLARE cursor_name cursor_options CURSOR opt_hold FOR SelectStmt
   13027                 :             :                 {
   13028                 :        2792 :                     DeclareCursorStmt *n = makeNode(DeclareCursorStmt);
   13029                 :             : 
   13030                 :        2792 :                     n->portalname = $2;
   13031                 :             :                     /* currently we always set FAST_PLAN option */
   13032                 :        2792 :                     n->options = $3 | $5 | CURSOR_OPT_FAST_PLAN;
   13033                 :        2792 :                     n->query = $7;
   13034                 :        2792 :                     $$ = (Node *) n;
   13035                 :             :                 }
   13036                 :             :         ;
   13037                 :             : 
   13038                 :        8709 : cursor_name:    name                        { $$ = $1; }
   13039                 :             :         ;
   13040                 :             : 
   13041                 :        2792 : cursor_options: /*EMPTY*/                   { $$ = 0; }
   13042                 :          18 :             | cursor_options NO SCROLL      { $$ = $1 | CURSOR_OPT_NO_SCROLL; }
   13043                 :         164 :             | cursor_options SCROLL         { $$ = $1 | CURSOR_OPT_SCROLL; }
   13044                 :           8 :             | cursor_options BINARY         { $$ = $1 | CURSOR_OPT_BINARY; }
   13045                 :           0 :             | cursor_options ASENSITIVE     { $$ = $1 | CURSOR_OPT_ASENSITIVE; }
   13046                 :           4 :             | cursor_options INSENSITIVE    { $$ = $1 | CURSOR_OPT_INSENSITIVE; }
   13047                 :             :         ;
   13048                 :             : 
   13049                 :        2725 : opt_hold: /* EMPTY */                       { $$ = 0; }
   13050                 :          63 :             | WITH HOLD                     { $$ = CURSOR_OPT_HOLD; }
   13051                 :           4 :             | WITHOUT HOLD                  { $$ = 0; }
   13052                 :             :         ;
   13053                 :             : 
   13054                 :             : /*****************************************************************************
   13055                 :             :  *
   13056                 :             :  *      QUERY:
   13057                 :             :  *              SELECT STATEMENTS
   13058                 :             :  *
   13059                 :             :  *****************************************************************************/
   13060                 :             : 
   13061                 :             : /* A complete SELECT statement looks like this.
   13062                 :             :  *
   13063                 :             :  * The rule returns either a single SelectStmt node or a tree of them,
   13064                 :             :  * representing a set-operation tree.
   13065                 :             :  *
   13066                 :             :  * There is an ambiguity when a sub-SELECT is within an a_expr and there
   13067                 :             :  * are excess parentheses: do the parentheses belong to the sub-SELECT or
   13068                 :             :  * to the surrounding a_expr?  We don't really care, but bison wants to know.
   13069                 :             :  * To resolve the ambiguity, we are careful to define the grammar so that
   13070                 :             :  * the decision is staved off as long as possible: as long as we can keep
   13071                 :             :  * absorbing parentheses into the sub-SELECT, we will do so, and only when
   13072                 :             :  * it's no longer possible to do that will we decide that parens belong to
   13073                 :             :  * the expression.  For example, in "SELECT (((SELECT 2)) + 3)" the extra
   13074                 :             :  * parentheses are treated as part of the sub-select.  The necessity of doing
   13075                 :             :  * it that way is shown by "SELECT (((SELECT 2)) UNION SELECT 2)".    Had we
   13076                 :             :  * parsed "((SELECT 2))" as an a_expr, it'd be too late to go back to the
   13077                 :             :  * SELECT viewpoint when we see the UNION.
   13078                 :             :  *
   13079                 :             :  * This approach is implemented by defining a nonterminal select_with_parens,
   13080                 :             :  * which represents a SELECT with at least one outer layer of parentheses,
   13081                 :             :  * and being careful to use select_with_parens, never '(' SelectStmt ')',
   13082                 :             :  * in the expression grammar.  We will then have shift-reduce conflicts
   13083                 :             :  * which we can resolve in favor of always treating '(' <select> ')' as
   13084                 :             :  * a select_with_parens.  To resolve the conflicts, the productions that
   13085                 :             :  * conflict with the select_with_parens productions are manually given
   13086                 :             :  * precedences lower than the precedence of ')', thereby ensuring that we
   13087                 :             :  * shift ')' (and then reduce to select_with_parens) rather than trying to
   13088                 :             :  * reduce the inner <select> nonterminal to something else.  We use UMINUS
   13089                 :             :  * precedence for this, which is a fairly arbitrary choice.
   13090                 :             :  *
   13091                 :             :  * To be able to define select_with_parens itself without ambiguity, we need
   13092                 :             :  * a nonterminal select_no_parens that represents a SELECT structure with no
   13093                 :             :  * outermost parentheses.  This is a little bit tedious, but it works.
   13094                 :             :  *
   13095                 :             :  * In non-expression contexts, we use SelectStmt which can represent a SELECT
   13096                 :             :  * with or without outer parentheses.
   13097                 :             :  */
   13098                 :             : 
   13099                 :             : SelectStmt: select_no_parens            %prec UMINUS
   13100                 :             :             | select_with_parens        %prec UMINUS
   13101                 :             :         ;
   13102                 :             : 
   13103                 :             : select_with_parens:
   13104                 :       49137 :             '(' select_no_parens ')'                { $$ = $2; }
   13105                 :         104 :             | '(' select_with_parens ')'            { $$ = $2; }
   13106                 :             :         ;
   13107                 :             : 
   13108                 :             : /*
   13109                 :             :  * This rule parses the equivalent of the standard's <query expression>.
   13110                 :             :  * The duplicative productions are annoying, but hard to get rid of without
   13111                 :             :  * creating shift/reduce conflicts.
   13112                 :             :  *
   13113                 :             :  *  The locking clause (FOR UPDATE etc) may be before or after LIMIT/OFFSET.
   13114                 :             :  *  In <=7.2.X, LIMIT/OFFSET had to be after FOR UPDATE
   13115                 :             :  *  We now support both orderings, but prefer LIMIT/OFFSET before the locking
   13116                 :             :  * clause.
   13117                 :             :  *  2002-08-28 bjm
   13118                 :             :  */
   13119                 :             : select_no_parens:
   13120                 :      259323 :             simple_select                       { $$ = $1; }
   13121                 :             :             | select_clause sort_clause
   13122                 :             :                 {
   13123                 :       47656 :                     insertSelectOptions((SelectStmt *) $1, $2, NIL,
   13124                 :             :                                         NULL, NULL,
   13125                 :             :                                         yyscanner);
   13126                 :       47656 :                     $$ = $1;
   13127                 :             :                 }
   13128                 :             :             | select_clause opt_sort_clause for_locking_clause opt_select_limit
   13129                 :             :                 {
   13130                 :        4770 :                     insertSelectOptions((SelectStmt *) $1, $2, $3,
   13131                 :        4770 :                                         $4,
   13132                 :             :                                         NULL,
   13133                 :             :                                         yyscanner);
   13134                 :        4770 :                     $$ = $1;
   13135                 :             :                 }
   13136                 :             :             | select_clause opt_sort_clause select_limit opt_for_locking_clause
   13137                 :             :                 {
   13138                 :        3183 :                     insertSelectOptions((SelectStmt *) $1, $2, $4,
   13139                 :        3183 :                                         $3,
   13140                 :             :                                         NULL,
   13141                 :             :                                         yyscanner);
   13142                 :        3175 :                     $$ = $1;
   13143                 :             :                 }
   13144                 :             :             | with_clause select_clause
   13145                 :             :                 {
   13146                 :        1641 :                     insertSelectOptions((SelectStmt *) $2, NULL, NIL,
   13147                 :             :                                         NULL,
   13148                 :        1641 :                                         $1,
   13149                 :             :                                         yyscanner);
   13150                 :        1641 :                     $$ = $2;
   13151                 :             :                 }
   13152                 :             :             | with_clause select_clause sort_clause
   13153                 :             :                 {
   13154                 :         368 :                     insertSelectOptions((SelectStmt *) $2, $3, NIL,
   13155                 :             :                                         NULL,
   13156                 :         368 :                                         $1,
   13157                 :             :                                         yyscanner);
   13158                 :         368 :                     $$ = $2;
   13159                 :             :                 }
   13160                 :             :             | with_clause select_clause opt_sort_clause for_locking_clause opt_select_limit
   13161                 :             :                 {
   13162                 :           4 :                     insertSelectOptions((SelectStmt *) $2, $3, $4,
   13163                 :           4 :                                         $5,
   13164                 :           4 :                                         $1,
   13165                 :             :                                         yyscanner);
   13166                 :           4 :                     $$ = $2;
   13167                 :             :                 }
   13168                 :             :             | with_clause select_clause opt_sort_clause select_limit opt_for_locking_clause
   13169                 :             :                 {
   13170                 :          42 :                     insertSelectOptions((SelectStmt *) $2, $3, $5,
   13171                 :          42 :                                         $4,
   13172                 :          42 :                                         $1,
   13173                 :             :                                         yyscanner);
   13174                 :          42 :                     $$ = $2;
   13175                 :             :                 }
   13176                 :             :         ;
   13177                 :             : 
   13178                 :             : select_clause:
   13179                 :       83379 :             simple_select                           { $$ = $1; }
   13180                 :         409 :             | select_with_parens                    { $$ = $1; }
   13181                 :             :         ;
   13182                 :             : 
   13183                 :             : /*
   13184                 :             :  * This rule parses SELECT statements that can appear within set operations,
   13185                 :             :  * including UNION, INTERSECT and EXCEPT.  '(' and ')' can be used to specify
   13186                 :             :  * the ordering of the set operations.  Without '(' and ')' we want the
   13187                 :             :  * operations to be ordered per the precedence specs at the head of this file.
   13188                 :             :  *
   13189                 :             :  * As with select_no_parens, simple_select cannot have outer parentheses,
   13190                 :             :  * but can have parenthesized subclauses.
   13191                 :             :  *
   13192                 :             :  * It might appear that we could fold the first two alternatives into one
   13193                 :             :  * by using opt_distinct_clause.  However, that causes a shift/reduce conflict
   13194                 :             :  * against INSERT ... SELECT ... ON CONFLICT.  We avoid the ambiguity by
   13195                 :             :  * requiring SELECT DISTINCT [ON] to be followed by a non-empty target_list.
   13196                 :             :  *
   13197                 :             :  * Note that sort clauses cannot be included at this level --- SQL requires
   13198                 :             :  *      SELECT foo UNION SELECT bar ORDER BY baz
   13199                 :             :  * to be parsed as
   13200                 :             :  *      (SELECT foo UNION SELECT bar) ORDER BY baz
   13201                 :             :  * not
   13202                 :             :  *      SELECT foo UNION (SELECT bar ORDER BY baz)
   13203                 :             :  * Likewise for WITH, FOR UPDATE and LIMIT.  Therefore, those clauses are
   13204                 :             :  * described as part of the select_no_parens production, not simple_select.
   13205                 :             :  * This does not limit functionality, because you can reintroduce these
   13206                 :             :  * clauses inside parentheses.
   13207                 :             :  *
   13208                 :             :  * NOTE: only the leftmost component SelectStmt should have INTO.
   13209                 :             :  * However, this is not checked by the grammar; parse analysis must check it.
   13210                 :             :  */
   13211                 :             : simple_select:
   13212                 :             :             SELECT opt_all_clause opt_target_list
   13213                 :             :             into_clause from_clause where_clause
   13214                 :             :             group_clause having_clause window_clause
   13215                 :             :                 {
   13216                 :      285632 :                     SelectStmt *n = makeNode(SelectStmt);
   13217                 :             : 
   13218                 :      285631 :                     n->targetList = $3;
   13219                 :      285631 :                     n->intoClause = $4;
   13220                 :      285631 :                     n->fromClause = $5;
   13221                 :      285631 :                     n->whereClause = $6;
   13222                 :      285631 :                     n->groupClause = ($7)->list;
   13223                 :      285631 :                     n->groupDistinct = ($7)->distinct;
   13224                 :      285631 :                     n->havingClause = $8;
   13225                 :      285631 :                     n->windowClause = $9;
   13226                 :      285631 :                     $$ = (Node *) n;
   13227                 :             :                 }
   13228                 :             :             | SELECT distinct_clause target_list
   13229                 :             :             into_clause from_clause where_clause
   13230                 :             :             group_clause having_clause window_clause
   13231                 :             :                 {
   13232                 :        2477 :                     SelectStmt *n = makeNode(SelectStmt);
   13233                 :             : 
   13234                 :        2477 :                     n->distinctClause = $2;
   13235                 :        2477 :                     n->targetList = $3;
   13236                 :        2477 :                     n->intoClause = $4;
   13237                 :        2477 :                     n->fromClause = $5;
   13238                 :        2477 :                     n->whereClause = $6;
   13239                 :        2477 :                     n->groupClause = ($7)->list;
   13240                 :        2477 :                     n->groupDistinct = ($7)->distinct;
   13241                 :        2477 :                     n->havingClause = $8;
   13242                 :        2477 :                     n->windowClause = $9;
   13243                 :        2477 :                     $$ = (Node *) n;
   13244                 :             :                 }
   13245                 :       41282 :             | values_clause                         { $$ = $1; }
   13246                 :             :             | TABLE relation_expr
   13247                 :             :                 {
   13248                 :             :                     /* same as SELECT * FROM relation_expr */
   13249                 :         253 :                     ColumnRef  *cr = makeNode(ColumnRef);
   13250                 :         253 :                     ResTarget  *rt = makeNode(ResTarget);
   13251                 :         253 :                     SelectStmt *n = makeNode(SelectStmt);
   13252                 :             : 
   13253                 :         253 :                     cr->fields = list_make1(makeNode(A_Star));
   13254                 :         253 :                     cr->location = -1;
   13255                 :             : 
   13256                 :         253 :                     rt->name = NULL;
   13257                 :         253 :                     rt->indirection = NIL;
   13258                 :         253 :                     rt->val = (Node *) cr;
   13259                 :         253 :                     rt->location = -1;
   13260                 :             : 
   13261                 :         253 :                     n->targetList = list_make1(rt);
   13262                 :         253 :                     n->fromClause = list_make1($2);
   13263                 :         253 :                     $$ = (Node *) n;
   13264                 :             :                 }
   13265                 :             :             | select_clause UNION set_quantifier select_clause
   13266                 :             :                 {
   13267                 :       12503 :                     $$ = makeSetOp(SETOP_UNION, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13268                 :             :                 }
   13269                 :             :             | select_clause INTERSECT set_quantifier select_clause
   13270                 :             :                 {
   13271                 :         216 :                     $$ = makeSetOp(SETOP_INTERSECT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13272                 :             :                 }
   13273                 :             :             | select_clause EXCEPT set_quantifier select_clause
   13274                 :             :                 {
   13275                 :         339 :                     $$ = makeSetOp(SETOP_EXCEPT, $3 == SET_QUANTIFIER_ALL, $1, $4);
   13276                 :             :                 }
   13277                 :             :         ;
   13278                 :             : 
   13279                 :             : /*
   13280                 :             :  * SQL standard WITH clause looks like:
   13281                 :             :  *
   13282                 :             :  * WITH [ RECURSIVE ] <query name> [ (<column>,...) ]
   13283                 :             :  *      AS (query) [ SEARCH or CYCLE clause ]
   13284                 :             :  *
   13285                 :             :  * Recognizing WITH_LA here allows a CTE to be named TIME or ORDINALITY.
   13286                 :             :  */
   13287                 :             : with_clause:
   13288                 :             :         WITH cte_list
   13289                 :             :             {
   13290                 :        1523 :                 $$ = makeNode(WithClause);
   13291                 :        1523 :                 $$->ctes = $2;
   13292                 :        1523 :                 $$->recursive = false;
   13293                 :        1523 :                 $$->location = @1;
   13294                 :             :             }
   13295                 :             :         | WITH_LA cte_list
   13296                 :             :             {
   13297                 :           4 :                 $$ = makeNode(WithClause);
   13298                 :           4 :                 $$->ctes = $2;
   13299                 :           4 :                 $$->recursive = false;
   13300                 :           4 :                 $$->location = @1;
   13301                 :             :             }
   13302                 :             :         | WITH RECURSIVE cte_list
   13303                 :             :             {
   13304                 :         833 :                 $$ = makeNode(WithClause);
   13305                 :         833 :                 $$->ctes = $3;
   13306                 :         833 :                 $$->recursive = true;
   13307                 :         833 :                 $$->location = @1;
   13308                 :             :             }
   13309                 :             :         ;
   13310                 :             : 
   13311                 :             : cte_list:
   13312                 :        2360 :         common_table_expr                       { $$ = list_make1($1); }
   13313                 :         758 :         | cte_list ',' common_table_expr        { $$ = lappend($1, $3); }
   13314                 :             :         ;
   13315                 :             : 
   13316                 :             : common_table_expr:  name opt_name_list AS opt_materialized '(' PreparableStmt ')' opt_search_clause opt_cycle_clause
   13317                 :             :             {
   13318                 :        3118 :                 CommonTableExpr *n = makeNode(CommonTableExpr);
   13319                 :             : 
   13320                 :        3118 :                 n->ctename = $1;
   13321                 :        3118 :                 n->aliascolnames = $2;
   13322                 :        3118 :                 n->ctematerialized = $4;
   13323                 :        3118 :                 n->ctequery = $6;
   13324                 :        3118 :                 n->search_clause = castNode(CTESearchClause, $8);
   13325                 :        3118 :                 n->cycle_clause = castNode(CTECycleClause, $9);
   13326                 :        3118 :                 n->location = @1;
   13327                 :        3118 :                 $$ = (Node *) n;
   13328                 :             :             }
   13329                 :             :         ;
   13330                 :             : 
   13331                 :             : opt_materialized:
   13332                 :         119 :         MATERIALIZED                            { $$ = CTEMaterializeAlways; }
   13333                 :          32 :         | NOT MATERIALIZED                      { $$ = CTEMaterializeNever; }
   13334                 :        2967 :         | /*EMPTY*/                             { $$ = CTEMaterializeDefault; }
   13335                 :             :         ;
   13336                 :             : 
   13337                 :             : opt_search_clause:
   13338                 :             :         SEARCH DEPTH FIRST_P BY columnList SET ColId
   13339                 :             :             {
   13340                 :          60 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13341                 :             : 
   13342                 :          60 :                 n->search_col_list = $5;
   13343                 :          60 :                 n->search_breadth_first = false;
   13344                 :          60 :                 n->search_seq_column = $7;
   13345                 :          60 :                 n->location = @1;
   13346                 :          60 :                 $$ = (Node *) n;
   13347                 :             :             }
   13348                 :             :         | SEARCH BREADTH FIRST_P BY columnList SET ColId
   13349                 :             :             {
   13350                 :          24 :                 CTESearchClause *n = makeNode(CTESearchClause);
   13351                 :             : 
   13352                 :          24 :                 n->search_col_list = $5;
   13353                 :          24 :                 n->search_breadth_first = true;
   13354                 :          24 :                 n->search_seq_column = $7;
   13355                 :          24 :                 n->location = @1;
   13356                 :          24 :                 $$ = (Node *) n;
   13357                 :             :             }
   13358                 :             :         | /*EMPTY*/
   13359                 :             :             {
   13360                 :        3034 :                 $$ = NULL;
   13361                 :             :             }
   13362                 :             :         ;
   13363                 :             : 
   13364                 :             : opt_cycle_clause:
   13365                 :             :         CYCLE columnList SET ColId TO AexprConst DEFAULT AexprConst USING ColId
   13366                 :             :             {
   13367                 :          44 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13368                 :             : 
   13369                 :          44 :                 n->cycle_col_list = $2;
   13370                 :          44 :                 n->cycle_mark_column = $4;
   13371                 :          44 :                 n->cycle_mark_value = $6;
   13372                 :          44 :                 n->cycle_mark_default = $8;
   13373                 :          44 :                 n->cycle_path_column = $10;
   13374                 :          44 :                 n->location = @1;
   13375                 :          44 :                 $$ = (Node *) n;
   13376                 :             :             }
   13377                 :             :         | CYCLE columnList SET ColId USING ColId
   13378                 :             :             {
   13379                 :          40 :                 CTECycleClause *n = makeNode(CTECycleClause);
   13380                 :             : 
   13381                 :          40 :                 n->cycle_col_list = $2;
   13382                 :          40 :                 n->cycle_mark_column = $4;
   13383                 :          40 :                 n->cycle_mark_value = makeBoolAConst(true, -1);
   13384                 :          40 :                 n->cycle_mark_default = makeBoolAConst(false, -1);
   13385                 :          40 :                 n->cycle_path_column = $6;
   13386                 :          40 :                 n->location = @1;
   13387                 :          40 :                 $$ = (Node *) n;
   13388                 :             :             }
   13389                 :             :         | /*EMPTY*/
   13390                 :             :             {
   13391                 :        3034 :                 $$ = NULL;
   13392                 :             :             }
   13393                 :             :         ;
   13394                 :             : 
   13395                 :             : opt_with_clause:
   13396                 :         305 :         with_clause                             { $$ = $1; }
   13397                 :       58715 :         | /*EMPTY*/                             { $$ = NULL; }
   13398                 :             :         ;
   13399                 :             : 
   13400                 :             : into_clause:
   13401                 :             :             INTO OptTempTableName
   13402                 :             :                 {
   13403                 :          91 :                     $$ = makeNode(IntoClause);
   13404                 :          91 :                     $$->rel = $2;
   13405                 :          91 :                     $$->colNames = NIL;
   13406                 :          91 :                     $$->options = NIL;
   13407                 :          91 :                     $$->onCommit = ONCOMMIT_NOOP;
   13408                 :          91 :                     $$->tableSpaceName = NULL;
   13409                 :          91 :                     $$->viewQuery = NULL;
   13410                 :          91 :                     $$->skipData = false;
   13411                 :             :                 }
   13412                 :             :             | /*EMPTY*/
   13413                 :      288038 :                 { $$ = NULL; }
   13414                 :             :         ;
   13415                 :             : 
   13416                 :             : /*
   13417                 :             :  * Redundancy here is needed to avoid shift/reduce conflicts,
   13418                 :             :  * since TEMP is not a reserved word.  See also OptTemp.
   13419                 :             :  */
   13420                 :             : OptTempTableName:
   13421                 :             :             TEMPORARY opt_table qualified_name
   13422                 :             :                 {
   13423                 :           0 :                     $$ = $3;
   13424                 :           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13425                 :             :                 }
   13426                 :             :             | TEMP opt_table qualified_name
   13427                 :             :                 {
   13428                 :           4 :                     $$ = $3;
   13429                 :           4 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13430                 :             :                 }
   13431                 :             :             | LOCAL TEMPORARY opt_table qualified_name
   13432                 :             :                 {
   13433                 :           0 :                     $$ = $4;
   13434                 :           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13435                 :             :                 }
   13436                 :             :             | LOCAL TEMP opt_table qualified_name
   13437                 :             :                 {
   13438                 :           0 :                     $$ = $4;
   13439                 :           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13440                 :             :                 }
   13441                 :             :             | GLOBAL TEMPORARY opt_table qualified_name
   13442                 :             :                 {
   13443         [ #  # ]:           0 :                     ereport(WARNING,
   13444                 :             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13445                 :             :                              parser_errposition(@1)));
   13446                 :           0 :                     $$ = $4;
   13447                 :           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13448                 :             :                 }
   13449                 :             :             | GLOBAL TEMP opt_table qualified_name
   13450                 :             :                 {
   13451         [ #  # ]:           0 :                     ereport(WARNING,
   13452                 :             :                             (errmsg("GLOBAL is deprecated in temporary table creation"),
   13453                 :             :                              parser_errposition(@1)));
   13454                 :           0 :                     $$ = $4;
   13455                 :           0 :                     $$->relpersistence = RELPERSISTENCE_TEMP;
   13456                 :             :                 }
   13457                 :             :             | UNLOGGED opt_table qualified_name
   13458                 :             :                 {
   13459                 :           0 :                     $$ = $3;
   13460                 :           0 :                     $$->relpersistence = RELPERSISTENCE_UNLOGGED;
   13461                 :             :                 }
   13462                 :             :             | TABLE qualified_name
   13463                 :             :                 {
   13464                 :          20 :                     $$ = $2;
   13465                 :          20 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13466                 :             :                 }
   13467                 :             :             | qualified_name
   13468                 :             :                 {
   13469                 :          67 :                     $$ = $1;
   13470                 :          67 :                     $$->relpersistence = RELPERSISTENCE_PERMANENT;
   13471                 :             :                 }
   13472                 :             :         ;
   13473                 :             : 
   13474                 :             : opt_table:  TABLE
   13475                 :             :             | /*EMPTY*/
   13476                 :             :         ;
   13477                 :             : 
   13478                 :             : set_quantifier:
   13479                 :        7267 :             ALL                                     { $$ = SET_QUANTIFIER_ALL; }
   13480                 :          25 :             | DISTINCT                              { $$ = SET_QUANTIFIER_DISTINCT; }
   13481                 :        9427 :             | /*EMPTY*/                             { $$ = SET_QUANTIFIER_DEFAULT; }
   13482                 :             :         ;
   13483                 :             : 
   13484                 :             : /* We use (NIL) as a placeholder to indicate that all target expressions
   13485                 :             :  * should be placed in the DISTINCT list during parsetree analysis.
   13486                 :             :  */
   13487                 :             : distinct_clause:
   13488                 :        2272 :             DISTINCT                                { $$ = list_make1(NIL); }
   13489                 :         209 :             | DISTINCT ON '(' expr_list ')'         { $$ = $4; }
   13490                 :             :         ;
   13491                 :             : 
   13492                 :             : opt_all_clause:
   13493                 :             :             ALL
   13494                 :             :             | /*EMPTY*/
   13495                 :             :         ;
   13496                 :             : 
   13497                 :             : opt_distinct_clause:
   13498                 :           0 :             distinct_clause                         { $$ = $1; }
   13499                 :       24957 :             | opt_all_clause                        { $$ = NIL; }
   13500                 :             :         ;
   13501                 :             : 
   13502                 :             : opt_sort_clause:
   13503                 :        4839 :             sort_clause                             { $$ = $1; }
   13504                 :      237401 :             | /*EMPTY*/                             { $$ = NIL; }
   13505                 :             :         ;
   13506                 :             : 
   13507                 :             : sort_clause:
   13508                 :       53091 :             ORDER BY sortby_list                    { $$ = $3; }
   13509                 :             :         ;
   13510                 :             : 
   13511                 :             : sortby_list:
   13512                 :       53127 :             sortby                                  { $$ = list_make1($1); }
   13513                 :       18342 :             | sortby_list ',' sortby                { $$ = lappend($1, $3); }
   13514                 :             :         ;
   13515                 :             : 
   13516                 :             : sortby:     a_expr USING qual_all_Op opt_nulls_order
   13517                 :             :                 {
   13518                 :         142 :                     $$ = makeNode(SortBy);
   13519                 :         142 :                     $$->node = $1;
   13520                 :         142 :                     $$->sortby_dir = SORTBY_USING;
   13521                 :         142 :                     $$->sortby_nulls = $4;
   13522                 :         142 :                     $$->useOp = $3;
   13523                 :         142 :                     $$->location = @3;
   13524                 :             :                 }
   13525                 :             :             | a_expr opt_asc_desc opt_nulls_order
   13526                 :             :                 {
   13527                 :       71327 :                     $$ = makeNode(SortBy);
   13528                 :       71327 :                     $$->node = $1;
   13529                 :       71327 :                     $$->sortby_dir = $2;
   13530                 :       71327 :                     $$->sortby_nulls = $3;
   13531                 :       71327 :                     $$->useOp = NIL;
   13532                 :       71327 :                     $$->location = -1;       /* no operator */
   13533                 :             :                 }
   13534                 :             :         ;
   13535                 :             : 
   13536                 :             : 
   13537                 :             : select_limit:
   13538                 :             :             limit_clause offset_clause
   13539                 :             :                 {
   13540                 :          99 :                     $$ = $1;
   13541                 :          99 :                     ($$)->limitOffset = $2;
   13542                 :          99 :                     ($$)->offsetLoc = @2;
   13543                 :             :                 }
   13544                 :             :             | offset_clause limit_clause
   13545                 :             :                 {
   13546                 :         113 :                     $$ = $2;
   13547                 :         113 :                     ($$)->limitOffset = $1;
   13548                 :         113 :                     ($$)->offsetLoc = @1;
   13549                 :             :                 }
   13550                 :             :             | limit_clause
   13551                 :             :                 {
   13552                 :        2710 :                     $$ = $1;
   13553                 :             :                 }
   13554                 :             :             | offset_clause
   13555                 :             :                 {
   13556                 :         398 :                     SelectLimit *n = palloc_object(SelectLimit);
   13557                 :             : 
   13558                 :         398 :                     n->limitOffset = $1;
   13559                 :         398 :                     n->limitCount = NULL;
   13560                 :         398 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13561                 :         398 :                     n->offsetLoc = @1;
   13562                 :         398 :                     n->countLoc = -1;
   13563                 :         398 :                     n->optionLoc = -1;
   13564                 :         398 :                     $$ = n;
   13565                 :             :                 }
   13566                 :             :         ;
   13567                 :             : 
   13568                 :             : opt_select_limit:
   13569                 :          95 :             select_limit                        { $$ = $1; }
   13570                 :       29636 :             | /* EMPTY */                       { $$ = NULL; }
   13571                 :             :         ;
   13572                 :             : 
   13573                 :             : limit_clause:
   13574                 :             :             LIMIT select_limit_value
   13575                 :             :                 {
   13576                 :        2861 :                     SelectLimit *n = palloc_object(SelectLimit);
   13577                 :             : 
   13578                 :        2861 :                     n->limitOffset = NULL;
   13579                 :        2861 :                     n->limitCount = $2;
   13580                 :        2861 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13581                 :        2861 :                     n->offsetLoc = -1;
   13582                 :        2861 :                     n->countLoc = @1;
   13583                 :        2861 :                     n->optionLoc = -1;
   13584                 :        2861 :                     $$ = n;
   13585                 :             :                 }
   13586                 :             :             | LIMIT select_limit_value ',' select_offset_value
   13587                 :             :                 {
   13588                 :             :                     /* Disabled because it was too confusing, bjm 2002-02-18 */
   13589         [ #  # ]:           0 :                     ereport(ERROR,
   13590                 :             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   13591                 :             :                              errmsg("LIMIT #,# syntax is not supported"),
   13592                 :             :                              errhint("Use separate LIMIT and OFFSET clauses."),
   13593                 :             :                              parser_errposition(@1)));
   13594                 :             :                 }
   13595                 :             :             /* SQL:2008 syntax */
   13596                 :             :             /* to avoid shift/reduce conflicts, handle the optional value with
   13597                 :             :              * a separate production rather than an opt_ expression.  The fact
   13598                 :             :              * that ONLY is fully reserved means that this way, we defer any
   13599                 :             :              * decision about what rule reduces ROW or ROWS to the point where
   13600                 :             :              * we can see the ONLY token in the lookahead slot.
   13601                 :             :              */
   13602                 :             :             | FETCH first_or_next select_fetch_first_value row_or_rows ONLY
   13603                 :             :                 {
   13604                 :          15 :                     SelectLimit *n = palloc_object(SelectLimit);
   13605                 :             : 
   13606                 :          15 :                     n->limitOffset = NULL;
   13607                 :          15 :                     n->limitCount = $3;
   13608                 :          15 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13609                 :          15 :                     n->offsetLoc = -1;
   13610                 :          15 :                     n->countLoc = @1;
   13611                 :          15 :                     n->optionLoc = -1;
   13612                 :          15 :                     $$ = n;
   13613                 :             :                 }
   13614                 :             :             | FETCH first_or_next select_fetch_first_value row_or_rows WITH TIES
   13615                 :             :                 {
   13616                 :          42 :                     SelectLimit *n = palloc_object(SelectLimit);
   13617                 :             : 
   13618                 :          42 :                     n->limitOffset = NULL;
   13619                 :          42 :                     n->limitCount = $3;
   13620                 :          42 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13621                 :          42 :                     n->offsetLoc = -1;
   13622                 :          42 :                     n->countLoc = @1;
   13623                 :          42 :                     n->optionLoc = @5;
   13624                 :          42 :                     $$ = n;
   13625                 :             :                 }
   13626                 :             :             | FETCH first_or_next row_or_rows ONLY
   13627                 :             :                 {
   13628                 :           0 :                     SelectLimit *n = palloc_object(SelectLimit);
   13629                 :             : 
   13630                 :           0 :                     n->limitOffset = NULL;
   13631                 :           0 :                     n->limitCount = makeIntConst(1, -1);
   13632                 :           0 :                     n->limitOption = LIMIT_OPTION_COUNT;
   13633                 :           0 :                     n->offsetLoc = -1;
   13634                 :           0 :                     n->countLoc = @1;
   13635                 :           0 :                     n->optionLoc = -1;
   13636                 :           0 :                     $$ = n;
   13637                 :             :                 }
   13638                 :             :             | FETCH first_or_next row_or_rows WITH TIES
   13639                 :             :                 {
   13640                 :           4 :                     SelectLimit *n = palloc_object(SelectLimit);
   13641                 :             : 
   13642                 :           4 :                     n->limitOffset = NULL;
   13643                 :           4 :                     n->limitCount = makeIntConst(1, -1);
   13644                 :           4 :                     n->limitOption = LIMIT_OPTION_WITH_TIES;
   13645                 :           4 :                     n->offsetLoc = -1;
   13646                 :           4 :                     n->countLoc = @1;
   13647                 :           4 :                     n->optionLoc = @4;
   13648                 :           4 :                     $$ = n;
   13649                 :             :                 }
   13650                 :             :         ;
   13651                 :             : 
   13652                 :             : offset_clause:
   13653                 :             :             OFFSET select_offset_value
   13654                 :         610 :                 { $$ = $2; }
   13655                 :             :             /* SQL:2008 syntax */
   13656                 :             :             | OFFSET select_fetch_first_value row_or_rows
   13657                 :           0 :                 { $$ = $2; }
   13658                 :             :         ;
   13659                 :             : 
   13660                 :             : select_limit_value:
   13661                 :        2860 :             a_expr                                  { $$ = $1; }
   13662                 :             :             | ALL
   13663                 :             :                 {
   13664                 :             :                     /* LIMIT ALL is represented as a NULL constant */
   13665                 :           1 :                     $$ = makeNullAConst(@1);
   13666                 :             :                 }
   13667                 :             :         ;
   13668                 :             : 
   13669                 :             : select_offset_value:
   13670                 :         610 :             a_expr                                  { $$ = $1; }
   13671                 :             :         ;
   13672                 :             : 
   13673                 :             : /*
   13674                 :             :  * Allowing full expressions without parentheses causes various parsing
   13675                 :             :  * problems with the trailing ROW/ROWS key words.  SQL spec only calls for
   13676                 :             :  * <simple value specification>, which is either a literal or a parameter (but
   13677                 :             :  * an <SQL parameter reference> could be an identifier, bringing up conflicts
   13678                 :             :  * with ROW/ROWS). We solve this by leveraging the presence of ONLY (see above)
   13679                 :             :  * to determine whether the expression is missing rather than trying to make it
   13680                 :             :  * optional in this rule.
   13681                 :             :  *
   13682                 :             :  * c_expr covers almost all the spec-required cases (and more), but it doesn't
   13683                 :             :  * cover signed numeric literals, which are allowed by the spec. So we include
   13684                 :             :  * those here explicitly. We need FCONST as well as ICONST because values that
   13685                 :             :  * don't fit in the platform's "long", but do fit in bigint, should still be
   13686                 :             :  * accepted here. (This is possible in 64-bit Windows as well as all 32-bit
   13687                 :             :  * builds.)
   13688                 :             :  */
   13689                 :             : select_fetch_first_value:
   13690                 :          57 :             c_expr                                  { $$ = $1; }
   13691                 :             :             | '+' I_or_F_const
   13692                 :           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   13693                 :             :             | '-' I_or_F_const
   13694                 :           0 :                 { $$ = doNegate($2, @1); }
   13695                 :             :         ;
   13696                 :             : 
   13697                 :             : I_or_F_const:
   13698                 :           0 :             Iconst                                  { $$ = makeIntConst($1,@1); }
   13699                 :           0 :             | FCONST                                { $$ = makeFloatConst($1,@1); }
   13700                 :             :         ;
   13701                 :             : 
   13702                 :             : /* noise words */
   13703                 :          23 : row_or_rows: ROW                                    { $$ = 0; }
   13704                 :          38 :             | ROWS                                  { $$ = 0; }
   13705                 :             :         ;
   13706                 :             : 
   13707                 :          61 : first_or_next: FIRST_P                              { $$ = 0; }
   13708                 :           0 :             | NEXT                                  { $$ = 0; }
   13709                 :             :         ;
   13710                 :             : 
   13711                 :             : 
   13712                 :             : /*
   13713                 :             :  * This syntax for group_clause tries to follow the spec quite closely.
   13714                 :             :  * However, the spec allows only column references, not expressions,
   13715                 :             :  * which introduces an ambiguity between implicit row constructors
   13716                 :             :  * (a,b) and lists of column references.
   13717                 :             :  *
   13718                 :             :  * We handle this by using the a_expr production for what the spec calls
   13719                 :             :  * <ordinary grouping set>, which in the spec represents either one column
   13720                 :             :  * reference or a parenthesized list of column references. Then, we check the
   13721                 :             :  * top node of the a_expr to see if it's an implicit RowExpr, and if so, just
   13722                 :             :  * grab and use the list, discarding the node. (this is done in parse analysis,
   13723                 :             :  * not here)
   13724                 :             :  *
   13725                 :             :  * (we abuse the row_format field of RowExpr to distinguish implicit and
   13726                 :             :  * explicit row constructors; it's debatable if anyone sanely wants to use them
   13727                 :             :  * in a group clause, but if they have a reason to, we make it possible.)
   13728                 :             :  *
   13729                 :             :  * Each item in the group_clause list is either an expression tree or a
   13730                 :             :  * GroupingSet node of some type.
   13731                 :             :  */
   13732                 :             : group_clause:
   13733                 :             :             GROUP_P BY set_quantifier group_by_list
   13734                 :             :                 {
   13735                 :        3653 :                     GroupClause *n = palloc_object(GroupClause);
   13736                 :             : 
   13737                 :        3653 :                     n->distinct = $3 == SET_QUANTIFIER_DISTINCT;
   13738                 :        3653 :                     n->list = $4;
   13739                 :        3653 :                     $$ = n;
   13740                 :             :                 }
   13741                 :             :             | /*EMPTY*/
   13742                 :             :                 {
   13743                 :      309413 :                     GroupClause *n = palloc_object(GroupClause);
   13744                 :             : 
   13745                 :      309412 :                     n->distinct = false;
   13746                 :      309412 :                     n->list = NIL;
   13747                 :      309412 :                     $$ = n;
   13748                 :             :                 }
   13749                 :             :         ;
   13750                 :             : 
   13751                 :             : group_by_list:
   13752                 :        4181 :             group_by_item                           { $$ = list_make1($1); }
   13753                 :        2142 :             | group_by_list ',' group_by_item       { $$ = lappend($1,$3); }
   13754                 :             :         ;
   13755                 :             : 
   13756                 :             : group_by_item:
   13757                 :        5231 :             a_expr                                  { $$ = $1; }
   13758                 :         226 :             | empty_grouping_set                    { $$ = $1; }
   13759                 :         122 :             | cube_clause                           { $$ = $1; }
   13760                 :         216 :             | rollup_clause                         { $$ = $1; }
   13761                 :         528 :             | grouping_sets_clause                  { $$ = $1; }
   13762                 :             :         ;
   13763                 :             : 
   13764                 :             : empty_grouping_set:
   13765                 :             :             '(' ')'
   13766                 :             :                 {
   13767                 :         226 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_EMPTY, NIL, @1);
   13768                 :             :                 }
   13769                 :             :         ;
   13770                 :             : 
   13771                 :             : /*
   13772                 :             :  * These hacks rely on setting precedence of CUBE and ROLLUP below that of '(',
   13773                 :             :  * so that they shift in these rules rather than reducing the conflicting
   13774                 :             :  * unreserved_keyword rule.
   13775                 :             :  */
   13776                 :             : 
   13777                 :             : rollup_clause:
   13778                 :             :             ROLLUP '(' expr_list ')'
   13779                 :             :                 {
   13780                 :         216 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_ROLLUP, $3, @1);
   13781                 :             :                 }
   13782                 :             :         ;
   13783                 :             : 
   13784                 :             : cube_clause:
   13785                 :             :             CUBE '(' expr_list ')'
   13786                 :             :                 {
   13787                 :         122 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_CUBE, $3, @1);
   13788                 :             :                 }
   13789                 :             :         ;
   13790                 :             : 
   13791                 :             : grouping_sets_clause:
   13792                 :             :             GROUPING SETS '(' group_by_list ')'
   13793                 :             :                 {
   13794                 :         528 :                     $$ = (Node *) makeGroupingSet(GROUPING_SET_SETS, $4, @1);
   13795                 :             :                 }
   13796                 :             :         ;
   13797                 :             : 
   13798                 :             : having_clause:
   13799                 :         677 :             HAVING a_expr                           { $$ = $2; }
   13800                 :      312389 :             | /*EMPTY*/                             { $$ = NULL; }
   13801                 :             :         ;
   13802                 :             : 
   13803                 :             : for_locking_clause:
   13804                 :        4945 :             for_locking_items                       { $$ = $1; }
   13805                 :           0 :             | FOR READ ONLY                         { $$ = NIL; }
   13806                 :             :         ;
   13807                 :             : 
   13808                 :             : opt_for_locking_clause:
   13809                 :         171 :             for_locking_clause                      { $$ = $1; }
   13810                 :       28011 :             | /* EMPTY */                           { $$ = NIL; }
   13811                 :             :         ;
   13812                 :             : 
   13813                 :             : for_locking_items:
   13814                 :        4945 :             for_locking_item                        { $$ = list_make1($1); }
   13815                 :          51 :             | for_locking_items for_locking_item    { $$ = lappend($1, $2); }
   13816                 :             :         ;
   13817                 :             : 
   13818                 :             : for_locking_item:
   13819                 :             :             for_locking_strength locked_rels_list opt_nowait_or_skip
   13820                 :             :                 {
   13821                 :        4996 :                     LockingClause *n = makeNode(LockingClause);
   13822                 :             : 
   13823                 :        4996 :                     n->lockedRels = $2;
   13824                 :        4996 :                     n->strength = $1;
   13825                 :        4996 :                     n->waitPolicy = $3;
   13826                 :        4996 :                     $$ = (Node *) n;
   13827                 :             :                 }
   13828                 :             :         ;
   13829                 :             : 
   13830                 :             : for_locking_strength:
   13831                 :         913 :             FOR UPDATE                          { $$ = LCS_FORUPDATE; }
   13832                 :          44 :             | FOR NO KEY UPDATE                 { $$ = LCS_FORNOKEYUPDATE; }
   13833                 :         127 :             | FOR SHARE                         { $$ = LCS_FORSHARE; }
   13834                 :        3992 :             | FOR KEY SHARE                     { $$ = LCS_FORKEYSHARE; }
   13835                 :             :         ;
   13836                 :             : 
   13837                 :             : opt_for_locking_strength:
   13838                 :          80 :             for_locking_strength                { $$ = $1; }
   13839                 :         182 :             | /* EMPTY */                       { $$ = LCS_NONE; }
   13840                 :             :         ;
   13841                 :             : 
   13842                 :             : locked_rels_list:
   13843                 :        1239 :             OF qualified_name_list                  { $$ = $2; }
   13844                 :        3757 :             | /* EMPTY */                           { $$ = NIL; }
   13845                 :             :         ;
   13846                 :             : 
   13847                 :             : 
   13848                 :             : /*
   13849                 :             :  * We should allow ROW '(' expr_list ')' too, but that seems to require
   13850                 :             :  * making VALUES a fully reserved word, which will probably break more apps
   13851                 :             :  * than allowing the noise-word is worth.
   13852                 :             :  */
   13853                 :             : values_clause:
   13854                 :             :             VALUES '(' expr_list ')'
   13855                 :             :                 {
   13856                 :       41282 :                     SelectStmt *n = makeNode(SelectStmt);
   13857                 :             : 
   13858                 :       41282 :                     n->valuesLists = list_make1($3);
   13859                 :       41282 :                     $$ = (Node *) n;
   13860                 :             :                 }
   13861                 :             :             | values_clause ',' '(' expr_list ')'
   13862                 :             :                 {
   13863                 :       17062 :                     SelectStmt *n = (SelectStmt *) $1;
   13864                 :             : 
   13865                 :       17062 :                     n->valuesLists = lappend(n->valuesLists, $4);
   13866                 :       17062 :                     $$ = (Node *) n;
   13867                 :             :                 }
   13868                 :             :         ;
   13869                 :             : 
   13870                 :             : 
   13871                 :             : /*****************************************************************************
   13872                 :             :  *
   13873                 :             :  *  clauses common to all Optimizable Stmts:
   13874                 :             :  *      from_clause     - allow list of both JOIN expressions and table names
   13875                 :             :  *      where_clause    - qualifications for joins or restrictions
   13876                 :             :  *
   13877                 :             :  *****************************************************************************/
   13878                 :             : 
   13879                 :             : from_clause:
   13880                 :      210783 :             FROM from_list                          { $$ = $2; }
   13881                 :      111151 :             | /*EMPTY*/                             { $$ = NIL; }
   13882                 :             :         ;
   13883                 :             : 
   13884                 :             : from_list:
   13885                 :      211508 :             table_ref                               { $$ = list_make1($1); }
   13886                 :       37134 :             | from_list ',' table_ref               { $$ = lappend($1, $3); }
   13887                 :             :         ;
   13888                 :             : 
   13889                 :             : /*
   13890                 :             :  * table_ref is where an alias clause can be attached.
   13891                 :             :  */
   13892                 :             : table_ref:  relation_expr opt_alias_clause
   13893                 :             :                 {
   13894                 :      260340 :                     $1->alias = $2;
   13895                 :      260340 :                     $$ = (Node *) $1;
   13896                 :             :                 }
   13897                 :             :             | relation_expr opt_alias_clause tablesample_clause
   13898                 :             :                 {
   13899                 :         174 :                     RangeTableSample *n = (RangeTableSample *) $3;
   13900                 :             : 
   13901                 :         174 :                     $1->alias = $2;
   13902                 :             :                     /* relation_expr goes inside the RangeTableSample node */
   13903                 :         174 :                     n->relation = (Node *) $1;
   13904                 :         174 :                     $$ = (Node *) n;
   13905                 :             :                 }
   13906                 :             :             | func_table func_alias_clause
   13907                 :             :                 {
   13908                 :       29530 :                     RangeFunction *n = (RangeFunction *) $1;
   13909                 :             : 
   13910                 :       29530 :                     n->alias = linitial($2);
   13911                 :       29530 :                     n->coldeflist = lsecond($2);
   13912                 :       29530 :                     $$ = (Node *) n;
   13913                 :             :                 }
   13914                 :             :             | LATERAL_P func_table func_alias_clause
   13915                 :             :                 {
   13916                 :         366 :                     RangeFunction *n = (RangeFunction *) $2;
   13917                 :             : 
   13918                 :         366 :                     n->lateral = true;
   13919                 :         366 :                     n->alias = linitial($3);
   13920                 :         366 :                     n->coldeflist = lsecond($3);
   13921                 :         366 :                     $$ = (Node *) n;
   13922                 :             :                 }
   13923                 :             :             | xmltable opt_alias_clause
   13924                 :             :                 {
   13925                 :          57 :                     RangeTableFunc *n = (RangeTableFunc *) $1;
   13926                 :             : 
   13927                 :          57 :                     n->alias = $2;
   13928                 :          57 :                     $$ = (Node *) n;
   13929                 :             :                 }
   13930                 :             :             | LATERAL_P xmltable opt_alias_clause
   13931                 :             :                 {
   13932                 :          93 :                     RangeTableFunc *n = (RangeTableFunc *) $2;
   13933                 :             : 
   13934                 :          93 :                     n->lateral = true;
   13935                 :          93 :                     n->alias = $3;
   13936                 :          93 :                     $$ = (Node *) n;
   13937                 :             :                 }
   13938                 :             :             | select_with_parens opt_alias_clause
   13939                 :             :                 {
   13940                 :       12670 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13941                 :             : 
   13942                 :       12670 :                     n->lateral = false;
   13943                 :       12670 :                     n->subquery = $1;
   13944                 :       12670 :                     n->alias = $2;
   13945                 :       12670 :                     $$ = (Node *) n;
   13946                 :             :                 }
   13947                 :             :             | LATERAL_P select_with_parens opt_alias_clause
   13948                 :             :                 {
   13949                 :        1308 :                     RangeSubselect *n = makeNode(RangeSubselect);
   13950                 :             : 
   13951                 :        1308 :                     n->lateral = true;
   13952                 :        1308 :                     n->subquery = $2;
   13953                 :        1308 :                     n->alias = $3;
   13954                 :        1308 :                     $$ = (Node *) n;
   13955                 :             :                 }
   13956                 :             :             | joined_table
   13957                 :             :                 {
   13958                 :       54784 :                     $$ = (Node *) $1;
   13959                 :             :                 }
   13960                 :             :             | '(' joined_table ')' alias_clause
   13961                 :             :                 {
   13962                 :         132 :                     $2->alias = $4;
   13963                 :         132 :                     $$ = (Node *) $2;
   13964                 :             :                 }
   13965                 :             :             | json_table opt_alias_clause
   13966                 :             :                 {
   13967                 :         484 :                     JsonTable  *jt = castNode(JsonTable, $1);
   13968                 :             : 
   13969                 :         484 :                     jt->alias = $2;
   13970                 :         484 :                     $$ = (Node *) jt;
   13971                 :             :                 }
   13972                 :             :             | LATERAL_P json_table opt_alias_clause
   13973                 :             :                 {
   13974                 :           0 :                     JsonTable  *jt = castNode(JsonTable, $2);
   13975                 :             : 
   13976                 :           0 :                     jt->alias = $3;
   13977                 :           0 :                     jt->lateral = true;
   13978                 :           0 :                     $$ = (Node *) jt;
   13979                 :             :                 }
   13980                 :             :         ;
   13981                 :             : 
   13982                 :             : 
   13983                 :             : /*
   13984                 :             :  * It may seem silly to separate joined_table from table_ref, but there is
   13985                 :             :  * method in SQL's madness: if you don't do it this way you get reduce-
   13986                 :             :  * reduce conflicts, because it's not clear to the parser generator whether
   13987                 :             :  * to expect alias_clause after ')' or not.  For the same reason we must
   13988                 :             :  * treat 'JOIN' and 'join_type JOIN' separately, rather than allowing
   13989                 :             :  * join_type to expand to empty; if we try it, the parser generator can't
   13990                 :             :  * figure out when to reduce an empty join_type right after table_ref.
   13991                 :             :  *
   13992                 :             :  * Note that a CROSS JOIN is the same as an unqualified
   13993                 :             :  * INNER JOIN, and an INNER JOIN/ON has the same shape
   13994                 :             :  * but a qualification expression to limit membership.
   13995                 :             :  * A NATURAL JOIN implicitly matches column names between
   13996                 :             :  * tables and the shape is determined by which columns are
   13997                 :             :  * in common. We'll collect columns during the later transformations.
   13998                 :             :  */
   13999                 :             : 
   14000                 :             : joined_table:
   14001                 :             :             '(' joined_table ')'
   14002                 :             :                 {
   14003                 :        2436 :                     $$ = $2;
   14004                 :             :                 }
   14005                 :             :             | table_ref CROSS JOIN table_ref
   14006                 :             :                 {
   14007                 :             :                     /* CROSS JOIN is same as unqualified inner join */
   14008                 :         367 :                     JoinExpr   *n = makeNode(JoinExpr);
   14009                 :             : 
   14010                 :         367 :                     n->jointype = JOIN_INNER;
   14011                 :         367 :                     n->isNatural = false;
   14012                 :         367 :                     n->larg = $1;
   14013                 :         367 :                     n->rarg = $4;
   14014                 :         367 :                     n->usingClause = NIL;
   14015                 :         367 :                     n->join_using_alias = NULL;
   14016                 :         367 :                     n->quals = NULL;
   14017                 :         367 :                     $$ = n;
   14018                 :             :                 }
   14019                 :             :             | table_ref join_type JOIN table_ref join_qual
   14020                 :             :                 {
   14021                 :       29767 :                     JoinExpr   *n = makeNode(JoinExpr);
   14022                 :             : 
   14023                 :       29767 :                     n->jointype = $2;
   14024                 :       29767 :                     n->isNatural = false;
   14025                 :       29767 :                     n->larg = $1;
   14026                 :       29767 :                     n->rarg = $4;
   14027   [ +  -  +  + ]:       29767 :                     if ($5 != NULL && IsA($5, List))
   14028                 :             :                     {
   14029                 :             :                          /* USING clause */
   14030                 :         374 :                         n->usingClause = linitial_node(List, castNode(List, $5));
   14031                 :         374 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $5));
   14032                 :             :                     }
   14033                 :             :                     else
   14034                 :             :                     {
   14035                 :             :                         /* ON clause */
   14036                 :       29393 :                         n->quals = $5;
   14037                 :             :                     }
   14038                 :       29767 :                     $$ = n;
   14039                 :             :                 }
   14040                 :             :             | table_ref JOIN table_ref join_qual
   14041                 :             :                 {
   14042                 :             :                     /* letting join_type reduce to empty doesn't work */
   14043                 :       24602 :                     JoinExpr   *n = makeNode(JoinExpr);
   14044                 :             : 
   14045                 :       24602 :                     n->jointype = JOIN_INNER;
   14046                 :       24602 :                     n->isNatural = false;
   14047                 :       24602 :                     n->larg = $1;
   14048                 :       24602 :                     n->rarg = $3;
   14049   [ +  -  +  + ]:       24602 :                     if ($4 != NULL && IsA($4, List))
   14050                 :             :                     {
   14051                 :             :                         /* USING clause */
   14052                 :         499 :                         n->usingClause = linitial_node(List, castNode(List, $4));
   14053                 :         499 :                         n->join_using_alias = lsecond_node(Alias, castNode(List, $4));
   14054                 :             :                     }
   14055                 :             :                     else
   14056                 :             :                     {
   14057                 :             :                         /* ON clause */
   14058                 :       24103 :                         n->quals = $4;
   14059                 :             :                     }
   14060                 :       24602 :                     $$ = n;
   14061                 :             :                 }
   14062                 :             :             | table_ref NATURAL join_type JOIN table_ref
   14063                 :             :                 {
   14064                 :          52 :                     JoinExpr   *n = makeNode(JoinExpr);
   14065                 :             : 
   14066                 :          52 :                     n->jointype = $3;
   14067                 :          52 :                     n->isNatural = true;
   14068                 :          52 :                     n->larg = $1;
   14069                 :          52 :                     n->rarg = $5;
   14070                 :          52 :                     n->usingClause = NIL; /* figure out which columns later... */
   14071                 :          52 :                     n->join_using_alias = NULL;
   14072                 :          52 :                     n->quals = NULL; /* fill later */
   14073                 :          52 :                     $$ = n;
   14074                 :             :                 }
   14075                 :             :             | table_ref NATURAL JOIN table_ref
   14076                 :             :                 {
   14077                 :             :                     /* letting join_type reduce to empty doesn't work */
   14078                 :         128 :                     JoinExpr   *n = makeNode(JoinExpr);
   14079                 :             : 
   14080                 :         128 :                     n->jointype = JOIN_INNER;
   14081                 :         128 :                     n->isNatural = true;
   14082                 :         128 :                     n->larg = $1;
   14083                 :         128 :                     n->rarg = $4;
   14084                 :         128 :                     n->usingClause = NIL; /* figure out which columns later... */
   14085                 :         128 :                     n->join_using_alias = NULL;
   14086                 :         128 :                     n->quals = NULL; /* fill later */
   14087                 :         128 :                     $$ = n;
   14088                 :             :                 }
   14089                 :             :         ;
   14090                 :             : 
   14091                 :             : alias_clause:
   14092                 :             :             AS ColId '(' name_list ')'
   14093                 :             :                 {
   14094                 :        4075 :                     $$ = makeNode(Alias);
   14095                 :        4075 :                     $$->aliasname = $2;
   14096                 :        4075 :                     $$->colnames = $4;
   14097                 :             :                 }
   14098                 :             :             | AS ColId
   14099                 :             :                 {
   14100                 :       10067 :                     $$ = makeNode(Alias);
   14101                 :       10067 :                     $$->aliasname = $2;
   14102                 :             :                 }
   14103                 :             :             | ColId '(' name_list ')'
   14104                 :             :                 {
   14105                 :        3968 :                     $$ = makeNode(Alias);
   14106                 :        3968 :                     $$->aliasname = $1;
   14107                 :        3968 :                     $$->colnames = $3;
   14108                 :             :                 }
   14109                 :             :             | ColId
   14110                 :             :                 {
   14111                 :      172842 :                     $$ = makeNode(Alias);
   14112                 :      172842 :                     $$->aliasname = $1;
   14113                 :             :                 }
   14114                 :             :         ;
   14115                 :             : 
   14116                 :      172960 : opt_alias_clause: alias_clause                      { $$ = $1; }
   14117                 :      102166 :             | /*EMPTY*/                             { $$ = NULL; }
   14118                 :             :         ;
   14119                 :             : 
   14120                 :             : /*
   14121                 :             :  * The alias clause after JOIN ... USING only accepts the AS ColId spelling,
   14122                 :             :  * per SQL standard.  (The grammar could parse the other variants, but they
   14123                 :             :  * don't seem to be useful, and it might lead to parser problems in the
   14124                 :             :  * future.)
   14125                 :             :  */
   14126                 :             : opt_alias_clause_for_join_using:
   14127                 :             :             AS ColId
   14128                 :             :                 {
   14129                 :          56 :                     $$ = makeNode(Alias);
   14130                 :          56 :                     $$->aliasname = $2;
   14131                 :             :                     /* the column name list will be inserted later */
   14132                 :             :                 }
   14133                 :         817 :             | /*EMPTY*/                             { $$ = NULL; }
   14134                 :             :         ;
   14135                 :             : 
   14136                 :             : /*
   14137                 :             :  * func_alias_clause can include both an Alias and a coldeflist, so we make it
   14138                 :             :  * return a 2-element list that gets disassembled by calling production.
   14139                 :             :  */
   14140                 :             : func_alias_clause:
   14141                 :             :             alias_clause
   14142                 :             :                 {
   14143                 :       17860 :                     $$ = list_make2($1, NIL);
   14144                 :             :                 }
   14145                 :             :             | AS '(' TableFuncElementList ')'
   14146                 :             :                 {
   14147                 :          70 :                     $$ = list_make2(NULL, $3);
   14148                 :             :                 }
   14149                 :             :             | AS ColId '(' TableFuncElementList ')'
   14150                 :             :                 {
   14151                 :         361 :                     Alias      *a = makeNode(Alias);
   14152                 :             : 
   14153                 :         361 :                     a->aliasname = $2;
   14154                 :         361 :                     $$ = list_make2(a, $4);
   14155                 :             :                 }
   14156                 :             :             | ColId '(' TableFuncElementList ')'
   14157                 :             :                 {
   14158                 :          33 :                     Alias      *a = makeNode(Alias);
   14159                 :             : 
   14160                 :          33 :                     a->aliasname = $1;
   14161                 :          33 :                     $$ = list_make2(a, $3);
   14162                 :             :                 }
   14163                 :             :             | /*EMPTY*/
   14164                 :             :                 {
   14165                 :       11572 :                     $$ = list_make2(NULL, NIL);
   14166                 :             :                 }
   14167                 :             :         ;
   14168                 :             : 
   14169                 :         775 : join_type:  FULL opt_outer                          { $$ = JOIN_FULL; }
   14170                 :       26359 :             | LEFT opt_outer                        { $$ = JOIN_LEFT; }
   14171                 :         280 :             | RIGHT opt_outer                       { $$ = JOIN_RIGHT; }
   14172                 :        2405 :             | INNER_P                               { $$ = JOIN_INNER; }
   14173                 :             :         ;
   14174                 :             : 
   14175                 :             : /* OUTER is just noise... */
   14176                 :             : opt_outer: OUTER_P
   14177                 :             :             | /*EMPTY*/
   14178                 :             :         ;
   14179                 :             : 
   14180                 :             : /* JOIN qualification clauses
   14181                 :             :  * Possibilities are:
   14182                 :             :  *  USING ( column list ) [ AS alias ]
   14183                 :             :  *                        allows only unqualified column names,
   14184                 :             :  *                        which must match between tables.
   14185                 :             :  *  ON expr allows more general qualifications.
   14186                 :             :  *
   14187                 :             :  * We return USING as a two-element List (the first item being a sub-List
   14188                 :             :  * of the common column names, and the second either an Alias item or NULL).
   14189                 :             :  * An ON-expr will not be a List, so it can be told apart that way.
   14190                 :             :  */
   14191                 :             : 
   14192                 :             : join_qual: USING '(' name_list ')' opt_alias_clause_for_join_using
   14193                 :             :                 {
   14194                 :         873 :                     $$ = (Node *) list_make2($3, $5);
   14195                 :             :                 }
   14196                 :             :             | ON a_expr
   14197                 :             :                 {
   14198                 :       53496 :                     $$ = $2;
   14199                 :             :                 }
   14200                 :             :         ;
   14201                 :             : 
   14202                 :             : 
   14203                 :             : relation_expr:
   14204                 :             :             qualified_name
   14205                 :             :                 {
   14206                 :             :                     /* inheritance query, implicitly */
   14207                 :      312157 :                     $$ = $1;
   14208                 :      312157 :                     $$->inh = true;
   14209                 :      312157 :                     $$->alias = NULL;
   14210                 :             :                 }
   14211                 :             :             | extended_relation_expr
   14212                 :             :                 {
   14213                 :        3750 :                     $$ = $1;
   14214                 :             :                 }
   14215                 :             :         ;
   14216                 :             : 
   14217                 :             : extended_relation_expr:
   14218                 :             :             qualified_name '*'
   14219                 :             :                 {
   14220                 :             :                     /* inheritance query, explicitly */
   14221                 :         140 :                     $$ = $1;
   14222                 :         140 :                     $$->inh = true;
   14223                 :         140 :                     $$->alias = NULL;
   14224                 :             :                 }
   14225                 :             :             | ONLY qualified_name
   14226                 :             :                 {
   14227                 :             :                     /* no inheritance */
   14228                 :        3614 :                     $$ = $2;
   14229                 :        3614 :                     $$->inh = false;
   14230                 :        3614 :                     $$->alias = NULL;
   14231                 :             :                 }
   14232                 :             :             | ONLY '(' qualified_name ')'
   14233                 :             :                 {
   14234                 :             :                     /* no inheritance, SQL99-style syntax */
   14235                 :           0 :                     $$ = $3;
   14236                 :           0 :                     $$->inh = false;
   14237                 :           0 :                     $$->alias = NULL;
   14238                 :             :                 }
   14239                 :             :         ;
   14240                 :             : 
   14241                 :             : 
   14242                 :             : relation_expr_list:
   14243                 :        1793 :             relation_expr                           { $$ = list_make1($1); }
   14244                 :        5987 :             | relation_expr_list ',' relation_expr  { $$ = lappend($1, $3); }
   14245                 :             :         ;
   14246                 :             : 
   14247                 :             : 
   14248                 :             : /*
   14249                 :             :  * Given "UPDATE foo set set ...", we have to decide without looking any
   14250                 :             :  * further ahead whether the first "set" is an alias or the UPDATE's SET
   14251                 :             :  * keyword.  Since "set" is allowed as a column name both interpretations
   14252                 :             :  * are feasible.  We resolve the shift/reduce conflict by giving the first
   14253                 :             :  * relation_expr_opt_alias production a higher precedence than the SET token
   14254                 :             :  * has, causing the parser to prefer to reduce, in effect assuming that the
   14255                 :             :  * SET is not an alias.
   14256                 :             :  */
   14257                 :             : relation_expr_opt_alias: relation_expr                  %prec UMINUS
   14258                 :             :                 {
   14259                 :       11786 :                     $$ = $1;
   14260                 :             :                 }
   14261                 :             :             | relation_expr ColId
   14262                 :             :                 {
   14263                 :        1518 :                     Alias      *alias = makeNode(Alias);
   14264                 :             : 
   14265                 :        1518 :                     alias->aliasname = $2;
   14266                 :        1518 :                     $1->alias = alias;
   14267                 :        1518 :                     $$ = $1;
   14268                 :             :                 }
   14269                 :             :             | relation_expr AS ColId
   14270                 :             :                 {
   14271                 :          59 :                     Alias      *alias = makeNode(Alias);
   14272                 :             : 
   14273                 :          59 :                     alias->aliasname = $3;
   14274                 :          59 :                     $1->alias = alias;
   14275                 :          59 :                     $$ = $1;
   14276                 :             :                 }
   14277                 :             :         ;
   14278                 :             : 
   14279                 :             : /*
   14280                 :             :  * TABLESAMPLE decoration in a FROM item
   14281                 :             :  */
   14282                 :             : tablesample_clause:
   14283                 :             :             TABLESAMPLE func_name '(' expr_list ')' opt_repeatable_clause
   14284                 :             :                 {
   14285                 :         174 :                     RangeTableSample *n = makeNode(RangeTableSample);
   14286                 :             : 
   14287                 :             :                     /* n->relation will be filled in later */
   14288                 :         174 :                     n->method = $2;
   14289                 :         174 :                     n->args = $4;
   14290                 :         174 :                     n->repeatable = $6;
   14291                 :         174 :                     n->location = @2;
   14292                 :         174 :                     $$ = (Node *) n;
   14293                 :             :                 }
   14294                 :             :         ;
   14295                 :             : 
   14296                 :             : opt_repeatable_clause:
   14297                 :          71 :             REPEATABLE '(' a_expr ')'   { $$ = (Node *) $3; }
   14298                 :         103 :             | /*EMPTY*/                 { $$ = NULL; }
   14299                 :             :         ;
   14300                 :             : 
   14301                 :             : /*
   14302                 :             :  * func_table represents a function invocation in a FROM list. It can be
   14303                 :             :  * a plain function call, like "foo(...)", or a ROWS FROM expression with
   14304                 :             :  * one or more function calls, "ROWS FROM (foo(...), bar(...))",
   14305                 :             :  * optionally with WITH ORDINALITY attached.
   14306                 :             :  * In the ROWS FROM syntax, a column definition list can be given for each
   14307                 :             :  * function, for example:
   14308                 :             :  *     ROWS FROM (foo() AS (foo_res_a text, foo_res_b text),
   14309                 :             :  *                bar() AS (bar_res_a text, bar_res_b text))
   14310                 :             :  * It's also possible to attach a column definition list to the RangeFunction
   14311                 :             :  * as a whole, but that's handled by the table_ref production.
   14312                 :             :  */
   14313                 :             : func_table: func_expr_windowless opt_ordinality
   14314                 :             :                 {
   14315                 :       29802 :                     RangeFunction *n = makeNode(RangeFunction);
   14316                 :             : 
   14317                 :       29802 :                     n->lateral = false;
   14318                 :       29802 :                     n->ordinality = $2;
   14319                 :       29802 :                     n->is_rowsfrom = false;
   14320                 :       29802 :                     n->functions = list_make1(list_make2($1, NIL));
   14321                 :             :                     /* alias and coldeflist are set by table_ref production */
   14322                 :       29802 :                     $$ = (Node *) n;
   14323                 :             :                 }
   14324                 :             :             | ROWS FROM '(' rowsfrom_list ')' opt_ordinality
   14325                 :             :                 {
   14326                 :          98 :                     RangeFunction *n = makeNode(RangeFunction);
   14327                 :             : 
   14328                 :          98 :                     n->lateral = false;
   14329                 :          98 :                     n->ordinality = $6;
   14330                 :          98 :                     n->is_rowsfrom = true;
   14331                 :          98 :                     n->functions = $4;
   14332                 :             :                     /* alias and coldeflist are set by table_ref production */
   14333                 :          98 :                     $$ = (Node *) n;
   14334                 :             :                 }
   14335                 :             :         ;
   14336                 :             : 
   14337                 :             : rowsfrom_item: func_expr_windowless opt_col_def_list
   14338                 :         232 :                 { $$ = list_make2($1, $2); }
   14339                 :             :         ;
   14340                 :             : 
   14341                 :             : rowsfrom_list:
   14342                 :          98 :             rowsfrom_item                       { $$ = list_make1($1); }
   14343                 :         134 :             | rowsfrom_list ',' rowsfrom_item   { $$ = lappend($1, $3); }
   14344                 :             :         ;
   14345                 :             : 
   14346                 :          36 : opt_col_def_list: AS '(' TableFuncElementList ')'   { $$ = $3; }
   14347                 :         196 :             | /*EMPTY*/                             { $$ = NIL; }
   14348                 :             :         ;
   14349                 :             : 
   14350                 :         607 : opt_ordinality: WITH_LA ORDINALITY                  { $$ = true; }
   14351                 :       29293 :             | /*EMPTY*/                             { $$ = false; }
   14352                 :             :         ;
   14353                 :             : 
   14354                 :             : 
   14355                 :             : where_clause:
   14356                 :      141323 :             WHERE a_expr                            { $$ = $2; }
   14357                 :      185782 :             | /*EMPTY*/                             { $$ = NULL; }
   14358                 :             :         ;
   14359                 :             : 
   14360                 :             : /* variant for UPDATE and DELETE */
   14361                 :             : where_or_current_clause:
   14362                 :        8446 :             WHERE a_expr                            { $$ = $2; }
   14363                 :             :             | WHERE CURRENT_P OF cursor_name
   14364                 :             :                 {
   14365                 :         188 :                     CurrentOfExpr *n = makeNode(CurrentOfExpr);
   14366                 :             : 
   14367                 :             :                     /* cvarno is filled in by parse analysis */
   14368                 :         188 :                     n->cursor_name = $4;
   14369                 :         188 :                     n->cursor_param = 0;
   14370                 :         188 :                     $$ = (Node *) n;
   14371                 :             :                 }
   14372                 :        3257 :             | /*EMPTY*/                             { $$ = NULL; }
   14373                 :             :         ;
   14374                 :             : 
   14375                 :             : 
   14376                 :             : OptTableFuncElementList:
   14377                 :         493 :             TableFuncElementList                { $$ = $1; }
   14378                 :        1894 :             | /*EMPTY*/                         { $$ = NIL; }
   14379                 :             :         ;
   14380                 :             : 
   14381                 :             : TableFuncElementList:
   14382                 :             :             TableFuncElement
   14383                 :             :                 {
   14384                 :         993 :                     $$ = list_make1($1);
   14385                 :             :                 }
   14386                 :             :             | TableFuncElementList ',' TableFuncElement
   14387                 :             :                 {
   14388                 :        1280 :                     $$ = lappend($1, $3);
   14389                 :             :                 }
   14390                 :             :         ;
   14391                 :             : 
   14392                 :             : TableFuncElement:   ColId Typename opt_collate_clause
   14393                 :             :                 {
   14394                 :        2319 :                     ColumnDef *n = makeNode(ColumnDef);
   14395                 :             : 
   14396                 :        2319 :                     n->colname = $1;
   14397                 :        2319 :                     n->typeName = $2;
   14398                 :        2319 :                     n->inhcount = 0;
   14399                 :        2319 :                     n->is_local = true;
   14400                 :        2319 :                     n->is_not_null = false;
   14401                 :        2319 :                     n->is_from_type = false;
   14402                 :        2319 :                     n->storage = 0;
   14403                 :        2319 :                     n->raw_default = NULL;
   14404                 :        2319 :                     n->cooked_default = NULL;
   14405                 :        2319 :                     n->collClause = (CollateClause *) $3;
   14406                 :        2319 :                     n->collOid = InvalidOid;
   14407                 :        2319 :                     n->constraints = NIL;
   14408                 :        2319 :                     n->location = @1;
   14409                 :        2319 :                     $$ = (Node *) n;
   14410                 :             :                 }
   14411                 :             :         ;
   14412                 :             : 
   14413                 :             : /*
   14414                 :             :  * XMLTABLE
   14415                 :             :  */
   14416                 :             : xmltable:
   14417                 :             :             XMLTABLE '(' c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14418                 :             :                 {
   14419                 :         137 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14420                 :             : 
   14421                 :         137 :                     n->rowexpr = $3;
   14422                 :         137 :                     n->docexpr = $4;
   14423                 :         137 :                     n->columns = $6;
   14424                 :         137 :                     n->namespaces = NIL;
   14425                 :         137 :                     n->location = @1;
   14426                 :         137 :                     $$ = (Node *) n;
   14427                 :             :                 }
   14428                 :             :             | XMLTABLE '(' XMLNAMESPACES '(' xml_namespace_list ')' ','
   14429                 :             :                 c_expr xmlexists_argument COLUMNS xmltable_column_list ')'
   14430                 :             :                 {
   14431                 :          13 :                     RangeTableFunc *n = makeNode(RangeTableFunc);
   14432                 :             : 
   14433                 :          13 :                     n->rowexpr = $8;
   14434                 :          13 :                     n->docexpr = $9;
   14435                 :          13 :                     n->columns = $11;
   14436                 :          13 :                     n->namespaces = $5;
   14437                 :          13 :                     n->location = @1;
   14438                 :          13 :                     $$ = (Node *) n;
   14439                 :             :                 }
   14440                 :             :         ;
   14441                 :             : 
   14442                 :         150 : xmltable_column_list: xmltable_column_el                    { $$ = list_make1($1); }
   14443                 :         351 :             | xmltable_column_list ',' xmltable_column_el   { $$ = lappend($1, $3); }
   14444                 :             :         ;
   14445                 :             : 
   14446                 :             : xmltable_column_el:
   14447                 :             :             ColId Typename
   14448                 :             :                 {
   14449                 :         136 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14450                 :             : 
   14451                 :         136 :                     fc->colname = $1;
   14452                 :         136 :                     fc->for_ordinality = false;
   14453                 :         136 :                     fc->typeName = $2;
   14454                 :         136 :                     fc->is_not_null = false;
   14455                 :         136 :                     fc->colexpr = NULL;
   14456                 :         136 :                     fc->coldefexpr = NULL;
   14457                 :         136 :                     fc->location = @1;
   14458                 :             : 
   14459                 :         136 :                     $$ = (Node *) fc;
   14460                 :             :                 }
   14461                 :             :             | ColId Typename xmltable_column_option_list
   14462                 :             :                 {
   14463                 :         324 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14464                 :             :                     ListCell   *option;
   14465                 :         324 :                     bool        nullability_seen = false;
   14466                 :             : 
   14467                 :         324 :                     fc->colname = $1;
   14468                 :         324 :                     fc->typeName = $2;
   14469                 :         324 :                     fc->for_ordinality = false;
   14470                 :         324 :                     fc->is_not_null = false;
   14471                 :         324 :                     fc->colexpr = NULL;
   14472                 :         324 :                     fc->coldefexpr = NULL;
   14473                 :         324 :                     fc->location = @1;
   14474                 :             : 
   14475   [ +  -  +  +  :         722 :                     foreach(option, $3)
                   +  + ]
   14476                 :             :                     {
   14477                 :         398 :                         DefElem   *defel = (DefElem *) lfirst(option);
   14478                 :             : 
   14479         [ +  + ]:         398 :                         if (strcmp(defel->defname, "default") == 0)
   14480                 :             :                         {
   14481         [ -  + ]:          37 :                             if (fc->coldefexpr != NULL)
   14482         [ #  # ]:           0 :                                 ereport(ERROR,
   14483                 :             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14484                 :             :                                          errmsg("only one DEFAULT value is allowed"),
   14485                 :             :                                          parser_errposition(defel->location)));
   14486                 :          37 :                             fc->coldefexpr = defel->arg;
   14487                 :             :                         }
   14488         [ +  + ]:         361 :                         else if (strcmp(defel->defname, "path") == 0)
   14489                 :             :                         {
   14490         [ -  + ]:         324 :                             if (fc->colexpr != NULL)
   14491         [ #  # ]:           0 :                                 ereport(ERROR,
   14492                 :             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14493                 :             :                                          errmsg("only one PATH value per column is allowed"),
   14494                 :             :                                          parser_errposition(defel->location)));
   14495                 :         324 :                             fc->colexpr = defel->arg;
   14496                 :             :                         }
   14497         [ +  - ]:          37 :                         else if (strcmp(defel->defname, "__pg__is_not_null") == 0)
   14498                 :             :                         {
   14499         [ -  + ]:          37 :                             if (nullability_seen)
   14500         [ #  # ]:           0 :                                 ereport(ERROR,
   14501                 :             :                                         (errcode(ERRCODE_SYNTAX_ERROR),
   14502                 :             :                                          errmsg("conflicting or redundant NULL / NOT NULL declarations for column \"%s\"", fc->colname),
   14503                 :             :                                          parser_errposition(defel->location)));
   14504                 :          37 :                             fc->is_not_null = boolVal(defel->arg);
   14505                 :          37 :                             nullability_seen = true;
   14506                 :             :                         }
   14507                 :             :                         else
   14508                 :             :                         {
   14509         [ #  # ]:           0 :                             ereport(ERROR,
   14510                 :             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   14511                 :             :                                      errmsg("unrecognized column option \"%s\"",
   14512                 :             :                                             defel->defname),
   14513                 :             :                                      parser_errposition(defel->location)));
   14514                 :             :                         }
   14515                 :             :                     }
   14516                 :         324 :                     $$ = (Node *) fc;
   14517                 :             :                 }
   14518                 :             :             | ColId FOR ORDINALITY
   14519                 :             :                 {
   14520                 :          41 :                     RangeTableFuncCol *fc = makeNode(RangeTableFuncCol);
   14521                 :             : 
   14522                 :          41 :                     fc->colname = $1;
   14523                 :          41 :                     fc->for_ordinality = true;
   14524                 :             :                     /* other fields are ignored, initialized by makeNode */
   14525                 :          41 :                     fc->location = @1;
   14526                 :             : 
   14527                 :          41 :                     $$ = (Node *) fc;
   14528                 :             :                 }
   14529                 :             :         ;
   14530                 :             : 
   14531                 :             : xmltable_column_option_list:
   14532                 :             :             xmltable_column_option_el
   14533                 :         324 :                 { $$ = list_make1($1); }
   14534                 :             :             | xmltable_column_option_list xmltable_column_option_el
   14535                 :          74 :                 { $$ = lappend($1, $2); }
   14536                 :             :         ;
   14537                 :             : 
   14538                 :             : xmltable_column_option_el:
   14539                 :             :             IDENT b_expr
   14540                 :             :                 {
   14541         [ +  - ]:           4 :                     if (strcmp($1, "__pg__is_not_null") == 0)
   14542         [ +  - ]:           4 :                         ereport(ERROR,
   14543                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   14544                 :             :                                  errmsg("option name \"%s\" cannot be used in XMLTABLE", $1),
   14545                 :             :                                  parser_errposition(@1)));
   14546                 :           0 :                     $$ = makeDefElem($1, $2, @1);
   14547                 :             :                 }
   14548                 :             :             | DEFAULT b_expr
   14549                 :          37 :                 { $$ = makeDefElem("default", $2, @1); }
   14550                 :             :             | NOT NULL_P
   14551                 :          37 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(true), @1); }
   14552                 :             :             | NULL_P
   14553                 :           0 :                 { $$ = makeDefElem("__pg__is_not_null", (Node *) makeBoolean(false), @1); }
   14554                 :             :             | PATH b_expr
   14555                 :         324 :                 { $$ = makeDefElem("path", $2, @1); }
   14556                 :             :         ;
   14557                 :             : 
   14558                 :             : xml_namespace_list:
   14559                 :             :             xml_namespace_el
   14560                 :          13 :                 { $$ = list_make1($1); }
   14561                 :             :             | xml_namespace_list ',' xml_namespace_el
   14562                 :           0 :                 { $$ = lappend($1, $3); }
   14563                 :             :         ;
   14564                 :             : 
   14565                 :             : xml_namespace_el:
   14566                 :             :             b_expr AS ColLabel
   14567                 :             :                 {
   14568                 :           9 :                     $$ = makeNode(ResTarget);
   14569                 :           9 :                     $$->name = $3;
   14570                 :           9 :                     $$->indirection = NIL;
   14571                 :           9 :                     $$->val = $1;
   14572                 :           9 :                     $$->location = @1;
   14573                 :             :                 }
   14574                 :             :             | DEFAULT b_expr
   14575                 :             :                 {
   14576                 :           4 :                     $$ = makeNode(ResTarget);
   14577                 :           4 :                     $$->name = NULL;
   14578                 :           4 :                     $$->indirection = NIL;
   14579                 :           4 :                     $$->val = $2;
   14580                 :           4 :                     $$->location = @1;
   14581                 :             :                 }
   14582                 :             :         ;
   14583                 :             : 
   14584                 :             : json_table:
   14585                 :             :             JSON_TABLE '('
   14586                 :             :                 json_value_expr ',' a_expr json_table_path_name_opt
   14587                 :             :                 json_passing_clause_opt
   14588                 :             :                 COLUMNS '(' json_table_column_definition_list ')'
   14589                 :             :                 json_table_plan_clause_opt
   14590                 :             :                 json_on_error_clause_opt
   14591                 :             :             ')'
   14592                 :             :                 {
   14593                 :         488 :                     JsonTable *n = makeNode(JsonTable);
   14594                 :             :                     char      *pathstring;
   14595                 :             : 
   14596                 :         488 :                     n->context_item = (JsonValueExpr *) $3;
   14597         [ +  + ]:         488 :                     if (!IsA($5, A_Const) ||
   14598         [ -  + ]:         484 :                         castNode(A_Const, $5)->val.node.type != T_String)
   14599         [ +  - ]:           4 :                         ereport(ERROR,
   14600                 :             :                                 errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   14601                 :             :                                 errmsg("only string constants are supported in"
   14602                 :             :                                        " JSON_TABLE path specification"),
   14603                 :             :                                 parser_errposition(@5));
   14604                 :         484 :                     pathstring = castNode(A_Const, $5)->val.sval.sval;
   14605                 :         484 :                     n->pathspec = makeJsonTablePathSpec(pathstring, $6, @5, @6);
   14606                 :         484 :                     n->passing = $7;
   14607                 :         484 :                     n->columns = $10;
   14608                 :         484 :                     n->planspec = (JsonTablePlanSpec *) $12;
   14609                 :         484 :                     n->on_error = (JsonBehavior *) $13;
   14610                 :         484 :                     n->location = @1;
   14611                 :         484 :                     $$ = (Node *) n;
   14612                 :             :                 }
   14613                 :             :         ;
   14614                 :             : 
   14615                 :             : json_table_path_name_opt:
   14616                 :         144 :             AS name         { $$ = $2; }
   14617                 :         352 :             | /* empty */   { $$ = NULL; }
   14618                 :             :         ;
   14619                 :             : 
   14620                 :             : json_table_column_definition_list:
   14621                 :             :             json_table_column_definition
   14622                 :        1032 :                 { $$ = list_make1($1); }
   14623                 :             :             | json_table_column_definition_list ',' json_table_column_definition
   14624                 :         688 :                 { $$ = lappend($1, $3); }
   14625                 :             :         ;
   14626                 :             : 
   14627                 :             : json_table_column_definition:
   14628                 :             :             ColId FOR ORDINALITY
   14629                 :             :                 {
   14630                 :         100 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14631                 :             : 
   14632                 :         100 :                     n->coltype = JTC_FOR_ORDINALITY;
   14633                 :         100 :                     n->name = $1;
   14634                 :         100 :                     n->location = @1;
   14635                 :         100 :                     $$ = (Node *) n;
   14636                 :             :                 }
   14637                 :             :             | ColId Typename
   14638                 :             :                 json_table_column_path_clause_opt
   14639                 :             :                 json_wrapper_behavior
   14640                 :             :                 json_quotes_clause_opt
   14641                 :             :                 json_behavior_clause_opt
   14642                 :             :                 {
   14643                 :         880 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14644                 :             : 
   14645                 :         880 :                     n->coltype = JTC_REGULAR;
   14646                 :         880 :                     n->name = $1;
   14647                 :         880 :                     n->typeName = $2;
   14648                 :         880 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14649                 :         880 :                     n->pathspec = (JsonTablePathSpec *) $3;
   14650                 :         880 :                     n->wrapper = $4;
   14651                 :         880 :                     n->quotes = $5;
   14652                 :         880 :                     n->on_empty = (JsonBehavior *) linitial($6);
   14653                 :         880 :                     n->on_error = (JsonBehavior *) lsecond($6);
   14654                 :         880 :                     n->location = @1;
   14655                 :         880 :                     $$ = (Node *) n;
   14656                 :             :                 }
   14657                 :             :             | ColId Typename json_format_clause
   14658                 :             :                 json_table_column_path_clause_opt
   14659                 :             :                 json_wrapper_behavior
   14660                 :             :                 json_quotes_clause_opt
   14661                 :             :                 json_behavior_clause_opt
   14662                 :             :                 {
   14663                 :          92 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14664                 :             : 
   14665                 :          92 :                     n->coltype = JTC_FORMATTED;
   14666                 :          92 :                     n->name = $1;
   14667                 :          92 :                     n->typeName = $2;
   14668                 :          92 :                     n->format = (JsonFormat *) $3;
   14669                 :          92 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14670                 :          92 :                     n->wrapper = $5;
   14671                 :          92 :                     n->quotes = $6;
   14672                 :          92 :                     n->on_empty = (JsonBehavior *) linitial($7);
   14673                 :          92 :                     n->on_error = (JsonBehavior *) lsecond($7);
   14674                 :          92 :                     n->location = @1;
   14675                 :          92 :                     $$ = (Node *) n;
   14676                 :             :                 }
   14677                 :             :             | ColId Typename
   14678                 :             :                 EXISTS json_table_column_path_clause_opt
   14679                 :             :                 json_on_error_clause_opt
   14680                 :             :                 {
   14681                 :         104 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14682                 :             : 
   14683                 :         104 :                     n->coltype = JTC_EXISTS;
   14684                 :         104 :                     n->name = $1;
   14685                 :         104 :                     n->typeName = $2;
   14686                 :         104 :                     n->format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   14687                 :         104 :                     n->wrapper = JSW_NONE;
   14688                 :         104 :                     n->quotes = JS_QUOTES_UNSPEC;
   14689                 :         104 :                     n->pathspec = (JsonTablePathSpec *) $4;
   14690                 :         104 :                     n->on_empty = NULL;
   14691                 :         104 :                     n->on_error = (JsonBehavior *) $5;
   14692                 :         104 :                     n->location = @1;
   14693                 :         104 :                     $$ = (Node *) n;
   14694                 :             :                 }
   14695                 :             :             | NESTED path_opt Sconst
   14696                 :             :                 COLUMNS '(' json_table_column_definition_list ')'
   14697                 :             :                 {
   14698                 :         108 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14699                 :             : 
   14700                 :         108 :                     n->coltype = JTC_NESTED;
   14701                 :         108 :                     n->pathspec = makeJsonTablePathSpec($3, NULL, @3, -1);
   14702                 :         108 :                     n->columns = $6;
   14703                 :         108 :                     n->location = @1;
   14704                 :         108 :                     $$ = (Node *) n;
   14705                 :             :                 }
   14706                 :             :             | NESTED path_opt Sconst AS name
   14707                 :             :                 COLUMNS '(' json_table_column_definition_list ')'
   14708                 :             :                 {
   14709                 :         436 :                     JsonTableColumn *n = makeNode(JsonTableColumn);
   14710                 :             : 
   14711                 :         436 :                     n->coltype = JTC_NESTED;
   14712                 :         436 :                     n->pathspec = makeJsonTablePathSpec($3, $5, @3, @5);
   14713                 :         436 :                     n->columns = $8;
   14714                 :         436 :                     n->location = @1;
   14715                 :         436 :                     $$ = (Node *) n;
   14716                 :             :                 }
   14717                 :             :         ;
   14718                 :             : 
   14719                 :             : path_opt:
   14720                 :             :             PATH
   14721                 :             :             | /* EMPTY */
   14722                 :             :         ;
   14723                 :             : 
   14724                 :             : json_table_column_path_clause_opt:
   14725                 :             :             PATH Sconst
   14726                 :         844 :                 { $$ = (Node *) makeJsonTablePathSpec($2, NULL, @2, -1); }
   14727                 :             :             | /* EMPTY */
   14728                 :         236 :                 { $$ = NULL; }
   14729                 :             :         ;
   14730                 :             : 
   14731                 :             : json_table_plan_clause_opt:
   14732                 :             :             PLAN '(' json_table_plan ')'
   14733                 :          84 :                 { $$ = $3; }
   14734                 :             :             | PLAN DEFAULT '(' json_table_default_plan_choices ')'
   14735                 :          24 :                 { $$ = makeJsonTableDefaultPlan($4, @1); }
   14736                 :             :             | /* EMPTY */
   14737                 :         380 :                 { $$ = NULL; }
   14738                 :             :         ;
   14739                 :             : 
   14740                 :             : json_table_plan:
   14741                 :             :             json_table_plan_simple
   14742                 :             :             | json_table_plan_outer
   14743                 :             :             | json_table_plan_inner
   14744                 :             :             | json_table_plan_union
   14745                 :             :             | json_table_plan_cross
   14746                 :             :         ;
   14747                 :             : 
   14748                 :             : json_table_plan_simple:
   14749                 :             :             name
   14750                 :         276 :                 { $$ = makeJsonTableSimplePlan($1, @1); }
   14751                 :             :         ;
   14752                 :             : 
   14753                 :             : json_table_plan_outer:
   14754                 :             :             json_table_plan_simple OUTER_P json_table_plan_primary
   14755                 :          68 :                 { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_OUTER, $1, $3, @1); }
   14756                 :             :         ;
   14757                 :             : 
   14758                 :             : json_table_plan_inner:
   14759                 :             :             json_table_plan_simple INNER_P json_table_plan_primary
   14760                 :          40 :                 { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_INNER, $1, $3, @1); }
   14761                 :             :         ;
   14762                 :             : 
   14763                 :             : json_table_plan_union:
   14764                 :             :             json_table_plan_primary UNION json_table_plan_primary
   14765                 :          28 :                 { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_UNION, $1, $3, @1); }
   14766                 :             :             | json_table_plan_union UNION json_table_plan_primary
   14767                 :           4 :                 { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_UNION, $1, $3, @1); }
   14768                 :             :         ;
   14769                 :             : 
   14770                 :             : json_table_plan_cross:
   14771                 :             :             json_table_plan_primary CROSS json_table_plan_primary
   14772                 :          52 :                 { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_CROSS, $1, $3, @1); }
   14773                 :             :             | json_table_plan_cross CROSS json_table_plan_primary
   14774                 :           0 :                 { $$ = makeJsonTableJoinedPlan(JSTP_JOIN_CROSS, $1, $3, @1); }
   14775                 :             :         ;
   14776                 :             : 
   14777                 :             : json_table_plan_primary:
   14778                 :             :             json_table_plan_simple
   14779                 :         156 :                 { $$ = $1; }
   14780                 :             :             | '(' json_table_plan ')'
   14781                 :             :                 {
   14782                 :         116 :                     castNode(JsonTablePlanSpec, $2)->location = @1;
   14783                 :         116 :                     $$ = $2;
   14784                 :             :                 }
   14785                 :             :         ;
   14786                 :             : 
   14787                 :             : json_table_default_plan_choices:
   14788                 :             :             json_table_default_plan_inner_outer
   14789                 :           4 :                 { $$ = $1 | JSTP_JOIN_UNION; }
   14790                 :             :             | json_table_default_plan_union_cross
   14791                 :           8 :                 { $$ = $1 | JSTP_JOIN_OUTER; }
   14792                 :             :             | json_table_default_plan_inner_outer ',' json_table_default_plan_union_cross
   14793                 :           8 :                 { $$ = $1 | $3; }
   14794                 :             :             | json_table_default_plan_union_cross ',' json_table_default_plan_inner_outer
   14795                 :           4 :                 { $$ = $1 | $3; }
   14796                 :             :         ;
   14797                 :             : 
   14798                 :             : json_table_default_plan_inner_outer:
   14799                 :           8 :             INNER_P                     { $$ = JSTP_JOIN_INNER; }
   14800                 :           8 :             | OUTER_P                   { $$ = JSTP_JOIN_OUTER; }
   14801                 :             :         ;
   14802                 :             : 
   14803                 :             : json_table_default_plan_union_cross:
   14804                 :          12 :             UNION                       { $$ = JSTP_JOIN_UNION; }
   14805                 :           8 :             | CROSS                     { $$ = JSTP_JOIN_CROSS; }
   14806                 :             :         ;
   14807                 :             : 
   14808                 :             : /*****************************************************************************
   14809                 :             :  *
   14810                 :             :  *  Type syntax
   14811                 :             :  *      SQL introduces a large amount of type-specific syntax.
   14812                 :             :  *      Define individual clauses to handle these cases, and use
   14813                 :             :  *       the generic case to handle regular type-extensible Postgres syntax.
   14814                 :             :  *      - thomas 1997-10-10
   14815                 :             :  *
   14816                 :             :  *****************************************************************************/
   14817                 :             : 
   14818                 :             : Typename:   SimpleTypename opt_array_bounds
   14819                 :             :                 {
   14820                 :      305494 :                     $$ = $1;
   14821                 :      305494 :                     $$->arrayBounds = $2;
   14822                 :             :                 }
   14823                 :             :             | SETOF SimpleTypename opt_array_bounds
   14824                 :             :                 {
   14825                 :        1101 :                     $$ = $2;
   14826                 :        1101 :                     $$->arrayBounds = $3;
   14827                 :        1101 :                     $$->setof = true;
   14828                 :             :                 }
   14829                 :             :             /* SQL standard syntax, currently only one-dimensional */
   14830                 :             :             | SimpleTypename ARRAY '[' Iconst ']'
   14831                 :             :                 {
   14832                 :           4 :                     $$ = $1;
   14833                 :           4 :                     $$->arrayBounds = list_make1(makeInteger($4));
   14834                 :             :                 }
   14835                 :             :             | SETOF SimpleTypename ARRAY '[' Iconst ']'
   14836                 :             :                 {
   14837                 :           0 :                     $$ = $2;
   14838                 :           0 :                     $$->arrayBounds = list_make1(makeInteger($5));
   14839                 :           0 :                     $$->setof = true;
   14840                 :             :                 }
   14841                 :             :             | SimpleTypename ARRAY
   14842                 :             :                 {
   14843                 :           0 :                     $$ = $1;
   14844                 :           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14845                 :             :                 }
   14846                 :             :             | SETOF SimpleTypename ARRAY
   14847                 :             :                 {
   14848                 :           0 :                     $$ = $2;
   14849                 :           0 :                     $$->arrayBounds = list_make1(makeInteger(-1));
   14850                 :           0 :                     $$->setof = true;
   14851                 :             :                 }
   14852                 :             :         ;
   14853                 :             : 
   14854                 :             : opt_array_bounds:
   14855                 :             :             opt_array_bounds '[' ']'
   14856                 :        8568 :                     {  $$ = lappend($1, makeInteger(-1)); }
   14857                 :             :             | opt_array_bounds '[' Iconst ']'
   14858                 :          38 :                     {  $$ = lappend($1, makeInteger($3)); }
   14859                 :             :             | /*EMPTY*/
   14860                 :      306595 :                     {  $$ = NIL; }
   14861                 :             :         ;
   14862                 :             : 
   14863                 :             : SimpleTypename:
   14864                 :      239573 :             GenericType                             { $$ = $1; }
   14865                 :       57482 :             | Numeric                               { $$ = $1; }
   14866                 :        1285 :             | Bit                                   { $$ = $1; }
   14867                 :        1930 :             | Character                             { $$ = $1; }
   14868                 :        3099 :             | ConstDatetime                         { $$ = $1; }
   14869                 :             :             | ConstInterval opt_interval
   14870                 :             :                 {
   14871                 :        2308 :                     $$ = $1;
   14872                 :        2308 :                     $$->typmods = $2;
   14873                 :             :                 }
   14874                 :             :             | ConstInterval '(' Iconst ')'
   14875                 :             :                 {
   14876                 :           0 :                     $$ = $1;
   14877                 :           0 :                     $$->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   14878                 :             :                                              makeIntConst($3, @3));
   14879                 :             :                 }
   14880                 :        1185 :             | JsonType                              { $$ = $1; }
   14881                 :             :         ;
   14882                 :             : 
   14883                 :             : /* We have a separate ConstTypename to allow defaulting fixed-length
   14884                 :             :  * types such as CHAR() and BIT() to an unspecified length.
   14885                 :             :  * SQL9x requires that these default to a length of one, but this
   14886                 :             :  * makes no sense for constructs like CHAR 'hi' and BIT '0101',
   14887                 :             :  * where there is an obvious better choice to make.
   14888                 :             :  * Note that ConstInterval is not included here since it must
   14889                 :             :  * be pushed up higher in the rules to accommodate the postfix
   14890                 :             :  * options (e.g. INTERVAL '1' YEAR). Likewise, we have to handle
   14891                 :             :  * the generic-type-name case in AexprConst to avoid premature
   14892                 :             :  * reduce/reduce conflicts against function names.
   14893                 :             :  */
   14894                 :             : ConstTypename:
   14895                 :          53 :             Numeric                                 { $$ = $1; }
   14896                 :           0 :             | ConstBit                              { $$ = $1; }
   14897                 :          22 :             | ConstCharacter                        { $$ = $1; }
   14898                 :        1793 :             | ConstDatetime                         { $$ = $1; }
   14899                 :         176 :             | JsonType                              { $$ = $1; }
   14900                 :             :         ;
   14901                 :             : 
   14902                 :             : /*
   14903                 :             :  * GenericType covers all type names that don't have special syntax mandated
   14904                 :             :  * by the standard, including qualified names.  We also allow type modifiers.
   14905                 :             :  * To avoid parsing conflicts against function invocations, the modifiers
   14906                 :             :  * have to be shown as expr_list here, but parse analysis will only accept
   14907                 :             :  * constants for them.
   14908                 :             :  */
   14909                 :             : GenericType:
   14910                 :             :             type_function_name opt_type_modifiers
   14911                 :             :                 {
   14912                 :      170297 :                     $$ = makeTypeName($1);
   14913                 :      170297 :                     $$->typmods = $2;
   14914                 :      170297 :                     $$->location = @1;
   14915                 :             :                 }
   14916                 :             :             | type_function_name attrs opt_type_modifiers
   14917                 :             :                 {
   14918                 :       69276 :                     $$ = makeTypeNameFromNameList(lcons(makeString($1), $2));
   14919                 :       69276 :                     $$->typmods = $3;
   14920                 :       69276 :                     $$->location = @1;
   14921                 :             :                 }
   14922                 :             :         ;
   14923                 :             : 
   14924                 :         820 : opt_type_modifiers: '(' expr_list ')'               { $$ = $2; }
   14925                 :      242666 :                     | /* EMPTY */                   { $$ = NIL; }
   14926                 :             :         ;
   14927                 :             : 
   14928                 :             : /*
   14929                 :             :  * SQL numeric data types
   14930                 :             :  */
   14931                 :             : Numeric:    INT_P
   14932                 :             :                 {
   14933                 :       26518 :                     $$ = SystemTypeName("int4");
   14934                 :       26518 :                     $$->location = @1;
   14935                 :             :                 }
   14936                 :             :             | INTEGER
   14937                 :             :                 {
   14938                 :       13979 :                     $$ = SystemTypeName("int4");
   14939                 :       13979 :                     $$->location = @1;
   14940                 :             :                 }
   14941                 :             :             | SMALLINT
   14942                 :             :                 {
   14943                 :         767 :                     $$ = SystemTypeName("int2");
   14944                 :         767 :                     $$->location = @1;
   14945                 :             :                 }
   14946                 :             :             | BIGINT
   14947                 :             :                 {
   14948                 :        2864 :                     $$ = SystemTypeName("int8");
   14949                 :        2864 :                     $$->location = @1;
   14950                 :             :                 }
   14951                 :             :             | REAL
   14952                 :             :                 {
   14953                 :        4091 :                     $$ = SystemTypeName("float4");
   14954                 :        4091 :                     $$->location = @1;
   14955                 :             :                 }
   14956                 :             :             | FLOAT_P opt_float
   14957                 :             :                 {
   14958                 :         346 :                     $$ = $2;
   14959                 :         346 :                     $$->location = @1;
   14960                 :             :                 }
   14961                 :             :             | DOUBLE_P PRECISION
   14962                 :             :                 {
   14963                 :         478 :                     $$ = SystemTypeName("float8");
   14964                 :         478 :                     $$->location = @1;
   14965                 :             :                 }
   14966                 :             :             | DECIMAL_P opt_type_modifiers
   14967                 :             :                 {
   14968                 :          20 :                     $$ = SystemTypeName("numeric");
   14969                 :          20 :                     $$->typmods = $2;
   14970                 :          20 :                     $$->location = @1;
   14971                 :             :                 }
   14972                 :             :             | DEC opt_type_modifiers
   14973                 :             :                 {
   14974                 :           0 :                     $$ = SystemTypeName("numeric");
   14975                 :           0 :                     $$->typmods = $2;
   14976                 :           0 :                     $$->location = @1;
   14977                 :             :                 }
   14978                 :             :             | NUMERIC opt_type_modifiers
   14979                 :             :                 {
   14980                 :        3893 :                     $$ = SystemTypeName("numeric");
   14981                 :        3893 :                     $$->typmods = $2;
   14982                 :        3893 :                     $$->location = @1;
   14983                 :             :                 }
   14984                 :             :             | BOOLEAN_P
   14985                 :             :                 {
   14986                 :        4579 :                     $$ = SystemTypeName("bool");
   14987                 :        4579 :                     $$->location = @1;
   14988                 :             :                 }
   14989                 :             :         ;
   14990                 :             : 
   14991                 :             : opt_float:  '(' Iconst ')'
   14992                 :             :                 {
   14993                 :             :                     /*
   14994                 :             :                      * Check FLOAT() precision limits assuming IEEE floating
   14995                 :             :                      * types - thomas 1997-09-18
   14996                 :             :                      */
   14997         [ -  + ]:           1 :                     if ($2 < 1)
   14998         [ #  # ]:           0 :                         ereport(ERROR,
   14999                 :             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   15000                 :             :                                  errmsg("precision for type float must be at least 1 bit"),
   15001                 :             :                                  parser_errposition(@2)));
   15002         [ +  - ]:           1 :                     else if ($2 <= 24)
   15003                 :           1 :                         $$ = SystemTypeName("float4");
   15004         [ #  # ]:           0 :                     else if ($2 <= 53)
   15005                 :           0 :                         $$ = SystemTypeName("float8");
   15006                 :             :                     else
   15007         [ #  # ]:           0 :                         ereport(ERROR,
   15008                 :             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   15009                 :             :                                  errmsg("precision for type float must be less than 54 bits"),
   15010                 :             :                                  parser_errposition(@2)));
   15011                 :             :                 }
   15012                 :             :             | /*EMPTY*/
   15013                 :             :                 {
   15014                 :         345 :                     $$ = SystemTypeName("float8");
   15015                 :             :                 }
   15016                 :             :         ;
   15017                 :             : 
   15018                 :             : /*
   15019                 :             :  * SQL bit-field data types
   15020                 :             :  * The following implements BIT() and BIT VARYING().
   15021                 :             :  */
   15022                 :             : Bit:        BitWithLength
   15023                 :             :                 {
   15024                 :        1154 :                     $$ = $1;
   15025                 :             :                 }
   15026                 :             :             | BitWithoutLength
   15027                 :             :                 {
   15028                 :         131 :                     $$ = $1;
   15029                 :             :                 }
   15030                 :             :         ;
   15031                 :             : 
   15032                 :             : /* ConstBit is like Bit except "BIT" defaults to unspecified length */
   15033                 :             : /* See notes for ConstCharacter, which addresses same issue for "CHAR" */
   15034                 :             : ConstBit:   BitWithLength
   15035                 :             :                 {
   15036                 :           0 :                     $$ = $1;
   15037                 :             :                 }
   15038                 :             :             | BitWithoutLength
   15039                 :             :                 {
   15040                 :           0 :                     $$ = $1;
   15041                 :           0 :                     $$->typmods = NIL;
   15042                 :             :                 }
   15043                 :             :         ;
   15044                 :             : 
   15045                 :             : BitWithLength:
   15046                 :             :             BIT opt_varying '(' expr_list ')'
   15047                 :             :                 {
   15048                 :             :                     char *typname;
   15049                 :             : 
   15050         [ +  + ]:        1154 :                     typname = $2 ? "varbit" : "bit";
   15051                 :        1154 :                     $$ = SystemTypeName(typname);
   15052                 :        1154 :                     $$->typmods = $4;
   15053                 :        1154 :                     $$->location = @1;
   15054                 :             :                 }
   15055                 :             :         ;
   15056                 :             : 
   15057                 :             : BitWithoutLength:
   15058                 :             :             BIT opt_varying
   15059                 :             :                 {
   15060                 :             :                     /* bit defaults to bit(1), varbit to no limit */
   15061         [ +  + ]:         131 :                     if ($2)
   15062                 :             :                     {
   15063                 :          10 :                         $$ = SystemTypeName("varbit");
   15064                 :             :                     }
   15065                 :             :                     else
   15066                 :             :                     {
   15067                 :         121 :                         $$ = SystemTypeName("bit");
   15068                 :         121 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   15069                 :             :                     }
   15070                 :         131 :                     $$->location = @1;
   15071                 :             :                 }
   15072                 :             :         ;
   15073                 :             : 
   15074                 :             : 
   15075                 :             : /*
   15076                 :             :  * SQL character data types
   15077                 :             :  * The following implements CHAR() and VARCHAR().
   15078                 :             :  */
   15079                 :             : Character:  CharacterWithLength
   15080                 :             :                 {
   15081                 :        1107 :                     $$ = $1;
   15082                 :             :                 }
   15083                 :             :             | CharacterWithoutLength
   15084                 :             :                 {
   15085                 :         823 :                     $$ = $1;
   15086                 :             :                 }
   15087                 :             :         ;
   15088                 :             : 
   15089                 :             : ConstCharacter:  CharacterWithLength
   15090                 :             :                 {
   15091                 :           8 :                     $$ = $1;
   15092                 :             :                 }
   15093                 :             :             | CharacterWithoutLength
   15094                 :             :                 {
   15095                 :             :                     /* Length was not specified so allow to be unrestricted.
   15096                 :             :                      * This handles problems with fixed-length (bpchar) strings
   15097                 :             :                      * which in column definitions must default to a length
   15098                 :             :                      * of one, but should not be constrained if the length
   15099                 :             :                      * was not specified.
   15100                 :             :                      */
   15101                 :          14 :                     $$ = $1;
   15102                 :          14 :                     $$->typmods = NIL;
   15103                 :             :                 }
   15104                 :             :         ;
   15105                 :             : 
   15106                 :             : CharacterWithLength:  character '(' Iconst ')'
   15107                 :             :                 {
   15108                 :        1115 :                     $$ = SystemTypeName($1);
   15109                 :        1115 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   15110                 :        1115 :                     $$->location = @1;
   15111                 :             :                 }
   15112                 :             :         ;
   15113                 :             : 
   15114                 :             : CharacterWithoutLength:  character
   15115                 :             :                 {
   15116                 :         837 :                     $$ = SystemTypeName($1);
   15117                 :             :                     /* char defaults to char(1), varchar to no limit */
   15118         [ +  + ]:         837 :                     if (strcmp($1, "bpchar") == 0)
   15119                 :         154 :                         $$->typmods = list_make1(makeIntConst(1, -1));
   15120                 :         837 :                     $$->location = @1;
   15121                 :             :                 }
   15122                 :             :         ;
   15123                 :             : 
   15124                 :             : character:  CHARACTER opt_varying
   15125         [ +  + ]:         326 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   15126                 :             :             | CHAR_P opt_varying
   15127         [ -  + ]:         745 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   15128                 :             :             | VARCHAR
   15129                 :         879 :                                         { $$ = "varchar"; }
   15130                 :             :             | NATIONAL CHARACTER opt_varying
   15131         [ #  # ]:           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   15132                 :             :             | NATIONAL CHAR_P opt_varying
   15133         [ #  # ]:           0 :                                         { $$ = $3 ? "varchar": "bpchar"; }
   15134                 :             :             | NCHAR opt_varying
   15135         [ -  + ]:           2 :                                         { $$ = $2 ? "varchar": "bpchar"; }
   15136                 :             :         ;
   15137                 :             : 
   15138                 :             : opt_varying:
   15139                 :         272 :             VARYING                                 { $$ = true; }
   15140                 :        2086 :             | /*EMPTY*/                             { $$ = false; }
   15141                 :             :         ;
   15142                 :             : 
   15143                 :             : /*
   15144                 :             :  * SQL date/time types
   15145                 :             :  */
   15146                 :             : ConstDatetime:
   15147                 :             :             TIMESTAMP '(' Iconst ')' opt_timezone
   15148                 :             :                 {
   15149         [ +  + ]:          81 :                     if ($5)
   15150                 :          66 :                         $$ = SystemTypeName("timestamptz");
   15151                 :             :                     else
   15152                 :          15 :                         $$ = SystemTypeName("timestamp");
   15153                 :          81 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   15154                 :          81 :                     $$->location = @1;
   15155                 :             :                 }
   15156                 :             :             | TIMESTAMP opt_timezone
   15157                 :             :                 {
   15158         [ +  + ]:        3240 :                     if ($2)
   15159                 :         774 :                         $$ = SystemTypeName("timestamptz");
   15160                 :             :                     else
   15161                 :        2466 :                         $$ = SystemTypeName("timestamp");
   15162                 :        3240 :                     $$->location = @1;
   15163                 :             :                 }
   15164                 :             :             | TIME '(' Iconst ')' opt_timezone
   15165                 :             :                 {
   15166         [ +  + ]:          14 :                     if ($5)
   15167                 :           5 :                         $$ = SystemTypeName("timetz");
   15168                 :             :                     else
   15169                 :           9 :                         $$ = SystemTypeName("time");
   15170                 :          14 :                     $$->typmods = list_make1(makeIntConst($3, @3));
   15171                 :          14 :                     $$->location = @1;
   15172                 :             :                 }
   15173                 :             :             | TIME opt_timezone
   15174                 :             :                 {
   15175         [ +  + ]:        1557 :                     if ($2)
   15176                 :         226 :                         $$ = SystemTypeName("timetz");
   15177                 :             :                     else
   15178                 :        1331 :                         $$ = SystemTypeName("time");
   15179                 :        1557 :                     $$->location = @1;
   15180                 :             :                 }
   15181                 :             :         ;
   15182                 :             : 
   15183                 :             : ConstInterval:
   15184                 :             :             INTERVAL
   15185                 :             :                 {
   15186                 :        4512 :                     $$ = SystemTypeName("interval");
   15187                 :        4512 :                     $$->location = @1;
   15188                 :             :                 }
   15189                 :             :         ;
   15190                 :             : 
   15191                 :             : opt_timezone:
   15192                 :        1071 :             WITH_LA TIME ZONE                       { $$ = true; }
   15193                 :         376 :             | WITHOUT_LA TIME ZONE                  { $$ = false; }
   15194                 :        3445 :             | /*EMPTY*/                             { $$ = false; }
   15195                 :             :         ;
   15196                 :             : 
   15197                 :             : opt_interval:
   15198                 :             :             YEAR_P
   15199                 :           8 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR), @1)); }
   15200                 :             :             | MONTH_P
   15201                 :          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MONTH), @1)); }
   15202                 :             :             | DAY_P
   15203                 :          12 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY), @1)); }
   15204                 :             :             | HOUR_P
   15205                 :           8 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR), @1)); }
   15206                 :             :             | MINUTE_P
   15207                 :           8 :                 { $$ = list_make1(makeIntConst(INTERVAL_MASK(MINUTE), @1)); }
   15208                 :             :             | interval_second
   15209                 :          24 :                 { $$ = $1; }
   15210                 :             :             | YEAR_P TO MONTH_P
   15211                 :             :                 {
   15212                 :          12 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(YEAR) |
   15213                 :             :                                                  INTERVAL_MASK(MONTH), @1));
   15214                 :             :                 }
   15215                 :             :             | DAY_P TO HOUR_P
   15216                 :             :                 {
   15217                 :          16 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   15218                 :             :                                                  INTERVAL_MASK(HOUR), @1));
   15219                 :             :                 }
   15220                 :             :             | DAY_P TO MINUTE_P
   15221                 :             :                 {
   15222                 :          16 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(DAY) |
   15223                 :             :                                                  INTERVAL_MASK(HOUR) |
   15224                 :             :                                                  INTERVAL_MASK(MINUTE), @1));
   15225                 :             :                 }
   15226                 :             :             | DAY_P TO interval_second
   15227                 :             :                 {
   15228                 :          32 :                     $$ = $3;
   15229                 :          32 :                     linitial($$) = makeIntConst(INTERVAL_MASK(DAY) |
   15230                 :             :                                                 INTERVAL_MASK(HOUR) |
   15231                 :             :                                                 INTERVAL_MASK(MINUTE) |
   15232                 :          32 :                                                 INTERVAL_MASK(SECOND), @1);
   15233                 :             :                 }
   15234                 :             :             | HOUR_P TO MINUTE_P
   15235                 :             :                 {
   15236                 :          12 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(HOUR) |
   15237                 :             :                                                  INTERVAL_MASK(MINUTE), @1));
   15238                 :             :                 }
   15239                 :             :             | HOUR_P TO interval_second
   15240                 :             :                 {
   15241                 :          24 :                     $$ = $3;
   15242                 :          24 :                     linitial($$) = makeIntConst(INTERVAL_MASK(HOUR) |
   15243                 :             :                                                 INTERVAL_MASK(MINUTE) |
   15244                 :          24 :                                                 INTERVAL_MASK(SECOND), @1);
   15245                 :             :                 }
   15246                 :             :             | MINUTE_P TO interval_second
   15247                 :             :                 {
   15248                 :          44 :                     $$ = $3;
   15249                 :          44 :                     linitial($$) = makeIntConst(INTERVAL_MASK(MINUTE) |
   15250                 :          44 :                                                 INTERVAL_MASK(SECOND), @1);
   15251                 :             :                 }
   15252                 :             :             | /*EMPTY*/
   15253                 :        4276 :                 { $$ = NIL; }
   15254                 :             :         ;
   15255                 :             : 
   15256                 :             : interval_second:
   15257                 :             :             SECOND_P
   15258                 :             :                 {
   15259                 :          68 :                     $$ = list_make1(makeIntConst(INTERVAL_MASK(SECOND), @1));
   15260                 :             :                 }
   15261                 :             :             | SECOND_P '(' Iconst ')'
   15262                 :             :                 {
   15263                 :          56 :                     $$ = list_make2(makeIntConst(INTERVAL_MASK(SECOND), @1),
   15264                 :             :                                     makeIntConst($3, @3));
   15265                 :             :                 }
   15266                 :             :         ;
   15267                 :             : 
   15268                 :             : JsonType:
   15269                 :             :             JSON
   15270                 :             :                 {
   15271                 :        1361 :                     $$ = SystemTypeName("json");
   15272                 :        1361 :                     $$->location = @1;
   15273                 :             :                 }
   15274                 :             :         ;
   15275                 :             : 
   15276                 :             : /*****************************************************************************
   15277                 :             :  *
   15278                 :             :  *  expression grammar
   15279                 :             :  *
   15280                 :             :  *****************************************************************************/
   15281                 :             : 
   15282                 :             : /*
   15283                 :             :  * General expressions
   15284                 :             :  * This is the heart of the expression syntax.
   15285                 :             :  *
   15286                 :             :  * We have two expression types: a_expr is the unrestricted kind, and
   15287                 :             :  * b_expr is a subset that must be used in some places to avoid shift/reduce
   15288                 :             :  * conflicts.  For example, we can't do BETWEEN as "BETWEEN a_expr AND a_expr"
   15289                 :             :  * because that use of AND conflicts with AND as a boolean operator.  So,
   15290                 :             :  * b_expr is used in BETWEEN and we remove boolean keywords from b_expr.
   15291                 :             :  *
   15292                 :             :  * Note that '(' a_expr ')' is a b_expr, so an unrestricted expression can
   15293                 :             :  * always be used by surrounding it with parens.
   15294                 :             :  *
   15295                 :             :  * c_expr is all the productions that are common to a_expr and b_expr;
   15296                 :             :  * it's factored out just to eliminate redundant coding.
   15297                 :             :  *
   15298                 :             :  * Be careful of productions involving more than one terminal token.
   15299                 :             :  * By default, bison will assign such productions the precedence of their
   15300                 :             :  * last terminal, but in nearly all cases you want it to be the precedence
   15301                 :             :  * of the first terminal instead; otherwise you will not get the behavior
   15302                 :             :  * you expect!  So we use %prec annotations freely to set precedences.
   15303                 :             :  */
   15304                 :     2374041 : a_expr:     c_expr                                  { $$ = $1; }
   15305                 :             :             | a_expr TYPECAST Typename
   15306                 :      145639 :                     { $$ = makeTypeCast($1, $3, @2); }
   15307                 :             :             | a_expr COLLATE any_name
   15308                 :             :                 {
   15309                 :        6619 :                     CollateClause *n = makeNode(CollateClause);
   15310                 :             : 
   15311                 :        6619 :                     n->arg = $1;
   15312                 :        6619 :                     n->collname = $3;
   15313                 :        6619 :                     n->location = @2;
   15314                 :        6619 :                     $$ = (Node *) n;
   15315                 :             :                 }
   15316                 :             :             | a_expr AT TIME ZONE a_expr            %prec AT
   15317                 :             :                 {
   15318                 :         272 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15319                 :         272 :                                                list_make2($5, $1),
   15320                 :             :                                                COERCE_SQL_SYNTAX,
   15321                 :         272 :                                                @2);
   15322                 :             :                 }
   15323                 :             :             | a_expr AT LOCAL                       %prec AT
   15324                 :             :                 {
   15325                 :          28 :                     $$ = (Node *) makeFuncCall(SystemFuncName("timezone"),
   15326                 :          28 :                                                list_make1($1),
   15327                 :             :                                                COERCE_SQL_SYNTAX,
   15328                 :             :                                                -1);
   15329                 :             :                 }
   15330                 :             :         /*
   15331                 :             :          * These operators must be called out explicitly in order to make use
   15332                 :             :          * of bison's automatic operator-precedence handling.  All other
   15333                 :             :          * operator names are handled by the generic productions using "Op",
   15334                 :             :          * below; and all those operators will have the same precedence.
   15335                 :             :          *
   15336                 :             :          * If you add more explicitly-known operators, be sure to add them
   15337                 :             :          * also to b_expr and to the MathOp list below.
   15338                 :             :          */
   15339                 :             :             | '+' a_expr                    %prec UMINUS
   15340                 :           8 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15341                 :             :             | '-' a_expr                    %prec UMINUS
   15342                 :        6401 :                 { $$ = doNegate($2, @1); }
   15343                 :             :             | a_expr '+' a_expr
   15344                 :        9697 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15345                 :             :             | a_expr '-' a_expr
   15346                 :        2884 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15347                 :             :             | a_expr '*' a_expr
   15348                 :        4257 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15349                 :             :             | a_expr '/' a_expr
   15350                 :        2278 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15351                 :             :             | a_expr '%' a_expr
   15352                 :        2095 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15353                 :             :             | a_expr '^' a_expr
   15354                 :         314 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15355                 :             :             | a_expr '<' a_expr
   15356                 :        6993 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15357                 :             :             | a_expr '>' a_expr
   15358                 :       10956 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15359                 :             :             | a_expr '=' a_expr
   15360                 :      258262 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15361                 :             :             | a_expr LESS_EQUALS a_expr
   15362                 :        2982 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15363                 :             :             | a_expr GREATER_EQUALS a_expr
   15364                 :        7466 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15365                 :             :             | a_expr NOT_EQUALS a_expr
   15366                 :       23354 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15367                 :             : 
   15368                 :             :             | a_expr qual_Op a_expr             %prec Op
   15369                 :       37245 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15370                 :             :             | qual_Op a_expr                    %prec Op
   15371                 :         157 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15372                 :             : 
   15373                 :             :             | a_expr AND a_expr
   15374                 :      153043 :                 { $$ = makeAndExpr($1, $3, @2); }
   15375                 :             :             | a_expr OR a_expr
   15376                 :       13990 :                 { $$ = makeOrExpr($1, $3, @2); }
   15377                 :             :             | NOT a_expr
   15378                 :       16984 :                 { $$ = makeNotExpr($2, @1); }
   15379                 :             :             | NOT_LA a_expr                     %prec NOT
   15380                 :           0 :                 { $$ = makeNotExpr($2, @1); }
   15381                 :             : 
   15382                 :             :             | a_expr LIKE a_expr
   15383                 :             :                 {
   15384                 :        1341 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15385                 :        1341 :                                                    $1, $3, @2);
   15386                 :             :                 }
   15387                 :             :             | a_expr LIKE a_expr ESCAPE a_expr                  %prec LIKE
   15388                 :             :                 {
   15389                 :          80 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15390                 :          80 :                                                  list_make2($3, $5),
   15391                 :             :                                                  COERCE_EXPLICIT_CALL,
   15392                 :          80 :                                                  @2);
   15393                 :          80 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "~~",
   15394                 :          80 :                                                    $1, (Node *) n, @2);
   15395                 :             :                 }
   15396                 :             :             | a_expr NOT_LA LIKE a_expr                         %prec NOT_LA
   15397                 :             :                 {
   15398                 :         124 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15399                 :         124 :                                                    $1, $4, @2);
   15400                 :             :                 }
   15401                 :             :             | a_expr NOT_LA LIKE a_expr ESCAPE a_expr           %prec NOT_LA
   15402                 :             :                 {
   15403                 :          64 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15404                 :          64 :                                                  list_make2($4, $6),
   15405                 :             :                                                  COERCE_EXPLICIT_CALL,
   15406                 :          64 :                                                  @2);
   15407                 :          64 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_LIKE, "!~~",
   15408                 :          64 :                                                    $1, (Node *) n, @2);
   15409                 :             :                 }
   15410                 :             :             | a_expr ILIKE a_expr
   15411                 :             :                 {
   15412                 :         116 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15413                 :         116 :                                                    $1, $3, @2);
   15414                 :             :                 }
   15415                 :             :             | a_expr ILIKE a_expr ESCAPE a_expr                 %prec ILIKE
   15416                 :             :                 {
   15417                 :           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15418                 :           0 :                                                  list_make2($3, $5),
   15419                 :             :                                                  COERCE_EXPLICIT_CALL,
   15420                 :           0 :                                                  @2);
   15421                 :           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "~~*",
   15422                 :           0 :                                                    $1, (Node *) n, @2);
   15423                 :             :                 }
   15424                 :             :             | a_expr NOT_LA ILIKE a_expr                        %prec NOT_LA
   15425                 :             :                 {
   15426                 :          20 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15427                 :          20 :                                                    $1, $4, @2);
   15428                 :             :                 }
   15429                 :             :             | a_expr NOT_LA ILIKE a_expr ESCAPE a_expr          %prec NOT_LA
   15430                 :             :                 {
   15431                 :           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("like_escape"),
   15432                 :           0 :                                                  list_make2($4, $6),
   15433                 :             :                                                  COERCE_EXPLICIT_CALL,
   15434                 :           0 :                                                  @2);
   15435                 :           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_ILIKE, "!~~*",
   15436                 :           0 :                                                    $1, (Node *) n, @2);
   15437                 :             :                 }
   15438                 :             : 
   15439                 :             :             | a_expr SIMILAR TO a_expr                          %prec SIMILAR
   15440                 :             :                 {
   15441                 :          58 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15442                 :          58 :                                                  list_make1($4),
   15443                 :             :                                                  COERCE_EXPLICIT_CALL,
   15444                 :          58 :                                                  @2);
   15445                 :          58 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15446                 :          58 :                                                    $1, (Node *) n, @2);
   15447                 :             :                 }
   15448                 :             :             | a_expr SIMILAR TO a_expr ESCAPE a_expr            %prec SIMILAR
   15449                 :             :                 {
   15450                 :          24 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15451                 :          24 :                                                  list_make2($4, $6),
   15452                 :             :                                                  COERCE_EXPLICIT_CALL,
   15453                 :          24 :                                                  @2);
   15454                 :          24 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "~",
   15455                 :          24 :                                                    $1, (Node *) n, @2);
   15456                 :             :                 }
   15457                 :             :             | a_expr NOT_LA SIMILAR TO a_expr                   %prec NOT_LA
   15458                 :             :                 {
   15459                 :           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15460                 :           0 :                                                  list_make1($5),
   15461                 :             :                                                  COERCE_EXPLICIT_CALL,
   15462                 :           0 :                                                  @2);
   15463                 :           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15464                 :           0 :                                                    $1, (Node *) n, @2);
   15465                 :             :                 }
   15466                 :             :             | a_expr NOT_LA SIMILAR TO a_expr ESCAPE a_expr     %prec NOT_LA
   15467                 :             :                 {
   15468                 :           0 :                     FuncCall   *n = makeFuncCall(SystemFuncName("similar_to_escape"),
   15469                 :           0 :                                                  list_make2($5, $7),
   15470                 :             :                                                  COERCE_EXPLICIT_CALL,
   15471                 :           0 :                                                  @2);
   15472                 :           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_SIMILAR, "!~",
   15473                 :           0 :                                                    $1, (Node *) n, @2);
   15474                 :             :                 }
   15475                 :             : 
   15476                 :             :             /* NullTest clause
   15477                 :             :              * Define SQL-style Null test clause.
   15478                 :             :              * Allow two forms described in the standard:
   15479                 :             :              *  a IS NULL
   15480                 :             :              *  a IS NOT NULL
   15481                 :             :              * Allow two SQL extensions
   15482                 :             :              *  a ISNULL
   15483                 :             :              *  a NOTNULL
   15484                 :             :              */
   15485                 :             :             | a_expr IS NULL_P                          %prec IS
   15486                 :             :                 {
   15487                 :        3842 :                     NullTest   *n = makeNode(NullTest);
   15488                 :             : 
   15489                 :        3842 :                     n->arg = (Expr *) $1;
   15490                 :        3842 :                     n->nulltesttype = IS_NULL;
   15491                 :        3842 :                     n->location = @2;
   15492                 :        3842 :                     $$ = (Node *) n;
   15493                 :             :                 }
   15494                 :             :             | a_expr ISNULL
   15495                 :             :                 {
   15496                 :          68 :                     NullTest   *n = makeNode(NullTest);
   15497                 :             : 
   15498                 :          68 :                     n->arg = (Expr *) $1;
   15499                 :          68 :                     n->nulltesttype = IS_NULL;
   15500                 :          68 :                     n->location = @2;
   15501                 :          68 :                     $$ = (Node *) n;
   15502                 :             :                 }
   15503                 :             :             | a_expr IS NOT NULL_P                      %prec IS
   15504                 :             :                 {
   15505                 :        8307 :                     NullTest   *n = makeNode(NullTest);
   15506                 :             : 
   15507                 :        8307 :                     n->arg = (Expr *) $1;
   15508                 :        8307 :                     n->nulltesttype = IS_NOT_NULL;
   15509                 :        8307 :                     n->location = @2;
   15510                 :        8307 :                     $$ = (Node *) n;
   15511                 :             :                 }
   15512                 :             :             | a_expr NOTNULL
   15513                 :             :                 {
   15514                 :           4 :                     NullTest   *n = makeNode(NullTest);
   15515                 :             : 
   15516                 :           4 :                     n->arg = (Expr *) $1;
   15517                 :           4 :                     n->nulltesttype = IS_NOT_NULL;
   15518                 :           4 :                     n->location = @2;
   15519                 :           4 :                     $$ = (Node *) n;
   15520                 :             :                 }
   15521                 :             :             | row OVERLAPS row
   15522                 :             :                 {
   15523         [ -  + ]:         581 :                     if (list_length($1) != 2)
   15524         [ #  # ]:           0 :                         ereport(ERROR,
   15525                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15526                 :             :                                  errmsg("wrong number of parameters on left side of OVERLAPS expression"),
   15527                 :             :                                  parser_errposition(@1)));
   15528         [ -  + ]:         581 :                     if (list_length($3) != 2)
   15529         [ #  # ]:           0 :                         ereport(ERROR,
   15530                 :             :                                 (errcode(ERRCODE_SYNTAX_ERROR),
   15531                 :             :                                  errmsg("wrong number of parameters on right side of OVERLAPS expression"),
   15532                 :             :                                  parser_errposition(@3)));
   15533                 :         581 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlaps"),
   15534                 :         581 :                                                list_concat($1, $3),
   15535                 :             :                                                COERCE_SQL_SYNTAX,
   15536                 :         581 :                                                @2);
   15537                 :             :                 }
   15538                 :             :             | a_expr IS TRUE_P                          %prec IS
   15539                 :             :                 {
   15540                 :         263 :                     BooleanTest *b = makeNode(BooleanTest);
   15541                 :             : 
   15542                 :         263 :                     b->arg = (Expr *) $1;
   15543                 :         263 :                     b->booltesttype = IS_TRUE;
   15544                 :         263 :                     b->location = @2;
   15545                 :         263 :                     $$ = (Node *) b;
   15546                 :             :                 }
   15547                 :             :             | a_expr IS NOT TRUE_P                      %prec IS
   15548                 :             :                 {
   15549                 :         100 :                     BooleanTest *b = makeNode(BooleanTest);
   15550                 :             : 
   15551                 :         100 :                     b->arg = (Expr *) $1;
   15552                 :         100 :                     b->booltesttype = IS_NOT_TRUE;
   15553                 :         100 :                     b->location = @2;
   15554                 :         100 :                     $$ = (Node *) b;
   15555                 :             :                 }
   15556                 :             :             | a_expr IS FALSE_P                         %prec IS
   15557                 :             :                 {
   15558                 :         159 :                     BooleanTest *b = makeNode(BooleanTest);
   15559                 :             : 
   15560                 :         159 :                     b->arg = (Expr *) $1;
   15561                 :         159 :                     b->booltesttype = IS_FALSE;
   15562                 :         159 :                     b->location = @2;
   15563                 :         159 :                     $$ = (Node *) b;
   15564                 :             :                 }
   15565                 :             :             | a_expr IS NOT FALSE_P                     %prec IS
   15566                 :             :                 {
   15567                 :          70 :                     BooleanTest *b = makeNode(BooleanTest);
   15568                 :             : 
   15569                 :          70 :                     b->arg = (Expr *) $1;
   15570                 :          70 :                     b->booltesttype = IS_NOT_FALSE;
   15571                 :          70 :                     b->location = @2;
   15572                 :          70 :                     $$ = (Node *) b;
   15573                 :             :                 }
   15574                 :             :             | a_expr IS UNKNOWN                         %prec IS
   15575                 :             :                 {
   15576                 :          50 :                     BooleanTest *b = makeNode(BooleanTest);
   15577                 :             : 
   15578                 :          50 :                     b->arg = (Expr *) $1;
   15579                 :          50 :                     b->booltesttype = IS_UNKNOWN;
   15580                 :          50 :                     b->location = @2;
   15581                 :          50 :                     $$ = (Node *) b;
   15582                 :             :                 }
   15583                 :             :             | a_expr IS NOT UNKNOWN                     %prec IS
   15584                 :             :                 {
   15585                 :          40 :                     BooleanTest *b = makeNode(BooleanTest);
   15586                 :             : 
   15587                 :          40 :                     b->arg = (Expr *) $1;
   15588                 :          40 :                     b->booltesttype = IS_NOT_UNKNOWN;
   15589                 :          40 :                     b->location = @2;
   15590                 :          40 :                     $$ = (Node *) b;
   15591                 :             :                 }
   15592                 :             :             | a_expr IS DISTINCT FROM a_expr            %prec IS
   15593                 :             :                 {
   15594                 :         655 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15595                 :             :                 }
   15596                 :             :             | a_expr IS NOT DISTINCT FROM a_expr        %prec IS
   15597                 :             :                 {
   15598                 :          84 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15599                 :             :                 }
   15600                 :             :             | a_expr BETWEEN opt_asymmetric b_expr AND a_expr       %prec BETWEEN
   15601                 :             :                 {
   15602                 :         316 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN,
   15603                 :             :                                                    "BETWEEN",
   15604                 :         316 :                                                    $1,
   15605                 :         316 :                                                    (Node *) list_make2($4, $6),
   15606                 :         316 :                                                    @2);
   15607                 :             :                 }
   15608                 :             :             | a_expr NOT_LA BETWEEN opt_asymmetric b_expr AND a_expr %prec NOT_LA
   15609                 :             :                 {
   15610                 :           8 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN,
   15611                 :             :                                                    "NOT BETWEEN",
   15612                 :           8 :                                                    $1,
   15613                 :           8 :                                                    (Node *) list_make2($5, $7),
   15614                 :           8 :                                                    @2);
   15615                 :             :                 }
   15616                 :             :             | a_expr BETWEEN SYMMETRIC b_expr AND a_expr            %prec BETWEEN
   15617                 :             :                 {
   15618                 :           8 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_BETWEEN_SYM,
   15619                 :             :                                                    "BETWEEN SYMMETRIC",
   15620                 :           8 :                                                    $1,
   15621                 :           8 :                                                    (Node *) list_make2($4, $6),
   15622                 :           8 :                                                    @2);
   15623                 :             :                 }
   15624                 :             :             | a_expr NOT_LA BETWEEN SYMMETRIC b_expr AND a_expr     %prec NOT_LA
   15625                 :             :                 {
   15626                 :           8 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_BETWEEN_SYM,
   15627                 :             :                                                    "NOT BETWEEN SYMMETRIC",
   15628                 :           8 :                                                    $1,
   15629                 :           8 :                                                    (Node *) list_make2($5, $7),
   15630                 :           8 :                                                    @2);
   15631                 :             :                 }
   15632                 :             :             | a_expr IN_P select_with_parens
   15633                 :             :                 {
   15634                 :             :                     /* generate foo = ANY (subquery) */
   15635                 :        3736 :                     SubLink    *n = makeNode(SubLink);
   15636                 :             : 
   15637                 :        3736 :                     n->subselect = $3;
   15638                 :        3736 :                     n->subLinkType = ANY_SUBLINK;
   15639                 :        3736 :                     n->subLinkId = 0;
   15640                 :        3736 :                     n->testexpr = $1;
   15641                 :        3736 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15642                 :        3736 :                     n->location = @2;
   15643                 :        3736 :                     $$ = (Node *) n;
   15644                 :             :                 }
   15645                 :             :             | a_expr IN_P '(' expr_list ')'
   15646                 :             :                 {
   15647                 :             :                     /* generate scalar IN expression */
   15648                 :       10776 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "=", $1, (Node *) $4, @2);
   15649                 :             : 
   15650                 :       10776 :                     n->rexpr_list_start = @3;
   15651                 :       10776 :                     n->rexpr_list_end = @5;
   15652                 :       10776 :                     $$ = (Node *) n;
   15653                 :             :                 }
   15654                 :             :             | a_expr NOT_LA IN_P select_with_parens         %prec NOT_LA
   15655                 :             :                 {
   15656                 :             :                     /* generate NOT (foo = ANY (subquery)) */
   15657                 :         184 :                     SubLink    *n = makeNode(SubLink);
   15658                 :             : 
   15659                 :         184 :                     n->subselect = $4;
   15660                 :         184 :                     n->subLinkType = ANY_SUBLINK;
   15661                 :         184 :                     n->subLinkId = 0;
   15662                 :         184 :                     n->testexpr = $1;
   15663                 :         184 :                     n->operName = NIL;       /* show it's IN not = ANY */
   15664                 :         184 :                     n->location = @2;
   15665                 :             :                     /* Stick a NOT on top; must have same parse location */
   15666                 :         184 :                     $$ = makeNotExpr((Node *) n, @2);
   15667                 :             :                 }
   15668                 :             :             | a_expr NOT_LA IN_P '(' expr_list ')'
   15669                 :             :                 {
   15670                 :             :                     /* generate scalar NOT IN expression */
   15671                 :        1580 :                     A_Expr *n = makeSimpleA_Expr(AEXPR_IN, "<>", $1, (Node *) $5, @2);
   15672                 :             : 
   15673                 :        1580 :                     n->rexpr_list_start = @4;
   15674                 :        1580 :                     n->rexpr_list_end = @6;
   15675                 :        1580 :                     $$ = (Node *) n;
   15676                 :             :                 }
   15677                 :             :             | a_expr subquery_Op sub_type select_with_parens    %prec Op
   15678                 :             :                 {
   15679                 :         124 :                     SubLink    *n = makeNode(SubLink);
   15680                 :             : 
   15681                 :         124 :                     n->subLinkType = $3;
   15682                 :         124 :                     n->subLinkId = 0;
   15683                 :         124 :                     n->testexpr = $1;
   15684                 :         124 :                     n->operName = $2;
   15685                 :         124 :                     n->subselect = $4;
   15686                 :         124 :                     n->location = @2;
   15687                 :         124 :                     $$ = (Node *) n;
   15688                 :             :                 }
   15689                 :             :             | a_expr subquery_Op sub_type '(' a_expr ')'        %prec Op
   15690                 :             :                 {
   15691         [ +  + ]:       11133 :                     if ($3 == ANY_SUBLINK)
   15692                 :       10928 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ANY, $2, $1, $5, @2);
   15693                 :             :                     else
   15694                 :         205 :                         $$ = (Node *) makeA_Expr(AEXPR_OP_ALL, $2, $1, $5, @2);
   15695                 :             :                 }
   15696                 :             :             | UNIQUE opt_unique_null_treatment select_with_parens
   15697                 :             :                 {
   15698                 :             :                     /* Not sure how to get rid of the parentheses
   15699                 :             :                      * but there are lots of shift/reduce errors without them.
   15700                 :             :                      *
   15701                 :             :                      * Should be able to implement this by plopping the entire
   15702                 :             :                      * select into a node, then transforming the target expressions
   15703                 :             :                      * from whatever they are into count(*), and testing the
   15704                 :             :                      * entire result equal to one.
   15705                 :             :                      * But, will probably implement a separate node in the executor.
   15706                 :             :                      */
   15707         [ #  # ]:           0 :                     ereport(ERROR,
   15708                 :             :                             (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   15709                 :             :                              errmsg("UNIQUE predicate is not yet implemented"),
   15710                 :             :                              parser_errposition(@1)));
   15711                 :             :                 }
   15712                 :             :             | a_expr IS DOCUMENT_P                  %prec IS
   15713                 :             :                 {
   15714                 :          16 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15715                 :          16 :                                      list_make1($1), @2);
   15716                 :             :                 }
   15717                 :             :             | a_expr IS NOT DOCUMENT_P              %prec IS
   15718                 :             :                 {
   15719                 :          12 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15720                 :          12 :                                                  list_make1($1), @2),
   15721                 :          12 :                                      @2);
   15722                 :             :                 }
   15723                 :             :             | a_expr IS NORMALIZED                              %prec IS
   15724                 :             :                 {
   15725                 :           8 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15726                 :           8 :                                                list_make1($1),
   15727                 :             :                                                COERCE_SQL_SYNTAX,
   15728                 :           8 :                                                @2);
   15729                 :             :                 }
   15730                 :             :             | a_expr IS unicode_normal_form NORMALIZED          %prec IS
   15731                 :             :                 {
   15732                 :          48 :                     $$ = (Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15733                 :          24 :                                                list_make2($1, makeStringConst($3, @3)),
   15734                 :             :                                                COERCE_SQL_SYNTAX,
   15735                 :          24 :                                                @2);
   15736                 :             :                 }
   15737                 :             :             | a_expr IS NOT NORMALIZED                          %prec IS
   15738                 :             :                 {
   15739                 :           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15740                 :           0 :                                                            list_make1($1),
   15741                 :             :                                                            COERCE_SQL_SYNTAX,
   15742                 :           0 :                                                            @2),
   15743                 :           0 :                                      @2);
   15744                 :             :                 }
   15745                 :             :             | a_expr IS NOT unicode_normal_form NORMALIZED      %prec IS
   15746                 :             :                 {
   15747                 :           0 :                     $$ = makeNotExpr((Node *) makeFuncCall(SystemFuncName("is_normalized"),
   15748                 :           0 :                                                            list_make2($1, makeStringConst($4, @4)),
   15749                 :             :                                                            COERCE_SQL_SYNTAX,
   15750                 :           0 :                                                            @2),
   15751                 :           0 :                                      @2);
   15752                 :             :                 }
   15753                 :             :             | a_expr IS json_predicate_type_constraint
   15754                 :             :                     json_key_uniqueness_constraint_opt      %prec IS
   15755                 :             :                 {
   15756                 :         246 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15757                 :             : 
   15758                 :         246 :                     $$ = makeJsonIsPredicate($1, format, $3, $4, InvalidOid, @1);
   15759                 :             :                 }
   15760                 :             :             /*
   15761                 :             :              * Required by SQL/JSON, but there are conflicts
   15762                 :             :             | a_expr
   15763                 :             :                 json_format_clause
   15764                 :             :                 IS  json_predicate_type_constraint
   15765                 :             :                     json_key_uniqueness_constraint_opt      %prec IS
   15766                 :             :                 {
   15767                 :             :                     $$ = makeJsonIsPredicate($1, $2, $4, $5, InvalidOid, @1);
   15768                 :             :                 }
   15769                 :             :             */
   15770                 :             :             | a_expr IS NOT
   15771                 :             :                     json_predicate_type_constraint
   15772                 :             :                     json_key_uniqueness_constraint_opt      %prec IS
   15773                 :             :                 {
   15774                 :          34 :                     JsonFormat *format = makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   15775                 :             : 
   15776                 :          34 :                     $$ = makeNotExpr(makeJsonIsPredicate($1, format, $4, $5, InvalidOid, @1), @1);
   15777                 :             :                 }
   15778                 :             :             /*
   15779                 :             :              * Required by SQL/JSON, but there are conflicts
   15780                 :             :             | a_expr
   15781                 :             :                 json_format_clause
   15782                 :             :                 IS NOT
   15783                 :             :                     json_predicate_type_constraint
   15784                 :             :                     json_key_uniqueness_constraint_opt      %prec IS
   15785                 :             :                 {
   15786                 :             :                     $$ = makeNotExpr(makeJsonIsPredicate($1, $2, $5, $6, InvalidOid, @1), @1);
   15787                 :             :                 }
   15788                 :             :             */
   15789                 :             :             | DEFAULT
   15790                 :             :                 {
   15791                 :             :                     /*
   15792                 :             :                      * The SQL spec only allows DEFAULT in "contextually typed
   15793                 :             :                      * expressions", but for us, it's easier to allow it in
   15794                 :             :                      * any a_expr and then throw error during parse analysis
   15795                 :             :                      * if it's in an inappropriate context.  This way also
   15796                 :             :                      * lets us say something smarter than "syntax error".
   15797                 :             :                      */
   15798                 :        1025 :                     SetToDefault *n = makeNode(SetToDefault);
   15799                 :             : 
   15800                 :             :                     /* parse analysis will fill in the rest */
   15801                 :        1025 :                     n->location = @1;
   15802                 :        1025 :                     $$ = (Node *) n;
   15803                 :             :                 }
   15804                 :             :         ;
   15805                 :             : 
   15806                 :             : /*
   15807                 :             :  * Restricted expressions
   15808                 :             :  *
   15809                 :             :  * b_expr is a subset of the complete expression syntax defined by a_expr.
   15810                 :             :  *
   15811                 :             :  * Presently, AND, NOT, IS, and IN are the a_expr keywords that would
   15812                 :             :  * cause trouble in the places where b_expr is used.  For simplicity, we
   15813                 :             :  * just eliminate all the boolean-keyword-operator productions from b_expr.
   15814                 :             :  */
   15815                 :             : b_expr:     c_expr
   15816                 :        2538 :                 { $$ = $1; }
   15817                 :             :             | b_expr TYPECAST Typename
   15818                 :         152 :                 { $$ = makeTypeCast($1, $3, @2); }
   15819                 :             :             | '+' b_expr                    %prec UMINUS
   15820                 :           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", NULL, $2, @1); }
   15821                 :             :             | '-' b_expr                    %prec UMINUS
   15822                 :          44 :                 { $$ = doNegate($2, @1); }
   15823                 :             :             | b_expr '+' b_expr
   15824                 :          24 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "+", $1, $3, @2); }
   15825                 :             :             | b_expr '-' b_expr
   15826                 :          10 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "-", $1, $3, @2); }
   15827                 :             :             | b_expr '*' b_expr
   15828                 :           8 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "*", $1, $3, @2); }
   15829                 :             :             | b_expr '/' b_expr
   15830                 :           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "/", $1, $3, @2); }
   15831                 :             :             | b_expr '%' b_expr
   15832                 :           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "%", $1, $3, @2); }
   15833                 :             :             | b_expr '^' b_expr
   15834                 :           4 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "^", $1, $3, @2); }
   15835                 :             :             | b_expr '<' b_expr
   15836                 :           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<", $1, $3, @2); }
   15837                 :             :             | b_expr '>' b_expr
   15838                 :           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">", $1, $3, @2); }
   15839                 :             :             | b_expr '=' b_expr
   15840                 :           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "=", $1, $3, @2); }
   15841                 :             :             | b_expr LESS_EQUALS b_expr
   15842                 :           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<=", $1, $3, @2); }
   15843                 :             :             | b_expr GREATER_EQUALS b_expr
   15844                 :           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, ">=", $1, $3, @2); }
   15845                 :             :             | b_expr NOT_EQUALS b_expr
   15846                 :           0 :                 { $$ = (Node *) makeSimpleA_Expr(AEXPR_OP, "<>", $1, $3, @2); }
   15847                 :             :             | b_expr qual_Op b_expr             %prec Op
   15848                 :           8 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $2, $1, $3, @2); }
   15849                 :             :             | qual_Op b_expr                    %prec Op
   15850                 :           0 :                 { $$ = (Node *) makeA_Expr(AEXPR_OP, $1, NULL, $2, @1); }
   15851                 :             :             | b_expr IS DISTINCT FROM b_expr        %prec IS
   15852                 :             :                 {
   15853                 :           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_DISTINCT, "=", $1, $5, @2);
   15854                 :             :                 }
   15855                 :             :             | b_expr IS NOT DISTINCT FROM b_expr    %prec IS
   15856                 :             :                 {
   15857                 :           0 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NOT_DISTINCT, "=", $1, $6, @2);
   15858                 :             :                 }
   15859                 :             :             | b_expr IS DOCUMENT_P                  %prec IS
   15860                 :             :                 {
   15861                 :           0 :                     $$ = makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15862                 :           0 :                                      list_make1($1), @2);
   15863                 :             :                 }
   15864                 :             :             | b_expr IS NOT DOCUMENT_P              %prec IS
   15865                 :             :                 {
   15866                 :           0 :                     $$ = makeNotExpr(makeXmlExpr(IS_DOCUMENT, NULL, NIL,
   15867                 :           0 :                                                  list_make1($1), @2),
   15868                 :           0 :                                      @2);
   15869                 :             :                 }
   15870                 :             :         ;
   15871                 :             : 
   15872                 :             : /*
   15873                 :             :  * Productions that can be used in both a_expr and b_expr.
   15874                 :             :  *
   15875                 :             :  * Note: productions that refer recursively to a_expr or b_expr mostly
   15876                 :             :  * cannot appear here.  However, it's OK to refer to a_exprs that occur
   15877                 :             :  * inside parentheses, such as function arguments; that cannot introduce
   15878                 :             :  * ambiguity to the b_expr syntax.
   15879                 :             :  */
   15880                 :     1157311 : c_expr:     columnref                               { $$ = $1; }
   15881                 :      811581 :             | AexprConst                            { $$ = $1; }
   15882                 :             :             | PARAM opt_indirection
   15883                 :             :                 {
   15884                 :       26944 :                     ParamRef   *p = makeNode(ParamRef);
   15885                 :             : 
   15886                 :       26944 :                     p->number = $1;
   15887                 :       26944 :                     p->location = @1;
   15888         [ +  + ]:       26944 :                     if ($2)
   15889                 :             :                     {
   15890                 :         725 :                         A_Indirection *n = makeNode(A_Indirection);
   15891                 :             : 
   15892                 :         725 :                         n->arg = (Node *) p;
   15893                 :         725 :                         n->indirection = check_indirection($2, yyscanner);
   15894                 :         725 :                         $$ = (Node *) n;
   15895                 :             :                     }
   15896                 :             :                     else
   15897                 :       26219 :                         $$ = (Node *) p;
   15898                 :             :                 }
   15899                 :             :             | '(' a_expr ')' opt_indirection
   15900                 :             :                 {
   15901         [ +  + ]:       60352 :                     if ($4)
   15902                 :             :                     {
   15903                 :        9318 :                         A_Indirection *n = makeNode(A_Indirection);
   15904                 :             : 
   15905                 :        9318 :                         n->arg = $2;
   15906                 :        9318 :                         n->indirection = check_indirection($4, yyscanner);
   15907                 :        9318 :                         $$ = (Node *) n;
   15908                 :             :                     }
   15909                 :             :                     else
   15910                 :       51034 :                         $$ = $2;
   15911                 :             :                 }
   15912                 :             :             | case_expr
   15913                 :       25456 :                 { $$ = $1; }
   15914                 :             :             | func_expr
   15915                 :      254750 :                 { $$ = $1; }
   15916                 :             :             | select_with_parens            %prec UMINUS
   15917                 :             :                 {
   15918                 :       16941 :                     SubLink    *n = makeNode(SubLink);
   15919                 :             : 
   15920                 :       16941 :                     n->subLinkType = EXPR_SUBLINK;
   15921                 :       16941 :                     n->subLinkId = 0;
   15922                 :       16941 :                     n->testexpr = NULL;
   15923                 :       16941 :                     n->operName = NIL;
   15924                 :       16941 :                     n->subselect = $1;
   15925                 :       16941 :                     n->location = @1;
   15926                 :       16941 :                     $$ = (Node *) n;
   15927                 :             :                 }
   15928                 :             :             | select_with_parens indirection
   15929                 :             :                 {
   15930                 :             :                     /*
   15931                 :             :                      * Because the select_with_parens nonterminal is designed
   15932                 :             :                      * to "eat" as many levels of parens as possible, the
   15933                 :             :                      * '(' a_expr ')' opt_indirection production above will
   15934                 :             :                      * fail to match a sub-SELECT with indirection decoration;
   15935                 :             :                      * the sub-SELECT won't be regarded as an a_expr as long
   15936                 :             :                      * as there are parens around it.  To support applying
   15937                 :             :                      * subscripting or field selection to a sub-SELECT result,
   15938                 :             :                      * we need this redundant-looking production.
   15939                 :             :                      */
   15940                 :          12 :                     SubLink    *n = makeNode(SubLink);
   15941                 :          12 :                     A_Indirection *a = makeNode(A_Indirection);
   15942                 :             : 
   15943                 :          12 :                     n->subLinkType = EXPR_SUBLINK;
   15944                 :          12 :                     n->subLinkId = 0;
   15945                 :          12 :                     n->testexpr = NULL;
   15946                 :          12 :                     n->operName = NIL;
   15947                 :          12 :                     n->subselect = $1;
   15948                 :          12 :                     n->location = @1;
   15949                 :          12 :                     a->arg = (Node *) n;
   15950                 :          12 :                     a->indirection = check_indirection($2, yyscanner);
   15951                 :          12 :                     $$ = (Node *) a;
   15952                 :             :                 }
   15953                 :             :             | EXISTS select_with_parens
   15954                 :             :                 {
   15955                 :        8197 :                     SubLink    *n = makeNode(SubLink);
   15956                 :             : 
   15957                 :        8197 :                     n->subLinkType = EXISTS_SUBLINK;
   15958                 :        8197 :                     n->subLinkId = 0;
   15959                 :        8197 :                     n->testexpr = NULL;
   15960                 :        8197 :                     n->operName = NIL;
   15961                 :        8197 :                     n->subselect = $2;
   15962                 :        8197 :                     n->location = @1;
   15963                 :        8197 :                     $$ = (Node *) n;
   15964                 :             :                 }
   15965                 :             :             | ARRAY select_with_parens
   15966                 :             :                 {
   15967                 :        5337 :                     SubLink    *n = makeNode(SubLink);
   15968                 :             : 
   15969                 :        5337 :                     n->subLinkType = ARRAY_SUBLINK;
   15970                 :        5337 :                     n->subLinkId = 0;
   15971                 :        5337 :                     n->testexpr = NULL;
   15972                 :        5337 :                     n->operName = NIL;
   15973                 :        5337 :                     n->subselect = $2;
   15974                 :        5337 :                     n->location = @1;
   15975                 :        5337 :                     $$ = (Node *) n;
   15976                 :             :                 }
   15977                 :             :             | ARRAY array_expr
   15978                 :             :                 {
   15979                 :        5461 :                     A_ArrayExpr *n = castNode(A_ArrayExpr, $2);
   15980                 :             : 
   15981                 :             :                     /* point outermost A_ArrayExpr to the ARRAY keyword */
   15982                 :        5461 :                     n->location = @1;
   15983                 :        5461 :                     $$ = (Node *) n;
   15984                 :             :                 }
   15985                 :             :             | explicit_row
   15986                 :             :                 {
   15987                 :        2701 :                     RowExpr    *r = makeNode(RowExpr);
   15988                 :             : 
   15989                 :        2701 :                     r->args = $1;
   15990                 :        2701 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   15991                 :        2701 :                     r->colnames = NIL;   /* to be filled in during analysis */
   15992                 :        2701 :                     r->row_format = COERCE_EXPLICIT_CALL; /* abuse */
   15993                 :        2701 :                     r->location = @1;
   15994                 :        2701 :                     $$ = (Node *) r;
   15995                 :             :                 }
   15996                 :             :             | implicit_row
   15997                 :             :                 {
   15998                 :        1825 :                     RowExpr    *r = makeNode(RowExpr);
   15999                 :             : 
   16000                 :        1825 :                     r->args = $1;
   16001                 :        1825 :                     r->row_typeid = InvalidOid;  /* not analyzed yet */
   16002                 :        1825 :                     r->colnames = NIL;   /* to be filled in during analysis */
   16003                 :        1825 :                     r->row_format = COERCE_IMPLICIT_CAST; /* abuse */
   16004                 :        1825 :                     r->location = @1;
   16005                 :        1825 :                     $$ = (Node *) r;
   16006                 :             :                 }
   16007                 :             :             | GROUPING '(' expr_list ')'
   16008                 :             :               {
   16009                 :         252 :                   GroupingFunc *g = makeNode(GroupingFunc);
   16010                 :             : 
   16011                 :         252 :                   g->args = $3;
   16012                 :         252 :                   g->location = @1;
   16013                 :         252 :                   $$ = (Node *) g;
   16014                 :             :               }
   16015                 :             :         ;
   16016                 :             : 
   16017                 :             : func_application: func_name '(' ')'
   16018                 :             :                 {
   16019                 :       19980 :                     $$ = (Node *) makeFuncCall($1, NIL,
   16020                 :             :                                                COERCE_EXPLICIT_CALL,
   16021                 :       19981 :                                                @1);
   16022                 :             :                 }
   16023                 :             :             | func_name '(' func_arg_list opt_sort_clause ')'
   16024                 :             :                 {
   16025                 :      205971 :                     FuncCall   *n = makeFuncCall($1, $3,
   16026                 :             :                                                  COERCE_EXPLICIT_CALL,
   16027                 :      205971 :                                                  @1);
   16028                 :             : 
   16029                 :      205971 :                     n->agg_order = $4;
   16030                 :      205971 :                     $$ = (Node *) n;
   16031                 :             :                 }
   16032                 :             :             | func_name '(' VARIADIC func_arg_expr opt_sort_clause ')'
   16033                 :             :                 {
   16034                 :         382 :                     FuncCall   *n = makeFuncCall($1, list_make1($4),
   16035                 :             :                                                  COERCE_EXPLICIT_CALL,
   16036                 :         382 :                                                  @1);
   16037                 :             : 
   16038                 :         382 :                     n->func_variadic = true;
   16039                 :         382 :                     n->agg_order = $5;
   16040                 :         382 :                     $$ = (Node *) n;
   16041                 :             :                 }
   16042                 :             :             | func_name '(' func_arg_list ',' VARIADIC func_arg_expr opt_sort_clause ')'
   16043                 :             :                 {
   16044                 :         116 :                     FuncCall   *n = makeFuncCall($1, lappend($3, $6),
   16045                 :             :                                                  COERCE_EXPLICIT_CALL,
   16046                 :         116 :                                                  @1);
   16047                 :             : 
   16048                 :         116 :                     n->func_variadic = true;
   16049                 :         116 :                     n->agg_order = $7;
   16050                 :         116 :                     $$ = (Node *) n;
   16051                 :             :                 }
   16052                 :             :             | func_name '(' ALL func_arg_list opt_sort_clause ')'
   16053                 :             :                 {
   16054                 :           0 :                     FuncCall   *n = makeFuncCall($1, $4,
   16055                 :             :                                                  COERCE_EXPLICIT_CALL,
   16056                 :           0 :                                                  @1);
   16057                 :             : 
   16058                 :           0 :                     n->agg_order = $5;
   16059                 :             :                     /* Ideally we'd mark the FuncCall node to indicate
   16060                 :             :                      * "must be an aggregate", but there's no provision
   16061                 :             :                      * for that in FuncCall at the moment.
   16062                 :             :                      */
   16063                 :           0 :                     $$ = (Node *) n;
   16064                 :             :                 }
   16065                 :             :             | func_name '(' DISTINCT func_arg_list opt_sort_clause ')'
   16066                 :             :                 {
   16067                 :         369 :                     FuncCall   *n = makeFuncCall($1, $4,
   16068                 :             :                                                  COERCE_EXPLICIT_CALL,
   16069                 :         369 :                                                  @1);
   16070                 :             : 
   16071                 :         369 :                     n->agg_order = $5;
   16072                 :         369 :                     n->agg_distinct = true;
   16073                 :         369 :                     $$ = (Node *) n;
   16074                 :             :                 }
   16075                 :             :             | func_name '(' '*' ')'
   16076                 :             :                 {
   16077                 :             :                     /*
   16078                 :             :                      * We consider AGGREGATE(*) to invoke a parameterless
   16079                 :             :                      * aggregate.  This does the right thing for COUNT(*),
   16080                 :             :                      * and there are no other aggregates in SQL that accept
   16081                 :             :                      * '*' as parameter.
   16082                 :             :                      *
   16083                 :             :                      * The FuncCall node is also marked agg_star = true,
   16084                 :             :                      * so that later processing can detect what the argument
   16085                 :             :                      * really was.
   16086                 :             :                      */
   16087                 :       11841 :                     FuncCall   *n = makeFuncCall($1, NIL,
   16088                 :             :                                                  COERCE_EXPLICIT_CALL,
   16089                 :       11841 :                                                  @1);
   16090                 :             : 
   16091                 :       11841 :                     n->agg_star = true;
   16092                 :       11841 :                     $$ = (Node *) n;
   16093                 :             :                 }
   16094                 :             :         ;
   16095                 :             : 
   16096                 :             : 
   16097                 :             : /*
   16098                 :             :  * func_expr and its cousin func_expr_windowless are split out from c_expr just
   16099                 :             :  * so that we have classifications for "everything that is a function call or
   16100                 :             :  * looks like one".  This isn't very important, but it saves us having to
   16101                 :             :  * document which variants are legal in places like "FROM function()" or the
   16102                 :             :  * backwards-compatible functional-index syntax for CREATE INDEX.
   16103                 :             :  * (Note that many of the special SQL functions wouldn't actually make any
   16104                 :             :  * sense as functional index entries, but we ignore that consideration here.)
   16105                 :             :  */
   16106                 :             : func_expr: func_application within_group_clause filter_clause null_treatment over_clause
   16107                 :             :                 {
   16108                 :      207966 :                     FuncCall   *n = (FuncCall *) $1;
   16109                 :             : 
   16110                 :             :                     /*
   16111                 :             :                      * The order clause for WITHIN GROUP and the one for
   16112                 :             :                      * plain-aggregate ORDER BY share a field, so we have to
   16113                 :             :                      * check here that at most one is present.  We also check
   16114                 :             :                      * for DISTINCT and VARIADIC here to give a better error
   16115                 :             :                      * location.  Other consistency checks are deferred to
   16116                 :             :                      * parse analysis.
   16117                 :             :                      */
   16118         [ +  + ]:      207966 :                     if ($2 != NIL)
   16119                 :             :                     {
   16120         [ +  + ]:         228 :                         if (n->agg_order != NIL)
   16121         [ +  - ]:           4 :                             ereport(ERROR,
   16122                 :             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   16123                 :             :                                      errmsg("cannot use multiple ORDER BY clauses with WITHIN GROUP"),
   16124                 :             :                                      parser_errposition(@2)));
   16125         [ -  + ]:         224 :                         if (n->agg_distinct)
   16126         [ #  # ]:           0 :                             ereport(ERROR,
   16127                 :             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   16128                 :             :                                      errmsg("cannot use DISTINCT with WITHIN GROUP"),
   16129                 :             :                                      parser_errposition(@2)));
   16130         [ -  + ]:         224 :                         if (n->func_variadic)
   16131         [ #  # ]:           0 :                             ereport(ERROR,
   16132                 :             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   16133                 :             :                                      errmsg("cannot use VARIADIC with WITHIN GROUP"),
   16134                 :             :                                      parser_errposition(@2)));
   16135                 :         224 :                         n->agg_order = $2;
   16136                 :         224 :                         n->agg_within_group = true;
   16137                 :             :                     }
   16138                 :      207962 :                     n->agg_filter = $3;
   16139                 :      207962 :                     n->ignore_nulls = $4;
   16140                 :      207962 :                     n->over = $5;
   16141                 :      207962 :                     $$ = (Node *) n;
   16142                 :             :                 }
   16143                 :             :             | json_aggregate_func filter_clause over_clause
   16144                 :             :                 {
   16145                 :         584 :                     JsonAggConstructor *n = IsA($1, JsonObjectAgg) ?
   16146         [ +  + ]:         292 :                         ((JsonObjectAgg *) $1)->constructor :
   16147                 :         140 :                         ((JsonArrayAgg *) $1)->constructor;
   16148                 :             : 
   16149                 :         292 :                     n->agg_filter = $2;
   16150                 :         292 :                     n->over = $3;
   16151                 :         292 :                     $$ = (Node *) $1;
   16152                 :             :                 }
   16153                 :             :             | func_expr_common_subexpr
   16154                 :       46496 :                 { $$ = $1; }
   16155                 :             :         ;
   16156                 :             : 
   16157                 :             : /*
   16158                 :             :  * Like func_expr but does not accept WINDOW functions directly
   16159                 :             :  * (but they can still be contained in arguments for functions etc).
   16160                 :             :  * Use this when window expressions are not allowed, where needed to
   16161                 :             :  * disambiguate the grammar (e.g. in CREATE INDEX).
   16162                 :             :  */
   16163                 :             : func_expr_windowless:
   16164                 :       30326 :             func_application                        { $$ = $1; }
   16165                 :         396 :             | func_expr_common_subexpr              { $$ = $1; }
   16166                 :          16 :             | json_aggregate_func                   { $$ = $1; }
   16167                 :             :         ;
   16168                 :             : 
   16169                 :             : /*
   16170                 :             :  * Special expressions that are considered to be functions.
   16171                 :             :  */
   16172                 :             : func_expr_common_subexpr:
   16173                 :             :             COLLATION FOR '(' a_expr ')'
   16174                 :             :                 {
   16175                 :          20 :                     $$ = (Node *) makeFuncCall(SystemFuncName("pg_collation_for"),
   16176                 :          20 :                                                list_make1($4),
   16177                 :             :                                                COERCE_SQL_SYNTAX,
   16178                 :          20 :                                                @1);
   16179                 :             :                 }
   16180                 :             :             | CURRENT_DATE
   16181                 :             :                 {
   16182                 :         191 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_DATE, -1, @1);
   16183                 :             :                 }
   16184                 :             :             | CURRENT_TIME
   16185                 :             :                 {
   16186                 :          16 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME, -1, @1);
   16187                 :             :                 }
   16188                 :             :             | CURRENT_TIME '(' Iconst ')'
   16189                 :             :                 {
   16190                 :          16 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIME_N, $3, @1);
   16191                 :             :                 }
   16192                 :             :             | CURRENT_TIMESTAMP
   16193                 :             :                 {
   16194                 :         152 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP, -1, @1);
   16195                 :             :                 }
   16196                 :             :             | CURRENT_TIMESTAMP '(' Iconst ')'
   16197                 :             :                 {
   16198                 :         109 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_TIMESTAMP_N, $3, @1);
   16199                 :             :                 }
   16200                 :             :             | LOCALTIME
   16201                 :             :                 {
   16202                 :          16 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME, -1, @1);
   16203                 :             :                 }
   16204                 :             :             | LOCALTIME '(' Iconst ')'
   16205                 :             :                 {
   16206                 :          16 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIME_N, $3, @1);
   16207                 :             :                 }
   16208                 :             :             | LOCALTIMESTAMP
   16209                 :             :                 {
   16210                 :          24 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP, -1, @1);
   16211                 :             :                 }
   16212                 :             :             | LOCALTIMESTAMP '(' Iconst ')'
   16213                 :             :                 {
   16214                 :          16 :                     $$ = makeSQLValueFunction(SVFOP_LOCALTIMESTAMP_N, $3, @1);
   16215                 :             :                 }
   16216                 :             :             | CURRENT_ROLE
   16217                 :             :                 {
   16218                 :          44 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_ROLE, -1, @1);
   16219                 :             :                 }
   16220                 :             :             | CURRENT_USER
   16221                 :             :                 {
   16222                 :         661 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_USER, -1, @1);
   16223                 :             :                 }
   16224                 :             :             | SESSION_USER
   16225                 :             :                 {
   16226                 :         313 :                     $$ = makeSQLValueFunction(SVFOP_SESSION_USER, -1, @1);
   16227                 :             :                 }
   16228                 :             :             | SYSTEM_USER
   16229                 :             :                 {
   16230                 :          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("system_user"),
   16231                 :             :                                                NIL,
   16232                 :             :                                                COERCE_SQL_SYNTAX,
   16233                 :             :                                                @1);
   16234                 :             :                 }
   16235                 :             :             | USER
   16236                 :             :                 {
   16237                 :          16 :                     $$ = makeSQLValueFunction(SVFOP_USER, -1, @1);
   16238                 :             :                 }
   16239                 :             :             | CURRENT_CATALOG
   16240                 :             :                 {
   16241                 :          35 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_CATALOG, -1, @1);
   16242                 :             :                 }
   16243                 :             :             | CURRENT_SCHEMA
   16244                 :             :                 {
   16245                 :          20 :                     $$ = makeSQLValueFunction(SVFOP_CURRENT_SCHEMA, -1, @1);
   16246                 :             :                 }
   16247                 :             :             | CAST '(' a_expr AS Typename ')'
   16248                 :       37145 :                 { $$ = makeTypeCast($3, $5, @1); }
   16249                 :             :             | EXTRACT '(' extract_list ')'
   16250                 :             :                 {
   16251                 :         892 :                     $$ = (Node *) makeFuncCall(SystemFuncName("extract"),
   16252                 :         892 :                                                $3,
   16253                 :             :                                                COERCE_SQL_SYNTAX,
   16254                 :         892 :                                                @1);
   16255                 :             :                 }
   16256                 :             :             | NORMALIZE '(' a_expr ')'
   16257                 :             :                 {
   16258                 :          12 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   16259                 :          12 :                                                list_make1($3),
   16260                 :             :                                                COERCE_SQL_SYNTAX,
   16261                 :          12 :                                                @1);
   16262                 :             :                 }
   16263                 :             :             | NORMALIZE '(' a_expr ',' unicode_normal_form ')'
   16264                 :             :                 {
   16265                 :         152 :                     $$ = (Node *) makeFuncCall(SystemFuncName("normalize"),
   16266                 :          76 :                                                list_make2($3, makeStringConst($5, @5)),
   16267                 :             :                                                COERCE_SQL_SYNTAX,
   16268                 :          76 :                                                @1);
   16269                 :             :                 }
   16270                 :             :             | OVERLAY '(' overlay_list ')'
   16271                 :             :                 {
   16272                 :          54 :                     $$ = (Node *) makeFuncCall(SystemFuncName("overlay"),
   16273                 :          54 :                                                $3,
   16274                 :             :                                                COERCE_SQL_SYNTAX,
   16275                 :          54 :                                                @1);
   16276                 :             :                 }
   16277                 :             :             | OVERLAY '(' func_arg_list_opt ')'
   16278                 :             :                 {
   16279                 :             :                     /*
   16280                 :             :                      * allow functions named overlay() to be called without
   16281                 :             :                      * special syntax
   16282                 :             :                      */
   16283                 :           0 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("overlay")),
   16284                 :           0 :                                                $3,
   16285                 :             :                                                COERCE_EXPLICIT_CALL,
   16286                 :           0 :                                                @1);
   16287                 :             :                 }
   16288                 :             :             | POSITION '(' position_list ')'
   16289                 :             :                 {
   16290                 :             :                     /*
   16291                 :             :                      * position(A in B) is converted to position(B, A)
   16292                 :             :                      *
   16293                 :             :                      * We deliberately don't offer a "plain syntax" option
   16294                 :             :                      * for position(), because the reversal of the arguments
   16295                 :             :                      * creates too much risk of confusion.
   16296                 :             :                      */
   16297                 :         279 :                     $$ = (Node *) makeFuncCall(SystemFuncName("position"),
   16298                 :         279 :                                                $3,
   16299                 :             :                                                COERCE_SQL_SYNTAX,
   16300                 :         279 :                                                @1);
   16301                 :             :                 }
   16302                 :             :             | SUBSTRING '(' substr_list ')'
   16303                 :             :                 {
   16304                 :             :                     /* substring(A from B for C) is converted to
   16305                 :             :                      * substring(A, B, C) - thomas 2000-11-28
   16306                 :             :                      */
   16307                 :         475 :                     $$ = (Node *) makeFuncCall(SystemFuncName("substring"),
   16308                 :         475 :                                                $3,
   16309                 :             :                                                COERCE_SQL_SYNTAX,
   16310                 :         475 :                                                @1);
   16311                 :             :                 }
   16312                 :             :             | SUBSTRING '(' func_arg_list_opt ')'
   16313                 :             :                 {
   16314                 :             :                     /*
   16315                 :             :                      * allow functions named substring() to be called without
   16316                 :             :                      * special syntax
   16317                 :             :                      */
   16318                 :         200 :                     $$ = (Node *) makeFuncCall(list_make1(makeString("substring")),
   16319                 :         200 :                                                $3,
   16320                 :             :                                                COERCE_EXPLICIT_CALL,
   16321                 :         200 :                                                @1);
   16322                 :             :                 }
   16323                 :             :             | TREAT '(' a_expr AS Typename ')'
   16324                 :             :                 {
   16325                 :             :                     /* TREAT(expr AS target) converts expr of a particular type to target,
   16326                 :             :                      * which is defined to be a subtype of the original expression.
   16327                 :             :                      * In SQL99, this is intended for use with structured UDTs,
   16328                 :             :                      * but let's make this a generally useful form allowing stronger
   16329                 :             :                      * coercions than are handled by implicit casting.
   16330                 :             :                      *
   16331                 :             :                      * Convert SystemTypeName() to SystemFuncName() even though
   16332                 :             :                      * at the moment they result in the same thing.
   16333                 :             :                      */
   16334                 :           0 :                     $$ = (Node *) makeFuncCall(SystemFuncName(strVal(llast($5->names))),
   16335                 :           0 :                                                list_make1($3),
   16336                 :             :                                                COERCE_EXPLICIT_CALL,
   16337                 :           0 :                                                @1);
   16338                 :             :                 }
   16339                 :             :             | TRIM '(' BOTH trim_list ')'
   16340                 :             :                 {
   16341                 :             :                     /* various trim expressions are defined in SQL
   16342                 :             :                      * - thomas 1997-07-19
   16343                 :             :                      */
   16344                 :           8 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16345                 :           8 :                                                $4,
   16346                 :             :                                                COERCE_SQL_SYNTAX,
   16347                 :           8 :                                                @1);
   16348                 :             :                 }
   16349                 :             :             | TRIM '(' LEADING trim_list ')'
   16350                 :             :                 {
   16351                 :          16 :                     $$ = (Node *) makeFuncCall(SystemFuncName("ltrim"),
   16352                 :          16 :                                                $4,
   16353                 :             :                                                COERCE_SQL_SYNTAX,
   16354                 :          16 :                                                @1);
   16355                 :             :                 }
   16356                 :             :             | TRIM '(' TRAILING trim_list ')'
   16357                 :             :                 {
   16358                 :         380 :                     $$ = (Node *) makeFuncCall(SystemFuncName("rtrim"),
   16359                 :         380 :                                                $4,
   16360                 :             :                                                COERCE_SQL_SYNTAX,
   16361                 :         380 :                                                @1);
   16362                 :             :                 }
   16363                 :             :             | TRIM '(' trim_list ')'
   16364                 :             :                 {
   16365                 :          64 :                     $$ = (Node *) makeFuncCall(SystemFuncName("btrim"),
   16366                 :          64 :                                                $3,
   16367                 :             :                                                COERCE_SQL_SYNTAX,
   16368                 :          64 :                                                @1);
   16369                 :             :                 }
   16370                 :             :             | NULLIF '(' a_expr ',' a_expr ')'
   16371                 :             :                 {
   16372                 :         344 :                     $$ = (Node *) makeSimpleA_Expr(AEXPR_NULLIF, "=", $3, $5, @1);
   16373                 :             :                 }
   16374                 :             :             | COALESCE '(' expr_list ')'
   16375                 :             :                 {
   16376                 :        2089 :                     CoalesceExpr *c = makeNode(CoalesceExpr);
   16377                 :             : 
   16378                 :        2089 :                     c->args = $3;
   16379                 :        2089 :                     c->location = @1;
   16380                 :        2089 :                     $$ = (Node *) c;
   16381                 :             :                 }
   16382                 :             :             | GREATEST '(' expr_list ')'
   16383                 :             :                 {
   16384                 :         106 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16385                 :             : 
   16386                 :         106 :                     v->args = $3;
   16387                 :         106 :                     v->op = IS_GREATEST;
   16388                 :         106 :                     v->location = @1;
   16389                 :         106 :                     $$ = (Node *) v;
   16390                 :             :                 }
   16391                 :             :             | LEAST '(' expr_list ')'
   16392                 :             :                 {
   16393                 :         100 :                     MinMaxExpr *v = makeNode(MinMaxExpr);
   16394                 :             : 
   16395                 :         100 :                     v->args = $3;
   16396                 :         100 :                     v->op = IS_LEAST;
   16397                 :         100 :                     v->location = @1;
   16398                 :         100 :                     $$ = (Node *) v;
   16399                 :             :                 }
   16400                 :             :             | XMLCONCAT '(' expr_list ')'
   16401                 :             :                 {
   16402                 :          41 :                     $$ = makeXmlExpr(IS_XMLCONCAT, NULL, NIL, $3, @1);
   16403                 :             :                 }
   16404                 :             :             | XMLELEMENT '(' NAME_P ColLabel ')'
   16405                 :             :                 {
   16406                 :           4 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, NIL, @1);
   16407                 :             :                 }
   16408                 :             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ')'
   16409                 :             :                 {
   16410                 :          24 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, NIL, @1);
   16411                 :             :                 }
   16412                 :             :             | XMLELEMENT '(' NAME_P ColLabel ',' expr_list ')'
   16413                 :             :                 {
   16414                 :          77 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, NIL, $6, @1);
   16415                 :             :                 }
   16416                 :             :             | XMLELEMENT '(' NAME_P ColLabel ',' xml_attributes ',' expr_list ')'
   16417                 :             :                 {
   16418                 :          13 :                     $$ = makeXmlExpr(IS_XMLELEMENT, $4, $6, $8, @1);
   16419                 :             :                 }
   16420                 :             :             | XMLEXISTS '(' c_expr xmlexists_argument ')'
   16421                 :             :                 {
   16422                 :             :                     /* xmlexists(A PASSING [BY REF] B [BY REF]) is
   16423                 :             :                      * converted to xmlexists(A, B)*/
   16424                 :          36 :                     $$ = (Node *) makeFuncCall(SystemFuncName("xmlexists"),
   16425                 :          36 :                                                list_make2($3, $4),
   16426                 :             :                                                COERCE_SQL_SYNTAX,
   16427                 :          36 :                                                @1);
   16428                 :             :                 }
   16429                 :             :             | XMLFOREST '(' labeled_expr_list ')'
   16430                 :             :                 {
   16431                 :          21 :                     $$ = makeXmlExpr(IS_XMLFOREST, NULL, $3, NIL, @1);
   16432                 :             :                 }
   16433                 :             :             | XMLPARSE '(' document_or_content a_expr xml_whitespace_option ')'
   16434                 :             :                 {
   16435                 :             :                     XmlExpr *x = (XmlExpr *)
   16436                 :         186 :                         makeXmlExpr(IS_XMLPARSE, NULL, NIL,
   16437                 :          93 :                                     list_make2($4, makeBoolAConst($5, -1)),
   16438                 :          93 :                                     @1);
   16439                 :             : 
   16440                 :          93 :                     x->xmloption = $3;
   16441                 :          93 :                     $$ = (Node *) x;
   16442                 :             :                 }
   16443                 :             :             | XMLPI '(' NAME_P ColLabel ')'
   16444                 :             :                 {
   16445                 :          20 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, NIL, @1);
   16446                 :             :                 }
   16447                 :             :             | XMLPI '(' NAME_P ColLabel ',' a_expr ')'
   16448                 :             :                 {
   16449                 :          33 :                     $$ = makeXmlExpr(IS_XMLPI, $4, NULL, list_make1($6), @1);
   16450                 :             :                 }
   16451                 :             :             | XMLROOT '(' a_expr ',' xml_root_version opt_xml_root_standalone ')'
   16452                 :             :                 {
   16453                 :          45 :                     $$ = makeXmlExpr(IS_XMLROOT, NULL, NIL,
   16454                 :          45 :                                      list_make3($3, $5, $6), @1);
   16455                 :             :                 }
   16456                 :             :             | XMLSERIALIZE '(' document_or_content a_expr AS SimpleTypename xml_indent_option ')'
   16457                 :             :                 {
   16458                 :         144 :                     XmlSerialize *n = makeNode(XmlSerialize);
   16459                 :             : 
   16460                 :         144 :                     n->xmloption = $3;
   16461                 :         144 :                     n->expr = $4;
   16462                 :         144 :                     n->typeName = $6;
   16463                 :         144 :                     n->indent = $7;
   16464                 :         144 :                     n->location = @1;
   16465                 :         144 :                     $$ = (Node *) n;
   16466                 :             :                 }
   16467                 :             :             | JSON_OBJECT '(' func_arg_list ')'
   16468                 :             :                 {
   16469                 :             :                     /* Support for legacy (non-standard) json_object() */
   16470                 :          60 :                     $$ = (Node *) makeFuncCall(SystemFuncName("json_object"),
   16471                 :          60 :                                                $3, COERCE_EXPLICIT_CALL, @1);
   16472                 :             :                 }
   16473                 :             :             | JSON_OBJECT '(' json_name_and_value_list
   16474                 :             :                 json_object_constructor_null_clause_opt
   16475                 :             :                 json_key_uniqueness_constraint_opt
   16476                 :             :                 json_returning_clause_opt ')'
   16477                 :             :                 {
   16478                 :         338 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16479                 :             : 
   16480                 :         338 :                     n->exprs = $3;
   16481                 :         338 :                     n->absent_on_null = $4;
   16482                 :         338 :                     n->unique = $5;
   16483                 :         338 :                     n->output = (JsonOutput *) $6;
   16484                 :         338 :                     n->location = @1;
   16485                 :         338 :                     $$ = (Node *) n;
   16486                 :             :                 }
   16487                 :             :             | JSON_OBJECT '(' json_returning_clause_opt ')'
   16488                 :             :                 {
   16489                 :          60 :                     JsonObjectConstructor *n = makeNode(JsonObjectConstructor);
   16490                 :             : 
   16491                 :          60 :                     n->exprs = NULL;
   16492                 :          60 :                     n->absent_on_null = false;
   16493                 :          60 :                     n->unique = false;
   16494                 :          60 :                     n->output = (JsonOutput *) $3;
   16495                 :          60 :                     n->location = @1;
   16496                 :          60 :                     $$ = (Node *) n;
   16497                 :             :                 }
   16498                 :             :             | JSON_ARRAY '('
   16499                 :             :                 json_value_expr_list
   16500                 :             :                 json_array_constructor_null_clause_opt
   16501                 :             :                 json_returning_clause_opt
   16502                 :             :             ')'
   16503                 :             :                 {
   16504                 :         168 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16505                 :             : 
   16506                 :         168 :                     n->exprs = $3;
   16507                 :         168 :                     n->absent_on_null = $4;
   16508                 :         168 :                     n->output = (JsonOutput *) $5;
   16509                 :         168 :                     n->location = @1;
   16510                 :         168 :                     $$ = (Node *) n;
   16511                 :             :                 }
   16512                 :             :             | JSON_ARRAY '('
   16513                 :             :                 select_no_parens
   16514                 :             :                 json_format_clause_opt
   16515                 :             :                 /* json_array_constructor_null_clause_opt */
   16516                 :             :                 json_returning_clause_opt
   16517                 :             :             ')'
   16518                 :             :                 {
   16519                 :          96 :                     JsonArrayQueryConstructor *n = makeNode(JsonArrayQueryConstructor);
   16520                 :             : 
   16521                 :          96 :                     n->query = $3;
   16522                 :          96 :                     n->format = (JsonFormat *) $4;
   16523                 :          96 :                     n->absent_on_null = true;    /* XXX */
   16524                 :          96 :                     n->output = (JsonOutput *) $5;
   16525                 :          96 :                     n->location = @1;
   16526                 :          96 :                     $$ = (Node *) n;
   16527                 :             :                 }
   16528                 :             :             | JSON_ARRAY '('
   16529                 :             :                 json_returning_clause_opt
   16530                 :             :             ')'
   16531                 :             :                 {
   16532                 :          56 :                     JsonArrayConstructor *n = makeNode(JsonArrayConstructor);
   16533                 :             : 
   16534                 :          56 :                     n->exprs = NIL;
   16535                 :          56 :                     n->absent_on_null = true;
   16536                 :          56 :                     n->output = (JsonOutput *) $3;
   16537                 :          56 :                     n->location = @1;
   16538                 :          56 :                     $$ = (Node *) n;
   16539                 :             :                 }
   16540                 :             :             | JSON '(' json_value_expr json_key_uniqueness_constraint_opt ')'
   16541                 :             :                 {
   16542                 :         108 :                     JsonParseExpr *n = makeNode(JsonParseExpr);
   16543                 :             : 
   16544                 :         108 :                     n->expr = (JsonValueExpr *) $3;
   16545                 :         108 :                     n->unique_keys = $4;
   16546                 :         108 :                     n->output = NULL;
   16547                 :         108 :                     n->location = @1;
   16548                 :         108 :                     $$ = (Node *) n;
   16549                 :             :                 }
   16550                 :             :             | JSON_SCALAR '(' a_expr ')'
   16551                 :             :                 {
   16552                 :          70 :                     JsonScalarExpr *n = makeNode(JsonScalarExpr);
   16553                 :             : 
   16554                 :          70 :                     n->expr = (Expr *) $3;
   16555                 :          70 :                     n->output = NULL;
   16556                 :          70 :                     n->location = @1;
   16557                 :          70 :                     $$ = (Node *) n;
   16558                 :             :                 }
   16559                 :             :             | JSON_SERIALIZE '(' json_value_expr json_returning_clause_opt ')'
   16560                 :             :                 {
   16561                 :          68 :                     JsonSerializeExpr *n = makeNode(JsonSerializeExpr);
   16562                 :             : 
   16563                 :          68 :                     n->expr = (JsonValueExpr *) $3;
   16564                 :          68 :                     n->output = (JsonOutput *) $4;
   16565                 :          68 :                     n->location = @1;
   16566                 :          68 :                     $$ = (Node *) n;
   16567                 :             :                 }
   16568                 :             :             | MERGE_ACTION '(' ')'
   16569                 :             :                 {
   16570                 :         152 :                     MergeSupportFunc *m = makeNode(MergeSupportFunc);
   16571                 :             : 
   16572                 :         152 :                     m->msftype = TEXTOID;
   16573                 :         152 :                     m->location = @1;
   16574                 :         152 :                     $$ = (Node *) m;
   16575                 :             :                 }
   16576                 :             :             | JSON_QUERY '('
   16577                 :             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16578                 :             :                 json_returning_clause_opt
   16579                 :             :                 json_wrapper_behavior
   16580                 :             :                 json_quotes_clause_opt
   16581                 :             :                 json_behavior_clause_opt
   16582                 :             :             ')'
   16583                 :             :                 {
   16584                 :         692 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16585                 :             : 
   16586                 :         692 :                     n->op = JSON_QUERY_OP;
   16587                 :         692 :                     n->context_item = (JsonValueExpr *) $3;
   16588                 :         692 :                     n->pathspec = $5;
   16589                 :         692 :                     n->passing = $6;
   16590                 :         692 :                     n->output = (JsonOutput *) $7;
   16591                 :         692 :                     n->wrapper = $8;
   16592                 :         692 :                     n->quotes = $9;
   16593                 :         692 :                     n->on_empty = (JsonBehavior *) linitial($10);
   16594                 :         692 :                     n->on_error = (JsonBehavior *) lsecond($10);
   16595                 :         692 :                     n->location = @1;
   16596                 :         692 :                     $$ = (Node *) n;
   16597                 :             :                 }
   16598                 :             :             | JSON_EXISTS '('
   16599                 :             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16600                 :             :                 json_on_error_clause_opt
   16601                 :             :             ')'
   16602                 :             :                 {
   16603                 :         112 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16604                 :             : 
   16605                 :         112 :                     n->op = JSON_EXISTS_OP;
   16606                 :         112 :                     n->context_item = (JsonValueExpr *) $3;
   16607                 :         112 :                     n->pathspec = $5;
   16608                 :         112 :                     n->passing = $6;
   16609                 :         112 :                     n->output = NULL;
   16610                 :         112 :                     n->on_error = (JsonBehavior *) $7;
   16611                 :         112 :                     n->location = @1;
   16612                 :         112 :                     $$ = (Node *) n;
   16613                 :             :                 }
   16614                 :             :             | JSON_VALUE '('
   16615                 :             :                 json_value_expr ',' a_expr json_passing_clause_opt
   16616                 :             :                 json_returning_clause_opt
   16617                 :             :                 json_behavior_clause_opt
   16618                 :             :             ')'
   16619                 :             :                 {
   16620                 :         444 :                     JsonFuncExpr *n = makeNode(JsonFuncExpr);
   16621                 :             : 
   16622                 :         444 :                     n->op = JSON_VALUE_OP;
   16623                 :         444 :                     n->context_item = (JsonValueExpr *) $3;
   16624                 :         444 :                     n->pathspec = $5;
   16625                 :         444 :                     n->passing = $6;
   16626                 :         444 :                     n->output = (JsonOutput *) $7;
   16627                 :         444 :                     n->on_empty = (JsonBehavior *) linitial($8);
   16628                 :         444 :                     n->on_error = (JsonBehavior *) lsecond($8);
   16629                 :         444 :                     n->location = @1;
   16630                 :         444 :                     $$ = (Node *) n;
   16631                 :             :                 }
   16632                 :             :             ;
   16633                 :             : 
   16634                 :             : 
   16635                 :             : /*
   16636                 :             :  * SQL/XML support
   16637                 :             :  */
   16638                 :             : xml_root_version: VERSION_P a_expr
   16639                 :          16 :                 { $$ = $2; }
   16640                 :             :             | VERSION_P NO VALUE_P
   16641                 :          29 :                 { $$ = makeNullAConst(-1); }
   16642                 :             :         ;
   16643                 :             : 
   16644                 :             : opt_xml_root_standalone: ',' STANDALONE_P YES_P
   16645                 :          17 :                 { $$ = makeIntConst(XML_STANDALONE_YES, -1); }
   16646                 :             :             | ',' STANDALONE_P NO
   16647                 :           8 :                 { $$ = makeIntConst(XML_STANDALONE_NO, -1); }
   16648                 :             :             | ',' STANDALONE_P NO VALUE_P
   16649                 :           8 :                 { $$ = makeIntConst(XML_STANDALONE_NO_VALUE, -1); }
   16650                 :             :             | /*EMPTY*/
   16651                 :          12 :                 { $$ = makeIntConst(XML_STANDALONE_OMITTED, -1); }
   16652                 :             :         ;
   16653                 :             : 
   16654                 :          37 : xml_attributes: XMLATTRIBUTES '(' labeled_expr_list ')' { $$ = $3; }
   16655                 :             :         ;
   16656                 :             : 
   16657                 :          58 : labeled_expr_list:  labeled_expr                    { $$ = list_make1($1); }
   16658                 :          95 :             | labeled_expr_list ',' labeled_expr    { $$ = lappend($1, $3); }
   16659                 :             :         ;
   16660                 :             : 
   16661                 :             : labeled_expr: a_expr AS ColLabel
   16662                 :             :                 {
   16663                 :          69 :                     $$ = makeNode(ResTarget);
   16664                 :          69 :                     $$->name = $3;
   16665                 :          69 :                     $$->indirection = NIL;
   16666                 :          69 :                     $$->val = (Node *) $1;
   16667                 :          69 :                     $$->location = @1;
   16668                 :             :                 }
   16669                 :             :             | a_expr
   16670                 :             :                 {
   16671                 :          84 :                     $$ = makeNode(ResTarget);
   16672                 :          84 :                     $$->name = NULL;
   16673                 :          84 :                     $$->indirection = NIL;
   16674                 :          84 :                     $$->val = (Node *) $1;
   16675                 :          84 :                     $$->location = @1;
   16676                 :             :                 }
   16677                 :             :         ;
   16678                 :             : 
   16679                 :         123 : document_or_content: DOCUMENT_P                     { $$ = XMLOPTION_DOCUMENT; }
   16680                 :         124 :             | CONTENT_P                             { $$ = XMLOPTION_CONTENT; }
   16681                 :             :         ;
   16682                 :             : 
   16683                 :          93 : xml_indent_option: INDENT                           { $$ = true; }
   16684                 :          23 :             | NO INDENT                             { $$ = false; }
   16685                 :          28 :             | /*EMPTY*/                             { $$ = false; }
   16686                 :             :         ;
   16687                 :             : 
   16688                 :           0 : xml_whitespace_option: PRESERVE WHITESPACE_P        { $$ = true; }
   16689                 :           1 :             | STRIP_P WHITESPACE_P                  { $$ = false; }
   16690                 :          92 :             | /*EMPTY*/                             { $$ = false; }
   16691                 :             :         ;
   16692                 :             : 
   16693                 :             : /* We allow several variants for SQL and other compatibility. */
   16694                 :             : xmlexists_argument:
   16695                 :             :             PASSING c_expr
   16696                 :             :                 {
   16697                 :         158 :                     $$ = $2;
   16698                 :             :                 }
   16699                 :             :             | PASSING c_expr xml_passing_mech
   16700                 :             :                 {
   16701                 :           0 :                     $$ = $2;
   16702                 :             :                 }
   16703                 :             :             | PASSING xml_passing_mech c_expr
   16704                 :             :                 {
   16705                 :          28 :                     $$ = $3;
   16706                 :             :                 }
   16707                 :             :             | PASSING xml_passing_mech c_expr xml_passing_mech
   16708                 :             :                 {
   16709                 :           4 :                     $$ = $3;
   16710                 :             :                 }
   16711                 :             :         ;
   16712                 :             : 
   16713                 :             : xml_passing_mech:
   16714                 :             :             BY REF_P
   16715                 :             :             | BY VALUE_P
   16716                 :             :         ;
   16717                 :             : 
   16718                 :             : /*****************************************************************************
   16719                 :             :  *
   16720                 :             :  * WAIT FOR LSN
   16721                 :             :  *
   16722                 :             :  *****************************************************************************/
   16723                 :             : 
   16724                 :             : WaitStmt:
   16725                 :             :             WAIT FOR LSN_P Sconst opt_wait_with_clause
   16726                 :             :                 {
   16727                 :         291 :                     WaitStmt *n = makeNode(WaitStmt);
   16728                 :         291 :                     n->lsn_literal = $4;
   16729                 :         291 :                     n->options = $5;
   16730                 :         291 :                     n->lsn_location = @4;
   16731                 :         291 :                     $$ = (Node *) n;
   16732                 :             :                 }
   16733                 :             :             ;
   16734                 :             : 
   16735                 :             : opt_wait_with_clause:
   16736                 :         275 :             WITH '(' utility_option_list ')'        { $$ = $3; }
   16737                 :          16 :             | /*EMPTY*/                             { $$ = NIL; }
   16738                 :             :             ;
   16739                 :             : 
   16740                 :             : /*
   16741                 :             :  * Aggregate decoration clauses
   16742                 :             :  */
   16743                 :             : within_group_clause:
   16744                 :         228 :             WITHIN GROUP_P '(' sort_clause ')'      { $$ = $4; }
   16745                 :      207742 :             | /*EMPTY*/                             { $$ = NIL; }
   16746                 :             :         ;
   16747                 :             : 
   16748                 :             : filter_clause:
   16749                 :         498 :             FILTER '(' WHERE a_expr ')'             { $$ = $4; }
   16750                 :      207764 :             | /*EMPTY*/                             { $$ = NULL; }
   16751                 :             :         ;
   16752                 :             : 
   16753                 :             : 
   16754                 :             : /*
   16755                 :             :  * Window Definitions
   16756                 :             :  */
   16757                 :             : null_treatment:
   16758                 :         156 :             IGNORE_P NULLS_P                        { $$ = PARSER_IGNORE_NULLS; }
   16759                 :          64 :             | RESPECT_P NULLS_P                     { $$ = PARSER_RESPECT_NULLS; }
   16760                 :      207750 :             | /*EMPTY*/                             { $$ = NO_NULLTREATMENT; }
   16761                 :             :         ;
   16762                 :             : 
   16763                 :             : window_clause:
   16764                 :         406 :             WINDOW window_definition_list           { $$ = $2; }
   16765                 :      312660 :             | /*EMPTY*/                             { $$ = NIL; }
   16766                 :             :         ;
   16767                 :             : 
   16768                 :             : window_definition_list:
   16769                 :         406 :             window_definition                       { $$ = list_make1($1); }
   16770                 :             :             | window_definition_list ',' window_definition
   16771                 :          20 :                                                     { $$ = lappend($1, $3); }
   16772                 :             :         ;
   16773                 :             : 
   16774                 :             : window_definition:
   16775                 :             :             ColId AS window_specification
   16776                 :             :                 {
   16777                 :         426 :                     WindowDef  *n = $3;
   16778                 :             : 
   16779                 :         426 :                     n->name = $1;
   16780                 :         426 :                     $$ = n;
   16781                 :             :                 }
   16782                 :             :         ;
   16783                 :             : 
   16784                 :             : over_clause: OVER window_specification
   16785                 :        2020 :                 { $$ = $2; }
   16786                 :             :             | OVER ColId
   16787                 :             :                 {
   16788                 :         790 :                     WindowDef  *n = makeNode(WindowDef);
   16789                 :             : 
   16790                 :         790 :                     n->name = $2;
   16791                 :         790 :                     n->refname = NULL;
   16792                 :         790 :                     n->partitionClause = NIL;
   16793                 :         790 :                     n->orderClause = NIL;
   16794                 :         790 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16795                 :         790 :                     n->startOffset = NULL;
   16796                 :         790 :                     n->endOffset = NULL;
   16797                 :         790 :                     n->location = @2;
   16798                 :         790 :                     $$ = n;
   16799                 :             :                 }
   16800                 :             :             | /*EMPTY*/
   16801                 :      205448 :                 { $$ = NULL; }
   16802                 :             :         ;
   16803                 :             : 
   16804                 :             : window_specification: '(' opt_existing_window_name opt_partition_clause
   16805                 :             :                         opt_sort_clause opt_frame_clause ')'
   16806                 :             :                 {
   16807                 :        2446 :                     WindowDef  *n = makeNode(WindowDef);
   16808                 :             : 
   16809                 :        2446 :                     n->name = NULL;
   16810                 :        2446 :                     n->refname = $2;
   16811                 :        2446 :                     n->partitionClause = $3;
   16812                 :        2446 :                     n->orderClause = $4;
   16813                 :             :                     /* copy relevant fields of opt_frame_clause */
   16814                 :        2446 :                     n->frameOptions = $5->frameOptions;
   16815                 :        2446 :                     n->startOffset = $5->startOffset;
   16816                 :        2446 :                     n->endOffset = $5->endOffset;
   16817                 :        2446 :                     n->location = @1;
   16818                 :        2446 :                     $$ = n;
   16819                 :             :                 }
   16820                 :             :         ;
   16821                 :             : 
   16822                 :             : /*
   16823                 :             :  * If we see PARTITION, RANGE, ROWS or GROUPS as the first token after the '('
   16824                 :             :  * of a window_specification, we want the assumption to be that there is
   16825                 :             :  * no existing_window_name; but those keywords are unreserved and so could
   16826                 :             :  * be ColIds.  We fix this by making them have the same precedence as IDENT
   16827                 :             :  * and giving the empty production here a slightly higher precedence, so
   16828                 :             :  * that the shift/reduce conflict is resolved in favor of reducing the rule.
   16829                 :             :  * These keywords are thus precluded from being an existing_window_name but
   16830                 :             :  * are not reserved for any other purpose.
   16831                 :             :  */
   16832                 :          36 : opt_existing_window_name: ColId                     { $$ = $1; }
   16833                 :        2414 :             | /*EMPTY*/             %prec Op        { $$ = NULL; }
   16834                 :             :         ;
   16835                 :             : 
   16836                 :         632 : opt_partition_clause: PARTITION BY expr_list        { $$ = $3; }
   16837                 :        1814 :             | /*EMPTY*/                             { $$ = NIL; }
   16838                 :             :         ;
   16839                 :             : 
   16840                 :             : /*
   16841                 :             :  * For frame clauses, we return a WindowDef, but only some fields are used:
   16842                 :             :  * frameOptions, startOffset, and endOffset.
   16843                 :             :  */
   16844                 :             : opt_frame_clause:
   16845                 :             :             RANGE frame_extent opt_window_exclusion_clause
   16846                 :             :                 {
   16847                 :         546 :                     WindowDef  *n = $2;
   16848                 :             : 
   16849                 :         546 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_RANGE;
   16850                 :         546 :                     n->frameOptions |= $3;
   16851                 :         546 :                     $$ = n;
   16852                 :             :                 }
   16853                 :             :             | ROWS frame_extent opt_window_exclusion_clause
   16854                 :             :                 {
   16855                 :         510 :                     WindowDef  *n = $2;
   16856                 :             : 
   16857                 :         510 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_ROWS;
   16858                 :         510 :                     n->frameOptions |= $3;
   16859                 :         510 :                     $$ = n;
   16860                 :             :                 }
   16861                 :             :             | GROUPS frame_extent opt_window_exclusion_clause
   16862                 :             :                 {
   16863                 :         156 :                     WindowDef  *n = $2;
   16864                 :             : 
   16865                 :         156 :                     n->frameOptions |= FRAMEOPTION_NONDEFAULT | FRAMEOPTION_GROUPS;
   16866                 :         156 :                     n->frameOptions |= $3;
   16867                 :         156 :                     $$ = n;
   16868                 :             :                 }
   16869                 :             :             | /*EMPTY*/
   16870                 :             :                 {
   16871                 :        1234 :                     WindowDef  *n = makeNode(WindowDef);
   16872                 :             : 
   16873                 :        1234 :                     n->frameOptions = FRAMEOPTION_DEFAULTS;
   16874                 :        1234 :                     n->startOffset = NULL;
   16875                 :        1234 :                     n->endOffset = NULL;
   16876                 :        1234 :                     $$ = n;
   16877                 :             :                 }
   16878                 :             :         ;
   16879                 :             : 
   16880                 :             : frame_extent: frame_bound
   16881                 :             :                 {
   16882                 :           8 :                     WindowDef  *n = $1;
   16883                 :             : 
   16884                 :             :                     /* reject invalid cases */
   16885         [ -  + ]:           8 :                     if (n->frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16886         [ #  # ]:           0 :                         ereport(ERROR,
   16887                 :             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16888                 :             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16889                 :             :                                  parser_errposition(@1)));
   16890         [ -  + ]:           8 :                     if (n->frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING)
   16891         [ #  # ]:           0 :                         ereport(ERROR,
   16892                 :             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16893                 :             :                                  errmsg("frame starting from following row cannot end with current row"),
   16894                 :             :                                  parser_errposition(@1)));
   16895                 :           8 :                     n->frameOptions |= FRAMEOPTION_END_CURRENT_ROW;
   16896                 :           8 :                     $$ = n;
   16897                 :             :                 }
   16898                 :             :             | BETWEEN frame_bound AND frame_bound
   16899                 :             :                 {
   16900                 :        1204 :                     WindowDef  *n1 = $2;
   16901                 :        1204 :                     WindowDef  *n2 = $4;
   16902                 :             : 
   16903                 :             :                     /* form merged options */
   16904                 :        1204 :                     int     frameOptions = n1->frameOptions;
   16905                 :             :                     /* shift converts START_ options to END_ options */
   16906                 :        1204 :                     frameOptions |= n2->frameOptions << 1;
   16907                 :        1204 :                     frameOptions |= FRAMEOPTION_BETWEEN;
   16908                 :             :                     /* reject invalid cases */
   16909         [ -  + ]:        1204 :                     if (frameOptions & FRAMEOPTION_START_UNBOUNDED_FOLLOWING)
   16910         [ #  # ]:           0 :                         ereport(ERROR,
   16911                 :             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16912                 :             :                                  errmsg("frame start cannot be UNBOUNDED FOLLOWING"),
   16913                 :             :                                  parser_errposition(@2)));
   16914         [ -  + ]:        1204 :                     if (frameOptions & FRAMEOPTION_END_UNBOUNDED_PRECEDING)
   16915         [ #  # ]:           0 :                         ereport(ERROR,
   16916                 :             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16917                 :             :                                  errmsg("frame end cannot be UNBOUNDED PRECEDING"),
   16918                 :             :                                  parser_errposition(@4)));
   16919         [ +  + ]:        1204 :                     if ((frameOptions & FRAMEOPTION_START_CURRENT_ROW) &&
   16920         [ -  + ]:         336 :                         (frameOptions & FRAMEOPTION_END_OFFSET_PRECEDING))
   16921         [ #  # ]:           0 :                         ereport(ERROR,
   16922                 :             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16923                 :             :                                  errmsg("frame starting from current row cannot have preceding rows"),
   16924                 :             :                                  parser_errposition(@4)));
   16925         [ +  + ]:        1204 :                     if ((frameOptions & FRAMEOPTION_START_OFFSET_FOLLOWING) &&
   16926         [ -  + ]:         120 :                         (frameOptions & (FRAMEOPTION_END_OFFSET_PRECEDING |
   16927                 :             :                                          FRAMEOPTION_END_CURRENT_ROW)))
   16928         [ #  # ]:           0 :                         ereport(ERROR,
   16929                 :             :                                 (errcode(ERRCODE_WINDOWING_ERROR),
   16930                 :             :                                  errmsg("frame starting from following row cannot have preceding rows"),
   16931                 :             :                                  parser_errposition(@4)));
   16932                 :        1204 :                     n1->frameOptions = frameOptions;
   16933                 :        1204 :                     n1->endOffset = n2->startOffset;
   16934                 :        1204 :                     $$ = n1;
   16935                 :             :                 }
   16936                 :             :         ;
   16937                 :             : 
   16938                 :             : /*
   16939                 :             :  * This is used for both frame start and frame end, with output set up on
   16940                 :             :  * the assumption it's frame start; the frame_extent productions must reject
   16941                 :             :  * invalid cases.
   16942                 :             :  */
   16943                 :             : frame_bound:
   16944                 :             :             UNBOUNDED PRECEDING
   16945                 :             :                 {
   16946                 :         192 :                     WindowDef  *n = makeNode(WindowDef);
   16947                 :             : 
   16948                 :         192 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_PRECEDING;
   16949                 :         192 :                     n->startOffset = NULL;
   16950                 :         192 :                     n->endOffset = NULL;
   16951                 :         192 :                     $$ = n;
   16952                 :             :                 }
   16953                 :             :             | UNBOUNDED FOLLOWING
   16954                 :             :                 {
   16955                 :         266 :                     WindowDef  *n = makeNode(WindowDef);
   16956                 :             : 
   16957                 :         266 :                     n->frameOptions = FRAMEOPTION_START_UNBOUNDED_FOLLOWING;
   16958                 :         266 :                     n->startOffset = NULL;
   16959                 :         266 :                     n->endOffset = NULL;
   16960                 :         266 :                     $$ = n;
   16961                 :             :                 }
   16962                 :             :             | CURRENT_P ROW
   16963                 :             :                 {
   16964                 :         464 :                     WindowDef  *n = makeNode(WindowDef);
   16965                 :             : 
   16966                 :         464 :                     n->frameOptions = FRAMEOPTION_START_CURRENT_ROW;
   16967                 :         464 :                     n->startOffset = NULL;
   16968                 :         464 :                     n->endOffset = NULL;
   16969                 :         464 :                     $$ = n;
   16970                 :             :                 }
   16971                 :             :             | a_expr PRECEDING
   16972                 :             :                 {
   16973                 :         664 :                     WindowDef  *n = makeNode(WindowDef);
   16974                 :             : 
   16975                 :         664 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_PRECEDING;
   16976                 :         664 :                     n->startOffset = $1;
   16977                 :         664 :                     n->endOffset = NULL;
   16978                 :         664 :                     $$ = n;
   16979                 :             :                 }
   16980                 :             :             | a_expr FOLLOWING
   16981                 :             :                 {
   16982                 :         830 :                     WindowDef  *n = makeNode(WindowDef);
   16983                 :             : 
   16984                 :         830 :                     n->frameOptions = FRAMEOPTION_START_OFFSET_FOLLOWING;
   16985                 :         830 :                     n->startOffset = $1;
   16986                 :         830 :                     n->endOffset = NULL;
   16987                 :         830 :                     $$ = n;
   16988                 :             :                 }
   16989                 :             :         ;
   16990                 :             : 
   16991                 :             : opt_window_exclusion_clause:
   16992                 :          92 :             EXCLUDE CURRENT_P ROW   { $$ = FRAMEOPTION_EXCLUDE_CURRENT_ROW; }
   16993                 :          72 :             | EXCLUDE GROUP_P       { $$ = FRAMEOPTION_EXCLUDE_GROUP; }
   16994                 :         108 :             | EXCLUDE TIES          { $$ = FRAMEOPTION_EXCLUDE_TIES; }
   16995                 :          12 :             | EXCLUDE NO OTHERS     { $$ = 0; }
   16996                 :         928 :             | /*EMPTY*/             { $$ = 0; }
   16997                 :             :         ;
   16998                 :             : 
   16999                 :             : 
   17000                 :             : /*
   17001                 :             :  * Supporting nonterminals for expressions.
   17002                 :             :  */
   17003                 :             : 
   17004                 :             : /* Explicit row production.
   17005                 :             :  *
   17006                 :             :  * SQL99 allows an optional ROW keyword, so we can now do single-element rows
   17007                 :             :  * without conflicting with the parenthesized a_expr production.  Without the
   17008                 :             :  * ROW keyword, there must be more than one a_expr inside the parens.
   17009                 :             :  */
   17010                 :           0 : row:        ROW '(' expr_list ')'                   { $$ = $3; }
   17011                 :           0 :             | ROW '(' ')'                           { $$ = NIL; }
   17012                 :        1162 :             | '(' expr_list ',' a_expr ')'          { $$ = lappend($2, $4); }
   17013                 :             :         ;
   17014                 :             : 
   17015                 :        2677 : explicit_row:   ROW '(' expr_list ')'               { $$ = $3; }
   17016                 :          24 :             | ROW '(' ')'                           { $$ = NIL; }
   17017                 :             :         ;
   17018                 :             : 
   17019                 :        1825 : implicit_row:   '(' expr_list ',' a_expr ')'        { $$ = lappend($2, $4); }
   17020                 :             :         ;
   17021                 :             : 
   17022                 :       11036 : sub_type:   ANY                                     { $$ = ANY_SUBLINK; }
   17023                 :           0 :             | SOME                                  { $$ = ANY_SUBLINK; }
   17024                 :         221 :             | ALL                                   { $$ = ALL_SUBLINK; }
   17025                 :             :         ;
   17026                 :             : 
   17027                 :        7538 : all_Op:     Op                                      { $$ = $1; }
   17028                 :       17506 :             | MathOp                                { $$ = $1; }
   17029                 :             :         ;
   17030                 :             : 
   17031                 :          25 : MathOp:      '+'                                    { $$ = "+"; }
   17032                 :          34 :             | '-'                                   { $$ = "-"; }
   17033                 :          95 :             | '*'                                   { $$ = "*"; }
   17034                 :           0 :             | '/'                                   { $$ = "/"; }
   17035                 :           4 :             | '%'                                   { $$ = "%"; }
   17036                 :           0 :             | '^'                                   { $$ = "^"; }
   17037                 :         565 :             | '<'                                    { $$ = "<"; }
   17038                 :         498 :             | '>'                                    { $$ = ">"; }
   17039                 :       14917 :             | '='                                   { $$ = "="; }
   17040                 :         466 :             | LESS_EQUALS                           { $$ = "<="; }
   17041                 :         460 :             | GREATER_EQUALS                        { $$ = ">="; }
   17042                 :         442 :             | NOT_EQUALS                            { $$ = "<>"; }
   17043                 :             :         ;
   17044                 :             : 
   17045                 :             : qual_Op:    Op
   17046                 :       28000 :                     { $$ = list_make1(makeString($1)); }
   17047                 :             :             | OPERATOR '(' any_operator ')'
   17048                 :        9414 :                     { $$ = $3; }
   17049                 :             :         ;
   17050                 :             : 
   17051                 :             : qual_all_Op:
   17052                 :             :             all_Op
   17053                 :         787 :                     { $$ = list_make1(makeString($1)); }
   17054                 :             :             | OPERATOR '(' any_operator ')'
   17055                 :          17 :                     { $$ = $3; }
   17056                 :             :         ;
   17057                 :             : 
   17058                 :             : subquery_Op:
   17059                 :             :             all_Op
   17060                 :       11076 :                     { $$ = list_make1(makeString($1)); }
   17061                 :             :             | OPERATOR '(' any_operator ')'
   17062                 :         159 :                     { $$ = $3; }
   17063                 :             :             | LIKE
   17064                 :          16 :                     { $$ = list_make1(makeString("~~")); }
   17065                 :             :             | NOT_LA LIKE
   17066                 :           8 :                     { $$ = list_make1(makeString("!~~")); }
   17067                 :             :             | ILIKE
   17068                 :           8 :                     { $$ = list_make1(makeString("~~*")); }
   17069                 :             :             | NOT_LA ILIKE
   17070                 :           0 :                     { $$ = list_make1(makeString("!~~*")); }
   17071                 :             : /* cannot put SIMILAR TO here, because SIMILAR TO is a hack.
   17072                 :             :  * the regular expression is preprocessed by a function (similar_to_escape),
   17073                 :             :  * and the ~ operator for posix regular expressions is used.
   17074                 :             :  *        x SIMILAR TO y     ->    x ~ similar_to_escape(y)
   17075                 :             :  * this transformation is made on the fly by the parser upwards.
   17076                 :             :  * however the SubLink structure which handles any/some/all stuff
   17077                 :             :  * is not ready for such a thing.
   17078                 :             :  */
   17079                 :             :             ;
   17080                 :             : 
   17081                 :             : expr_list:  a_expr
   17082                 :             :                 {
   17083                 :      107342 :                     $$ = list_make1($1);
   17084                 :             :                 }
   17085                 :             :             | expr_list ',' a_expr
   17086                 :             :                 {
   17087                 :       96131 :                     $$ = lappend($1, $3);
   17088                 :             :                 }
   17089                 :             :         ;
   17090                 :             : 
   17091                 :             : /* function arguments can have names */
   17092                 :             : func_arg_list:  func_arg_expr
   17093                 :             :                 {
   17094                 :      206716 :                     $$ = list_make1($1);
   17095                 :             :                 }
   17096                 :             :             | func_arg_list ',' func_arg_expr
   17097                 :             :                 {
   17098                 :      179835 :                     $$ = lappend($1, $3);
   17099                 :             :                 }
   17100                 :             :         ;
   17101                 :             : 
   17102                 :             : func_arg_expr:  a_expr
   17103                 :             :                 {
   17104                 :      362544 :                     $$ = $1;
   17105                 :             :                 }
   17106                 :             :             | param_name COLON_EQUALS a_expr
   17107                 :             :                 {
   17108                 :       22853 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   17109                 :             : 
   17110                 :       22853 :                     na->name = $1;
   17111                 :       22853 :                     na->arg = (Expr *) $3;
   17112                 :       22853 :                     na->argnumber = -1;      /* until determined */
   17113                 :       22853 :                     na->location = @1;
   17114                 :       22853 :                     $$ = (Node *) na;
   17115                 :             :                 }
   17116                 :             :             | param_name EQUALS_GREATER a_expr
   17117                 :             :                 {
   17118                 :        1652 :                     NamedArgExpr *na = makeNode(NamedArgExpr);
   17119                 :             : 
   17120                 :        1652 :                     na->name = $1;
   17121                 :        1652 :                     na->arg = (Expr *) $3;
   17122                 :        1652 :                     na->argnumber = -1;      /* until determined */
   17123                 :        1652 :                     na->location = @1;
   17124                 :        1652 :                     $$ = (Node *) na;
   17125                 :             :                 }
   17126                 :             :         ;
   17127                 :             : 
   17128                 :         200 : func_arg_list_opt:  func_arg_list                   { $$ = $1; }
   17129                 :           0 :             | /*EMPTY*/                             { $$ = NIL; }
   17130                 :             :         ;
   17131                 :             : 
   17132                 :        1103 : type_list:  Typename                                { $$ = list_make1($1); }
   17133                 :         323 :             | type_list ',' Typename                { $$ = lappend($1, $3); }
   17134                 :             :         ;
   17135                 :             : 
   17136                 :             : array_expr: '[' expr_list ']'
   17137                 :             :                 {
   17138                 :        5595 :                     $$ = makeAArrayExpr($2, @1, @3);
   17139                 :             :                 }
   17140                 :             :             | '[' array_expr_list ']'
   17141                 :             :                 {
   17142                 :         255 :                     $$ = makeAArrayExpr($2, @1, @3);
   17143                 :             :                 }
   17144                 :             :             | '[' ']'
   17145                 :             :                 {
   17146                 :          74 :                     $$ = makeAArrayExpr(NIL, @1, @2);
   17147                 :             :                 }
   17148                 :             :         ;
   17149                 :             : 
   17150                 :         255 : array_expr_list: array_expr                         { $$ = list_make1($1); }
   17151                 :         208 :             | array_expr_list ',' array_expr        { $$ = lappend($1, $3); }
   17152                 :             :         ;
   17153                 :             : 
   17154                 :             : 
   17155                 :             : extract_list:
   17156                 :             :             extract_arg FROM a_expr
   17157                 :             :                 {
   17158                 :         892 :                     $$ = list_make2(makeStringConst($1, @1), $3);
   17159                 :             :                 }
   17160                 :             :         ;
   17161                 :             : 
   17162                 :             : /* Allow delimited string Sconst in extract_arg as an SQL extension.
   17163                 :             :  * - thomas 2001-04-12
   17164                 :             :  */
   17165                 :             : extract_arg:
   17166                 :         720 :             IDENT                                   { $$ = $1; }
   17167                 :          48 :             | YEAR_P                                { $$ = "year"; }
   17168                 :          28 :             | MONTH_P                               { $$ = "month"; }
   17169                 :          36 :             | DAY_P                                 { $$ = "day"; }
   17170                 :          20 :             | HOUR_P                                { $$ = "hour"; }
   17171                 :          20 :             | MINUTE_P                              { $$ = "minute"; }
   17172                 :          20 :             | SECOND_P                              { $$ = "second"; }
   17173                 :           0 :             | Sconst                                { $$ = $1; }
   17174                 :             :         ;
   17175                 :             : 
   17176                 :             : unicode_normal_form:
   17177                 :          52 :             NFC                                     { $$ = "NFC"; }
   17178                 :          24 :             | NFD                                   { $$ = "NFD"; }
   17179                 :          12 :             | NFKC                                  { $$ = "NFKC"; }
   17180                 :          12 :             | NFKD                                  { $$ = "NFKD"; }
   17181                 :             :         ;
   17182                 :             : 
   17183                 :             : /* OVERLAY() arguments */
   17184                 :             : overlay_list:
   17185                 :             :             a_expr PLACING a_expr FROM a_expr FOR a_expr
   17186                 :             :                 {
   17187                 :             :                     /* overlay(A PLACING B FROM C FOR D) is converted to overlay(A, B, C, D) */
   17188                 :          22 :                     $$ = list_make4($1, $3, $5, $7);
   17189                 :             :                 }
   17190                 :             :             | a_expr PLACING a_expr FROM a_expr
   17191                 :             :                 {
   17192                 :             :                     /* overlay(A PLACING B FROM C) is converted to overlay(A, B, C) */
   17193                 :          32 :                     $$ = list_make3($1, $3, $5);
   17194                 :             :                 }
   17195                 :             :         ;
   17196                 :             : 
   17197                 :             : /* position_list uses b_expr not a_expr to avoid conflict with general IN */
   17198                 :             : position_list:
   17199                 :         279 :             b_expr IN_P b_expr                      { $$ = list_make2($3, $1); }
   17200                 :             :         ;
   17201                 :             : 
   17202                 :             : /*
   17203                 :             :  * SUBSTRING() arguments
   17204                 :             :  *
   17205                 :             :  * Note that SQL:1999 has both
   17206                 :             :  *     text FROM int FOR int
   17207                 :             :  * and
   17208                 :             :  *     text FROM pattern FOR escape
   17209                 :             :  *
   17210                 :             :  * In the parser we map them both to a call to the substring() function and
   17211                 :             :  * rely on type resolution to pick the right one.
   17212                 :             :  *
   17213                 :             :  * In SQL:2003, the second variant was changed to
   17214                 :             :  *     text SIMILAR pattern ESCAPE escape
   17215                 :             :  * We could in theory map that to a different function internally, but
   17216                 :             :  * since we still support the SQL:1999 version, we don't.  However,
   17217                 :             :  * ruleutils.c will reverse-list the call in the newer style.
   17218                 :             :  */
   17219                 :             : substr_list:
   17220                 :             :             a_expr FROM a_expr FOR a_expr
   17221                 :             :                 {
   17222                 :         101 :                     $$ = list_make3($1, $3, $5);
   17223                 :             :                 }
   17224                 :             :             | a_expr FOR a_expr FROM a_expr
   17225                 :             :                 {
   17226                 :             :                     /* not legal per SQL, but might as well allow it */
   17227                 :           0 :                     $$ = list_make3($1, $5, $3);
   17228                 :             :                 }
   17229                 :             :             | a_expr FROM a_expr
   17230                 :             :                 {
   17231                 :             :                     /*
   17232                 :             :                      * Because we aren't restricting data types here, this
   17233                 :             :                      * syntax can end up resolving to textregexsubstr().
   17234                 :             :                      * We've historically allowed that to happen, so continue
   17235                 :             :                      * to accept it.  However, ruleutils.c will reverse-list
   17236                 :             :                      * such a call in regular function call syntax.
   17237                 :             :                      */
   17238                 :         225 :                     $$ = list_make2($1, $3);
   17239                 :             :                 }
   17240                 :             :             | a_expr FOR a_expr
   17241                 :             :                 {
   17242                 :             :                     /* not legal per SQL */
   17243                 :             : 
   17244                 :             :                     /*
   17245                 :             :                      * Since there are no cases where this syntax allows
   17246                 :             :                      * a textual FOR value, we forcibly cast the argument
   17247                 :             :                      * to int4.  The possible matches in pg_proc are
   17248                 :             :                      * substring(text,int4) and substring(text,text),
   17249                 :             :                      * and we don't want the parser to choose the latter,
   17250                 :             :                      * which it is likely to do if the second argument
   17251                 :             :                      * is unknown or doesn't have an implicit cast to int4.
   17252                 :             :                      */
   17253                 :          31 :                     $$ = list_make3($1, makeIntConst(1, -1),
   17254                 :             :                                     makeTypeCast($3,
   17255                 :             :                                                  SystemTypeName("int4"), -1));
   17256                 :             :                 }
   17257                 :             :             | a_expr SIMILAR a_expr ESCAPE a_expr
   17258                 :             :                 {
   17259                 :         118 :                     $$ = list_make3($1, $3, $5);
   17260                 :             :                 }
   17261                 :             :         ;
   17262                 :             : 
   17263                 :         396 : trim_list:  a_expr FROM expr_list                   { $$ = lappend($3, $1); }
   17264                 :          16 :             | FROM expr_list                        { $$ = $2; }
   17265                 :          56 :             | expr_list                             { $$ = $1; }
   17266                 :             :         ;
   17267                 :             : 
   17268                 :             : /*
   17269                 :             :  * Define SQL-style CASE clause.
   17270                 :             :  * - Full specification
   17271                 :             :  *  CASE WHEN a = b THEN c ... ELSE d END
   17272                 :             :  * - Implicit argument
   17273                 :             :  *  CASE a WHEN b THEN c ... ELSE d END
   17274                 :             :  */
   17275                 :             : case_expr:  CASE case_arg when_clause_list case_default END_P
   17276                 :             :                 {
   17277                 :       25456 :                     CaseExpr   *c = makeNode(CaseExpr);
   17278                 :             : 
   17279                 :       25456 :                     c->casetype = InvalidOid; /* not analyzed yet */
   17280                 :       25456 :                     c->arg = (Expr *) $2;
   17281                 :       25456 :                     c->args = $3;
   17282                 :       25456 :                     c->defresult = (Expr *) $4;
   17283                 :       25456 :                     c->location = @1;
   17284                 :       25456 :                     $$ = (Node *) c;
   17285                 :             :                 }
   17286                 :             :         ;
   17287                 :             : 
   17288                 :             : when_clause_list:
   17289                 :             :             /* There must be at least one */
   17290                 :       25456 :             when_clause                             { $$ = list_make1($1); }
   17291                 :       19750 :             | when_clause_list when_clause          { $$ = lappend($1, $2); }
   17292                 :             :         ;
   17293                 :             : 
   17294                 :             : when_clause:
   17295                 :             :             WHEN a_expr THEN a_expr
   17296                 :             :                 {
   17297                 :       45206 :                     CaseWhen   *w = makeNode(CaseWhen);
   17298                 :             : 
   17299                 :       45206 :                     w->expr = (Expr *) $2;
   17300                 :       45206 :                     w->result = (Expr *) $4;
   17301                 :       45206 :                     w->location = @1;
   17302                 :       45206 :                     $$ = (Node *) w;
   17303                 :             :                 }
   17304                 :             :         ;
   17305                 :             : 
   17306                 :             : case_default:
   17307                 :       18950 :             ELSE a_expr                             { $$ = $2; }
   17308                 :        6506 :             | /*EMPTY*/                             { $$ = NULL; }
   17309                 :             :         ;
   17310                 :             : 
   17311                 :        5042 : case_arg:   a_expr                                  { $$ = $1; }
   17312                 :       20414 :             | /*EMPTY*/                             { $$ = NULL; }
   17313                 :             :         ;
   17314                 :             : 
   17315                 :             : columnref:  ColId
   17316                 :             :                 {
   17317                 :      464186 :                     $$ = makeColumnRef($1, NIL, @1, yyscanner);
   17318                 :             :                 }
   17319                 :             :             | ColId indirection
   17320                 :             :                 {
   17321                 :      693125 :                     $$ = makeColumnRef($1, $2, @1, yyscanner);
   17322                 :             :                 }
   17323                 :             :         ;
   17324                 :             : 
   17325                 :             : indirection_el:
   17326                 :             :             '.' attr_name
   17327                 :             :                 {
   17328                 :      940401 :                     $$ = (Node *) makeString($2);
   17329                 :             :                 }
   17330                 :             :             | '.' '*'
   17331                 :             :                 {
   17332                 :        4691 :                     $$ = (Node *) makeNode(A_Star);
   17333                 :             :                 }
   17334                 :             :             | '[' a_expr ']'
   17335                 :             :                 {
   17336                 :        8652 :                     A_Indices *ai = makeNode(A_Indices);
   17337                 :             : 
   17338                 :        8652 :                     ai->is_slice = false;
   17339                 :        8652 :                     ai->lidx = NULL;
   17340                 :        8652 :                     ai->uidx = $2;
   17341                 :        8652 :                     $$ = (Node *) ai;
   17342                 :             :                 }
   17343                 :             :             | '[' opt_slice_bound ':' opt_slice_bound ']'
   17344                 :             :                 {
   17345                 :         405 :                     A_Indices *ai = makeNode(A_Indices);
   17346                 :             : 
   17347                 :         405 :                     ai->is_slice = true;
   17348                 :         405 :                     ai->lidx = $2;
   17349                 :         405 :                     ai->uidx = $4;
   17350                 :         405 :                     $$ = (Node *) ai;
   17351                 :             :                 }
   17352                 :             :         ;
   17353                 :             : 
   17354                 :             : opt_slice_bound:
   17355                 :         690 :             a_expr                                  { $$ = $1; }
   17356                 :         120 :             | /*EMPTY*/                             { $$ = NULL; }
   17357                 :             :         ;
   17358                 :             : 
   17359                 :             : indirection:
   17360                 :      939187 :             indirection_el                          { $$ = list_make1($1); }
   17361                 :        2078 :             | indirection indirection_el            { $$ = lappend($1, $2); }
   17362                 :             :         ;
   17363                 :             : 
   17364                 :             : opt_indirection:
   17365                 :      123869 :             /*EMPTY*/                               { $$ = NIL; }
   17366                 :       12884 :             | opt_indirection indirection_el        { $$ = lappend($1, $2); }
   17367                 :             :         ;
   17368                 :             : 
   17369                 :             : opt_asymmetric: ASYMMETRIC
   17370                 :             :             | /*EMPTY*/
   17371                 :             :         ;
   17372                 :             : 
   17373                 :             : /* SQL/JSON support */
   17374                 :             : json_passing_clause_opt:
   17375                 :         232 :             PASSING json_arguments                  { $$ = $2; }
   17376                 :        1512 :             | /*EMPTY*/                             { $$ = NIL; }
   17377                 :             :         ;
   17378                 :             : 
   17379                 :             : json_arguments:
   17380                 :         232 :             json_argument                           { $$ = list_make1($1); }
   17381                 :          88 :             | json_arguments ',' json_argument      { $$ = lappend($1, $3); }
   17382                 :             :         ;
   17383                 :             : 
   17384                 :             : json_argument:
   17385                 :             :             json_value_expr AS ColLabel
   17386                 :             :             {
   17387                 :         320 :                 JsonArgument *n = makeNode(JsonArgument);
   17388                 :             : 
   17389                 :         320 :                 n->val = (JsonValueExpr *) $1;
   17390                 :         320 :                 n->name = $3;
   17391                 :         320 :                 $$ = (Node *) n;
   17392                 :             :             }
   17393                 :             :         ;
   17394                 :             : 
   17395                 :             : /* ARRAY is a noise word */
   17396                 :             : json_wrapper_behavior:
   17397                 :          28 :               WITHOUT WRAPPER                   { $$ = JSW_NONE; }
   17398                 :           0 :             | WITHOUT ARRAY WRAPPER             { $$ = JSW_NONE; }
   17399                 :          56 :             | WITH WRAPPER                      { $$ = JSW_UNCONDITIONAL; }
   17400                 :           8 :             | WITH ARRAY WRAPPER                { $$ = JSW_UNCONDITIONAL; }
   17401                 :           0 :             | WITH CONDITIONAL ARRAY WRAPPER    { $$ = JSW_CONDITIONAL; }
   17402                 :           8 :             | WITH UNCONDITIONAL ARRAY WRAPPER  { $$ = JSW_UNCONDITIONAL; }
   17403                 :          24 :             | WITH CONDITIONAL WRAPPER          { $$ = JSW_CONDITIONAL; }
   17404                 :           8 :             | WITH UNCONDITIONAL WRAPPER        { $$ = JSW_UNCONDITIONAL; }
   17405                 :        1532 :             | /* empty */                       { $$ = JSW_UNSPEC; }
   17406                 :             :         ;
   17407                 :             : 
   17408                 :             : json_behavior:
   17409                 :             :             DEFAULT a_expr
   17410                 :         360 :                 { $$ = (Node *) makeJsonBehavior(JSON_BEHAVIOR_DEFAULT, $2, @1); }
   17411                 :             :             | json_behavior_type
   17412                 :         488 :                 { $$ = (Node *) makeJsonBehavior($1, NULL, @1); }
   17413                 :             :         ;
   17414                 :             : 
   17415                 :             : json_behavior_type:
   17416                 :         340 :             ERROR_P     { $$ = JSON_BEHAVIOR_ERROR; }
   17417                 :          20 :             | NULL_P    { $$ = JSON_BEHAVIOR_NULL; }
   17418                 :          24 :             | TRUE_P    { $$ = JSON_BEHAVIOR_TRUE; }
   17419                 :           8 :             | FALSE_P   { $$ = JSON_BEHAVIOR_FALSE; }
   17420                 :          12 :             | UNKNOWN   { $$ = JSON_BEHAVIOR_UNKNOWN; }
   17421                 :          20 :             | EMPTY_P ARRAY { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17422                 :          48 :             | EMPTY_P OBJECT_P  { $$ = JSON_BEHAVIOR_EMPTY_OBJECT; }
   17423                 :             :             /* non-standard, for Oracle compatibility only */
   17424                 :          16 :             | EMPTY_P   { $$ = JSON_BEHAVIOR_EMPTY_ARRAY; }
   17425                 :             :         ;
   17426                 :             : 
   17427                 :             : json_behavior_clause_opt:
   17428                 :             :             json_behavior ON EMPTY_P
   17429                 :         220 :                 { $$ = list_make2($1, NULL); }
   17430                 :             :             | json_behavior ON ERROR_P
   17431                 :         372 :                 { $$ = list_make2(NULL, $1); }
   17432                 :             :             | json_behavior ON EMPTY_P json_behavior ON ERROR_P
   17433                 :          68 :                 { $$ = list_make2($1, $4); }
   17434                 :             :             | /* EMPTY */
   17435                 :        1448 :                 { $$ = list_make2(NULL, NULL); }
   17436                 :             :         ;
   17437                 :             : 
   17438                 :             : json_on_error_clause_opt:
   17439                 :             :             json_behavior ON ERROR_P
   17440                 :         116 :                 { $$ = $1; }
   17441                 :             :             | /* EMPTY */
   17442                 :         588 :                 { $$ = NULL; }
   17443                 :             :         ;
   17444                 :             : 
   17445                 :             : json_value_expr:
   17446                 :             :             a_expr json_format_clause_opt
   17447                 :             :             {
   17448                 :             :                 /* formatted_expr will be set during parse-analysis. */
   17449                 :        3314 :                 $$ = (Node *) makeJsonValueExpr((Expr *) $1, NULL,
   17450                 :        3314 :                                                 castNode(JsonFormat, $2));
   17451                 :             :             }
   17452                 :             :         ;
   17453                 :             : 
   17454                 :             : json_format_clause:
   17455                 :             :             FORMAT_LA JSON ENCODING name
   17456                 :             :                 {
   17457                 :             :                     int     encoding;
   17458                 :             : 
   17459         [ +  + ]:          66 :                     if (!pg_strcasecmp($4, "utf8"))
   17460                 :          42 :                         encoding = JS_ENC_UTF8;
   17461         [ +  + ]:          24 :                     else if (!pg_strcasecmp($4, "utf16"))
   17462                 :           8 :                         encoding = JS_ENC_UTF16;
   17463         [ +  + ]:          16 :                     else if (!pg_strcasecmp($4, "utf32"))
   17464                 :           8 :                         encoding = JS_ENC_UTF32;
   17465                 :             :                     else
   17466         [ +  - ]:           8 :                         ereport(ERROR,
   17467                 :             :                                 (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   17468                 :             :                                  errmsg("unrecognized JSON encoding: %s", $4),
   17469                 :             :                                  parser_errposition(@4)));
   17470                 :             : 
   17471                 :          58 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, encoding, @1);
   17472                 :             :                 }
   17473                 :             :             | FORMAT_LA JSON
   17474                 :             :                 {
   17475                 :         296 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_JSON, JS_ENC_DEFAULT, @1);
   17476                 :             :                 }
   17477                 :             :         ;
   17478                 :             : 
   17479                 :             : json_format_clause_opt:
   17480                 :             :             json_format_clause
   17481                 :             :                 {
   17482                 :         262 :                     $$ = $1;
   17483                 :             :                 }
   17484                 :             :             | /* EMPTY */
   17485                 :             :                 {
   17486                 :        4470 :                     $$ = (Node *) makeJsonFormat(JS_FORMAT_DEFAULT, JS_ENC_DEFAULT, -1);
   17487                 :             :                 }
   17488                 :             :         ;
   17489                 :             : 
   17490                 :             : json_quotes_clause_opt:
   17491                 :           8 :             KEEP QUOTES ON SCALAR STRING_P      { $$ = JS_QUOTES_KEEP; }
   17492                 :          60 :             | KEEP QUOTES                       { $$ = JS_QUOTES_KEEP; }
   17493                 :           8 :             | OMIT QUOTES ON SCALAR STRING_P    { $$ = JS_QUOTES_OMIT; }
   17494                 :         120 :             | OMIT QUOTES                       { $$ = JS_QUOTES_OMIT; }
   17495                 :        1468 :             | /* EMPTY */                       { $$ = JS_QUOTES_UNSPEC; }
   17496                 :             :         ;
   17497                 :             : 
   17498                 :             : json_returning_clause_opt:
   17499                 :             :             RETURNING Typename json_format_clause_opt
   17500                 :             :                 {
   17501                 :        1322 :                     JsonOutput *n = makeNode(JsonOutput);
   17502                 :             : 
   17503                 :        1322 :                     n->typeName = $2;
   17504                 :        1322 :                     n->returning = makeNode(JsonReturning);
   17505                 :        1322 :                     n->returning->format = (JsonFormat *) $3;
   17506                 :        1322 :                     $$ = (Node *) n;
   17507                 :             :                 }
   17508                 :         908 :             | /* EMPTY */                           { $$ = NULL; }
   17509                 :             :         ;
   17510                 :             : 
   17511                 :             : /*
   17512                 :             :  * We must assign the only-JSON production a precedence less than IDENT in
   17513                 :             :  * order to favor shifting over reduction when JSON is followed by VALUE_P,
   17514                 :             :  * OBJECT_P, or SCALAR.  (ARRAY doesn't need that treatment, because it's a
   17515                 :             :  * fully reserved word.)  Because json_predicate_type_constraint is always
   17516                 :             :  * followed by json_key_uniqueness_constraint_opt, we also need the only-JSON
   17517                 :             :  * production to have precedence less than WITH and WITHOUT.  UNBOUNDED isn't
   17518                 :             :  * really related to this syntax, but it's a convenient choice because it
   17519                 :             :  * already has a precedence less than IDENT for other reasons.
   17520                 :             :  */
   17521                 :             : json_predicate_type_constraint:
   17522                 :         184 :             JSON                    %prec UNBOUNDED { $$ = JS_TYPE_ANY; }
   17523                 :          18 :             | JSON VALUE_P                          { $$ = JS_TYPE_ANY; }
   17524                 :          26 :             | JSON ARRAY                            { $$ = JS_TYPE_ARRAY; }
   17525                 :          26 :             | JSON OBJECT_P                         { $$ = JS_TYPE_OBJECT; }
   17526                 :          26 :             | JSON SCALAR                           { $$ = JS_TYPE_SCALAR; }
   17527                 :             :         ;
   17528                 :             : 
   17529                 :             : /*
   17530                 :             :  * KEYS is a noise word here.  To avoid shift/reduce conflicts, assign the
   17531                 :             :  * KEYS-less productions a precedence less than IDENT (i.e., less than KEYS).
   17532                 :             :  * This prevents reducing them when the next token is KEYS.
   17533                 :             :  */
   17534                 :             : json_key_uniqueness_constraint_opt:
   17535                 :         102 :             WITH UNIQUE KEYS                            { $$ = true; }
   17536                 :          74 :             | WITH UNIQUE               %prec UNBOUNDED { $$ = true; }
   17537                 :          28 :             | WITHOUT UNIQUE KEYS                       { $$ = false; }
   17538                 :          10 :             | WITHOUT UNIQUE            %prec UNBOUNDED { $$ = false; }
   17539                 :         672 :             | /* EMPTY */               %prec UNBOUNDED { $$ = false; }
   17540                 :             :         ;
   17541                 :             : 
   17542                 :             : json_name_and_value_list:
   17543                 :             :             json_name_and_value
   17544                 :         338 :                 { $$ = list_make1($1); }
   17545                 :             :             | json_name_and_value_list ',' json_name_and_value
   17546                 :         168 :                 { $$ = lappend($1, $3); }
   17547                 :             :         ;
   17548                 :             : 
   17549                 :             : json_name_and_value:
   17550                 :             : /* Supporting this syntax seems to require major surgery
   17551                 :             :             KEY c_expr VALUE_P json_value_expr
   17552                 :             :                 { $$ = makeJsonKeyValue($2, $4); }
   17553                 :             :             |
   17554                 :             : */
   17555                 :             :             c_expr VALUE_P json_value_expr
   17556                 :         104 :                 { $$ = makeJsonKeyValue($1, $3); }
   17557                 :             :             |
   17558                 :             :             a_expr ':' json_value_expr
   17559                 :         562 :                 { $$ = makeJsonKeyValue($1, $3); }
   17560                 :             :         ;
   17561                 :             : 
   17562                 :             : /* empty means false for objects, true for arrays */
   17563                 :             : json_object_constructor_null_clause_opt:
   17564                 :          20 :             NULL_P ON NULL_P                    { $$ = false; }
   17565                 :          88 :             | ABSENT ON NULL_P                  { $$ = true; }
   17566                 :         390 :             | /* EMPTY */                       { $$ = false; }
   17567                 :             :         ;
   17568                 :             : 
   17569                 :             : json_array_constructor_null_clause_opt:
   17570                 :          56 :             NULL_P ON NULL_P                        { $$ = false; }
   17571                 :          24 :             | ABSENT ON NULL_P                      { $$ = true; }
   17572                 :         236 :             | /* EMPTY */                           { $$ = true; }
   17573                 :             :         ;
   17574                 :             : 
   17575                 :             : json_value_expr_list:
   17576                 :         168 :             json_value_expr                             { $$ = list_make1($1); }
   17577                 :          92 :             | json_value_expr_list ',' json_value_expr  { $$ = lappend($1, $3);}
   17578                 :             :         ;
   17579                 :             : 
   17580                 :             : json_aggregate_func:
   17581                 :             :             JSON_OBJECTAGG '('
   17582                 :             :                 json_name_and_value
   17583                 :             :                 json_object_constructor_null_clause_opt
   17584                 :             :                 json_key_uniqueness_constraint_opt
   17585                 :             :                 json_returning_clause_opt
   17586                 :             :             ')'
   17587                 :             :                 {
   17588                 :         160 :                     JsonObjectAgg *n = makeNode(JsonObjectAgg);
   17589                 :             : 
   17590                 :         160 :                     n->arg = (JsonKeyValue *) $3;
   17591                 :         160 :                     n->absent_on_null = $4;
   17592                 :         160 :                     n->unique = $5;
   17593                 :         160 :                     n->constructor = makeNode(JsonAggConstructor);
   17594                 :         160 :                     n->constructor->output = (JsonOutput *) $6;
   17595                 :         160 :                     n->constructor->agg_order = NULL;
   17596                 :         160 :                     n->constructor->location = @1;
   17597                 :         160 :                     $$ = (Node *) n;
   17598                 :             :                 }
   17599                 :             :             | JSON_ARRAYAGG '('
   17600                 :             :                 json_value_expr
   17601                 :             :                 json_array_aggregate_order_by_clause_opt
   17602                 :             :                 json_array_constructor_null_clause_opt
   17603                 :             :                 json_returning_clause_opt
   17604                 :             :             ')'
   17605                 :             :                 {
   17606                 :         148 :                     JsonArrayAgg *n = makeNode(JsonArrayAgg);
   17607                 :             : 
   17608                 :         148 :                     n->arg = (JsonValueExpr *) $3;
   17609                 :         148 :                     n->absent_on_null = $5;
   17610                 :         148 :                     n->constructor = makeNode(JsonAggConstructor);
   17611                 :         148 :                     n->constructor->agg_order = $4;
   17612                 :         148 :                     n->constructor->output = (JsonOutput *) $6;
   17613                 :         148 :                     n->constructor->location = @1;
   17614                 :         148 :                     $$ = (Node *) n;
   17615                 :             :                 }
   17616                 :             :         ;
   17617                 :             : 
   17618                 :             : json_array_aggregate_order_by_clause_opt:
   17619                 :          36 :             ORDER BY sortby_list                    { $$ = $3; }
   17620                 :         112 :             | /* EMPTY */                           { $$ = NIL; }
   17621                 :             :         ;
   17622                 :             : 
   17623                 :             : /*****************************************************************************
   17624                 :             :  *
   17625                 :             :  *  target list for SELECT
   17626                 :             :  *
   17627                 :             :  *****************************************************************************/
   17628                 :             : 
   17629                 :      310229 : opt_target_list: target_list                        { $$ = $1; }
   17630                 :         380 :             | /* EMPTY */                           { $$ = NIL; }
   17631                 :             :         ;
   17632                 :             : 
   17633                 :             : target_list:
   17634                 :      315121 :             target_el                               { $$ = list_make1($1); }
   17635                 :      414873 :             | target_list ',' target_el             { $$ = lappend($1, $3); }
   17636                 :             :         ;
   17637                 :             : 
   17638                 :             : target_el:  a_expr AS ColLabel
   17639                 :             :                 {
   17640                 :      146534 :                     $$ = makeNode(ResTarget);
   17641                 :      146534 :                     $$->name = $3;
   17642                 :      146534 :                     $$->indirection = NIL;
   17643                 :      146534 :                     $$->val = (Node *) $1;
   17644                 :      146534 :                     $$->location = @1;
   17645                 :             :                 }
   17646                 :             :             | a_expr BareColLabel
   17647                 :             :                 {
   17648                 :        2294 :                     $$ = makeNode(ResTarget);
   17649                 :        2294 :                     $$->name = $2;
   17650                 :        2294 :                     $$->indirection = NIL;
   17651                 :        2294 :                     $$->val = (Node *) $1;
   17652                 :        2294 :                     $$->location = @1;
   17653                 :             :                 }
   17654                 :             :             | a_expr
   17655                 :             :                 {
   17656                 :      541002 :                     $$ = makeNode(ResTarget);
   17657                 :      541001 :                     $$->name = NULL;
   17658                 :      541001 :                     $$->indirection = NIL;
   17659                 :      541001 :                     $$->val = (Node *) $1;
   17660                 :      541001 :                     $$->location = @1;
   17661                 :             :                 }
   17662                 :             :             | '*'
   17663                 :             :                 {
   17664                 :       40164 :                     ColumnRef  *n = makeNode(ColumnRef);
   17665                 :             : 
   17666                 :       40164 :                     n->fields = list_make1(makeNode(A_Star));
   17667                 :       40164 :                     n->location = @1;
   17668                 :             : 
   17669                 :       40164 :                     $$ = makeNode(ResTarget);
   17670                 :       40164 :                     $$->name = NULL;
   17671                 :       40164 :                     $$->indirection = NIL;
   17672                 :       40164 :                     $$->val = (Node *) n;
   17673                 :       40164 :                     $$->location = @1;
   17674                 :             :                 }
   17675                 :             :         ;
   17676                 :             : 
   17677                 :             : 
   17678                 :             : /*****************************************************************************
   17679                 :             :  *
   17680                 :             :  *  Names and constants
   17681                 :             :  *
   17682                 :             :  *****************************************************************************/
   17683                 :             : 
   17684                 :             : qualified_name_list:
   17685                 :        9860 :             qualified_name                          { $$ = list_make1($1); }
   17686                 :         307 :             | qualified_name_list ',' qualified_name { $$ = lappend($1, $3); }
   17687                 :             :         ;
   17688                 :             : 
   17689                 :             : /*
   17690                 :             :  * The production for a qualified relation name has to exactly match the
   17691                 :             :  * production for a qualified func_name, because in a FROM clause we cannot
   17692                 :             :  * tell which we are parsing until we see what comes after it ('(' for a
   17693                 :             :  * func_name, something else for a relation). Therefore we allow 'indirection'
   17694                 :             :  * which may contain subscripts, and reject that case in the C code.
   17695                 :             :  */
   17696                 :             : qualified_name:
   17697                 :             :             ColId
   17698                 :             :                 {
   17699                 :      273898 :                     $$ = makeRangeVar(NULL, $1, @1);
   17700                 :             :                 }
   17701                 :             :             | ColId indirection
   17702                 :             :                 {
   17703                 :      159050 :                     $$ = makeRangeVarFromQualifiedName($1, $2, @1, yyscanner);
   17704                 :             :                 }
   17705                 :             :         ;
   17706                 :             : 
   17707                 :             : name_list:  name
   17708                 :       18539 :                     { $$ = list_make1(makeString($1)); }
   17709                 :             :             | name_list ',' name
   17710                 :       38684 :                     { $$ = lappend($1, makeString($3)); }
   17711                 :             :         ;
   17712                 :             : 
   17713                 :             : 
   17714                 :      110449 : name:       ColId                                   { $$ = $1; };
   17715                 :             : 
   17716                 :     1015774 : attr_name:  ColLabel                                { $$ = $1; };
   17717                 :             : 
   17718                 :          50 : file_name:  Sconst                                  { $$ = $1; };
   17719                 :             : 
   17720                 :             : /*
   17721                 :             :  * The production for a qualified func_name has to exactly match the
   17722                 :             :  * production for a qualified columnref, because we cannot tell which we
   17723                 :             :  * are parsing until we see what comes after it ('(' or Sconst for a func_name,
   17724                 :             :  * anything else for a columnref).  Therefore we allow 'indirection' which
   17725                 :             :  * may contain subscripts, and reject that case in the C code.  (If we
   17726                 :             :  * ever implement SQL99-like methods, such syntax may actually become legal!)
   17727                 :             :  */
   17728                 :             : func_name:  type_function_name
   17729                 :      180126 :                     { $$ = list_make1(makeString($1)); }
   17730                 :             :             | ColId indirection
   17731                 :             :                     {
   17732                 :       86965 :                         $$ = check_func_name(lcons(makeString($1), $2),
   17733                 :             :                                              yyscanner);
   17734                 :             :                     }
   17735                 :             :         ;
   17736                 :             : 
   17737                 :             : 
   17738                 :             : /*
   17739                 :             :  * Constants
   17740                 :             :  */
   17741                 :             : AexprConst: Iconst
   17742                 :             :                 {
   17743                 :      261634 :                     $$ = makeIntConst($1, @1);
   17744                 :             :                 }
   17745                 :             :             | FCONST
   17746                 :             :                 {
   17747                 :        7943 :                     $$ = makeFloatConst($1, @1);
   17748                 :             :                 }
   17749                 :             :             | Sconst
   17750                 :             :                 {
   17751                 :      446705 :                     $$ = makeStringConst($1, @1);
   17752                 :             :                 }
   17753                 :             :             | BCONST
   17754                 :             :                 {
   17755                 :         510 :                     $$ = makeBitStringConst($1, @1);
   17756                 :             :                 }
   17757                 :             :             | XCONST
   17758                 :             :                 {
   17759                 :             :                     /* This is a bit constant per SQL99:
   17760                 :             :                      * Without Feature F511, "BIT data type",
   17761                 :             :                      * a <general literal> shall not be a
   17762                 :             :                      * <bit string literal> or a <hex string literal>.
   17763                 :             :                      */
   17764                 :        2217 :                     $$ = makeBitStringConst($1, @1);
   17765                 :             :                 }
   17766                 :             :             | func_name Sconst
   17767                 :             :                 {
   17768                 :             :                     /* generic type 'literal' syntax */
   17769                 :        6420 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17770                 :             : 
   17771                 :        6420 :                     t->location = @1;
   17772                 :        6420 :                     $$ = makeStringConstCast($2, @2, t);
   17773                 :             :                 }
   17774                 :             :             | func_name '(' func_arg_list opt_sort_clause ')' Sconst
   17775                 :             :                 {
   17776                 :             :                     /* generic syntax with a type modifier */
   17777                 :           0 :                     TypeName   *t = makeTypeNameFromNameList($1);
   17778                 :             :                     ListCell   *lc;
   17779                 :             : 
   17780                 :             :                     /*
   17781                 :             :                      * We must use func_arg_list and opt_sort_clause in the
   17782                 :             :                      * production to avoid reduce/reduce conflicts, but we
   17783                 :             :                      * don't actually wish to allow NamedArgExpr in this
   17784                 :             :                      * context, nor ORDER BY.
   17785                 :             :                      */
   17786   [ #  #  #  #  :           0 :                     foreach(lc, $3)
                   #  # ]
   17787                 :             :                     {
   17788                 :           0 :                         NamedArgExpr *arg = (NamedArgExpr *) lfirst(lc);
   17789                 :             : 
   17790         [ #  # ]:           0 :                         if (IsA(arg, NamedArgExpr))
   17791         [ #  # ]:           0 :                             ereport(ERROR,
   17792                 :             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17793                 :             :                                      errmsg("type modifier cannot have parameter name"),
   17794                 :             :                                      parser_errposition(arg->location)));
   17795                 :             :                     }
   17796         [ #  # ]:           0 :                     if ($4 != NIL)
   17797         [ #  # ]:           0 :                             ereport(ERROR,
   17798                 :             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17799                 :             :                                      errmsg("type modifier cannot have ORDER BY"),
   17800                 :             :                                      parser_errposition(@4)));
   17801                 :             : 
   17802                 :           0 :                     t->typmods = $3;
   17803                 :           0 :                     t->location = @1;
   17804                 :           0 :                     $$ = makeStringConstCast($6, @6, t);
   17805                 :             :                 }
   17806                 :             :             | ConstTypename Sconst
   17807                 :             :                 {
   17808                 :        2044 :                     $$ = makeStringConstCast($2, @2, $1);
   17809                 :             :                 }
   17810                 :             :             | ConstInterval Sconst opt_interval
   17811                 :             :                 {
   17812                 :        2196 :                     TypeName   *t = $1;
   17813                 :             : 
   17814                 :        2196 :                     t->typmods = $3;
   17815                 :        2196 :                     $$ = makeStringConstCast($2, @2, t);
   17816                 :             :                 }
   17817                 :             :             | ConstInterval '(' Iconst ')' Sconst
   17818                 :             :                 {
   17819                 :           8 :                     TypeName   *t = $1;
   17820                 :             : 
   17821                 :           8 :                     t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
   17822                 :             :                                             makeIntConst($3, @3));
   17823                 :           8 :                     $$ = makeStringConstCast($5, @5, t);
   17824                 :             :                 }
   17825                 :             :             | TRUE_P
   17826                 :             :                 {
   17827                 :       19477 :                     $$ = makeBoolAConst(true, @1);
   17828                 :             :                 }
   17829                 :             :             | FALSE_P
   17830                 :             :                 {
   17831                 :       19536 :                     $$ = makeBoolAConst(false, @1);
   17832                 :             :                 }
   17833                 :             :             | NULL_P
   17834                 :             :                 {
   17835                 :       42979 :                     $$ = makeNullAConst(@1);
   17836                 :             :                 }
   17837                 :             :         ;
   17838                 :             : 
   17839                 :      277520 : Iconst:     ICONST                                  { $$ = $1; };
   17840                 :      491244 : Sconst:     SCONST                                  { $$ = $1; };
   17841                 :             : 
   17842                 :        9678 : SignedIconst: Iconst                                { $$ = $1; }
   17843                 :           0 :             | '+' Iconst                            { $$ = + $2; }
   17844                 :         188 :             | '-' Iconst                            { $$ = - $2; }
   17845                 :             :         ;
   17846                 :             : 
   17847                 :             : /* Role specifications */
   17848                 :             : RoleId:     RoleSpec
   17849                 :             :                 {
   17850                 :        1327 :                     RoleSpec   *spc = (RoleSpec *) $1;
   17851                 :             : 
   17852   [ +  +  +  +  :        1327 :                     switch (spc->roletype)
                   +  - ]
   17853                 :             :                     {
   17854                 :        1322 :                         case ROLESPEC_CSTRING:
   17855                 :        1322 :                             $$ = spc->rolename;
   17856                 :        1322 :                             break;
   17857                 :           2 :                         case ROLESPEC_PUBLIC:
   17858         [ +  - ]:           2 :                             ereport(ERROR,
   17859                 :             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17860                 :             :                                      errmsg("role name \"%s\" is reserved",
   17861                 :             :                                             "public"),
   17862                 :             :                                      parser_errposition(@1)));
   17863                 :             :                             break;
   17864                 :           1 :                         case ROLESPEC_SESSION_USER:
   17865         [ +  - ]:           1 :                             ereport(ERROR,
   17866                 :             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17867                 :             :                                      errmsg("%s cannot be used as a role name here",
   17868                 :             :                                             "SESSION_USER"),
   17869                 :             :                                      parser_errposition(@1)));
   17870                 :             :                             break;
   17871                 :           1 :                         case ROLESPEC_CURRENT_USER:
   17872         [ +  - ]:           1 :                             ereport(ERROR,
   17873                 :             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17874                 :             :                                      errmsg("%s cannot be used as a role name here",
   17875                 :             :                                             "CURRENT_USER"),
   17876                 :             :                                      parser_errposition(@1)));
   17877                 :             :                             break;
   17878                 :           1 :                         case ROLESPEC_CURRENT_ROLE:
   17879         [ +  - ]:           1 :                             ereport(ERROR,
   17880                 :             :                                     (errcode(ERRCODE_RESERVED_NAME),
   17881                 :             :                                      errmsg("%s cannot be used as a role name here",
   17882                 :             :                                             "CURRENT_ROLE"),
   17883                 :             :                                      parser_errposition(@1)));
   17884                 :             :                             break;
   17885                 :             :                     }
   17886                 :             :                 }
   17887                 :             :             ;
   17888                 :             : 
   17889                 :             : RoleSpec:   NonReservedWord
   17890                 :             :                 {
   17891                 :             :                     /*
   17892                 :             :                      * "public" and "none" are not keywords, but they must
   17893                 :             :                      * be treated specially here.
   17894                 :             :                      */
   17895                 :             :                     RoleSpec   *n;
   17896                 :             : 
   17897         [ +  + ]:       15224 :                     if (strcmp($1, "public") == 0)
   17898                 :             :                     {
   17899                 :        6657 :                         n = (RoleSpec *) makeRoleSpec(ROLESPEC_PUBLIC, @1);
   17900                 :        6657 :                         n->roletype = ROLESPEC_PUBLIC;
   17901                 :             :                     }
   17902         [ +  + ]:        8567 :                     else if (strcmp($1, "none") == 0)
   17903                 :             :                     {
   17904         [ +  - ]:          13 :                         ereport(ERROR,
   17905                 :             :                                 (errcode(ERRCODE_RESERVED_NAME),
   17906                 :             :                                  errmsg("role name \"%s\" is reserved",
   17907                 :             :                                         "none"),
   17908                 :             :                                  parser_errposition(@1)));
   17909                 :             :                     }
   17910                 :             :                     else
   17911                 :             :                     {
   17912                 :        8554 :                         n = makeRoleSpec(ROLESPEC_CSTRING, @1);
   17913                 :        8554 :                         n->rolename = pstrdup($1);
   17914                 :             :                     }
   17915                 :       15211 :                     $$ = n;
   17916                 :             :                 }
   17917                 :             :             | CURRENT_ROLE
   17918                 :             :                 {
   17919                 :          80 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_ROLE, @1);
   17920                 :             :                 }
   17921                 :             :             | CURRENT_USER
   17922                 :             :                 {
   17923                 :         149 :                     $$ = makeRoleSpec(ROLESPEC_CURRENT_USER, @1);
   17924                 :             :                 }
   17925                 :             :             | SESSION_USER
   17926                 :             :                 {
   17927                 :          18 :                     $$ = makeRoleSpec(ROLESPEC_SESSION_USER, @1);
   17928                 :             :                 }
   17929                 :             :         ;
   17930                 :             : 
   17931                 :             : role_list:  RoleSpec
   17932                 :        2064 :                 { $$ = list_make1($1); }
   17933                 :             :             | role_list ',' RoleSpec
   17934                 :         189 :                 { $$ = lappend($1, $3); }
   17935                 :             :         ;
   17936                 :             : 
   17937                 :             : 
   17938                 :             : /*****************************************************************************
   17939                 :             :  *
   17940                 :             :  * PL/pgSQL extensions
   17941                 :             :  *
   17942                 :             :  * You'd think a PL/pgSQL "expression" should be just an a_expr, but
   17943                 :             :  * historically it can include just about anything that can follow SELECT.
   17944                 :             :  * Therefore the returned struct is a SelectStmt.
   17945                 :             :  *****************************************************************************/
   17946                 :             : 
   17947                 :             : PLpgSQL_Expr: opt_distinct_clause opt_target_list
   17948                 :             :             from_clause where_clause
   17949                 :             :             group_clause having_clause window_clause
   17950                 :             :             opt_sort_clause opt_select_limit opt_for_locking_clause
   17951                 :             :                 {
   17952                 :       24957 :                     SelectStmt *n = makeNode(SelectStmt);
   17953                 :             : 
   17954                 :       24957 :                     n->distinctClause = $1;
   17955                 :       24957 :                     n->targetList = $2;
   17956                 :       24957 :                     n->fromClause = $3;
   17957                 :       24957 :                     n->whereClause = $4;
   17958                 :       24957 :                     n->groupClause = ($5)->list;
   17959                 :       24957 :                     n->groupDistinct = ($5)->distinct;
   17960                 :       24957 :                     n->havingClause = $6;
   17961                 :       24957 :                     n->windowClause = $7;
   17962                 :       24957 :                     n->sortClause = $8;
   17963         [ +  + ]:       24957 :                     if ($9)
   17964                 :             :                     {
   17965                 :           2 :                         n->limitOffset = $9->limitOffset;
   17966                 :           2 :                         n->limitCount = $9->limitCount;
   17967         [ +  - ]:           2 :                         if (!n->sortClause &&
   17968         [ -  + ]:           2 :                             $9->limitOption == LIMIT_OPTION_WITH_TIES)
   17969         [ #  # ]:           0 :                             ereport(ERROR,
   17970                 :             :                                     (errcode(ERRCODE_SYNTAX_ERROR),
   17971                 :             :                                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   17972                 :             :                                      parser_errposition($9->optionLoc)));
   17973                 :           2 :                         n->limitOption = $9->limitOption;
   17974                 :             :                     }
   17975                 :       24957 :                     n->lockingClause = $10;
   17976                 :       24957 :                     $$ = (Node *) n;
   17977                 :             :                 }
   17978                 :             :         ;
   17979                 :             : 
   17980                 :             : /*
   17981                 :             :  * PL/pgSQL Assignment statement: name opt_indirection := PLpgSQL_Expr
   17982                 :             :  */
   17983                 :             : 
   17984                 :             : PLAssignStmt: plassign_target opt_indirection plassign_equals PLpgSQL_Expr
   17985                 :             :                 {
   17986                 :        4272 :                     PLAssignStmt *n = makeNode(PLAssignStmt);
   17987                 :             : 
   17988                 :        4272 :                     n->name = $1;
   17989                 :        4272 :                     n->indirection = check_indirection($2, yyscanner);
   17990                 :             :                     /* nnames will be filled by calling production */
   17991                 :        4237 :                     n->val = (SelectStmt *) $4;
   17992                 :        4237 :                     n->location = @1;
   17993                 :        4237 :                     $$ = (Node *) n;
   17994                 :             :                 }
   17995                 :             :         ;
   17996                 :             : 
   17997                 :        4256 : plassign_target: ColId                          { $$ = $1; }
   17998                 :          16 :             | PARAM                             { $$ = psprintf("$%d", $1); }
   17999                 :             :         ;
   18000                 :             : 
   18001                 :             : plassign_equals: COLON_EQUALS
   18002                 :             :             | '='
   18003                 :             :         ;
   18004                 :             : 
   18005                 :             : 
   18006                 :             : /*
   18007                 :             :  * Name classification hierarchy.
   18008                 :             :  *
   18009                 :             :  * IDENT is the lexeme returned by the lexer for identifiers that match
   18010                 :             :  * no known keyword.  In most cases, we can accept certain keywords as
   18011                 :             :  * names, not only IDENTs.  We prefer to accept as many such keywords
   18012                 :             :  * as possible to minimize the impact of "reserved words" on programmers.
   18013                 :             :  * So, we divide names into several possible classes.  The classification
   18014                 :             :  * is chosen in part to make keywords acceptable as names wherever possible.
   18015                 :             :  */
   18016                 :             : 
   18017                 :             : /* Column identifier --- names that can be column, table, etc names.
   18018                 :             :  */
   18019                 :     2168396 : ColId:      IDENT                                   { $$ = $1; }
   18020                 :       32242 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   18021                 :        3907 :             | col_name_keyword                      { $$ = pstrdup($1); }
   18022                 :             :         ;
   18023                 :             : 
   18024                 :             : /* Type/function identifier --- names that can be type or function names.
   18025                 :             :  */
   18026                 :      417211 : type_function_name: IDENT                           { $$ = $1; }
   18027                 :       39787 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   18028                 :          52 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   18029                 :             :         ;
   18030                 :             : 
   18031                 :             : /* Any not-fully-reserved word --- these names can be, eg, role names.
   18032                 :             :  */
   18033                 :       47420 : NonReservedWord:    IDENT                           { $$ = $1; }
   18034                 :       21162 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   18035                 :         280 :             | col_name_keyword                      { $$ = pstrdup($1); }
   18036                 :        3831 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   18037                 :             :         ;
   18038                 :             : 
   18039                 :             : /* Column label --- allowed labels in "AS" clauses.
   18040                 :             :  * This presently includes *all* Postgres keywords.
   18041                 :             :  */
   18042                 :     1151037 : ColLabel:   IDENT                                   { $$ = $1; }
   18043                 :       25952 :             | unreserved_keyword                    { $$ = pstrdup($1); }
   18044                 :         190 :             | col_name_keyword                      { $$ = pstrdup($1); }
   18045                 :         944 :             | type_func_name_keyword                { $$ = pstrdup($1); }
   18046                 :        5080 :             | reserved_keyword                      { $$ = pstrdup($1); }
   18047                 :             :         ;
   18048                 :             : 
   18049                 :             : /* Bare column label --- names that can be column labels without writing "AS".
   18050                 :             :  * This classification is orthogonal to the other keyword categories.
   18051                 :             :  */
   18052                 :        2286 : BareColLabel:   IDENT                               { $$ = $1; }
   18053                 :           8 :             | bare_label_keyword                    { $$ = pstrdup($1); }
   18054                 :             :         ;
   18055                 :             : 
   18056                 :             : 
   18057                 :             : /*
   18058                 :             :  * Keyword category lists.  Generally, every keyword present in
   18059                 :             :  * the Postgres grammar should appear in exactly one of these lists.
   18060                 :             :  *
   18061                 :             :  * Put a new keyword into the first list that it can go into without causing
   18062                 :             :  * shift or reduce conflicts.  The earlier lists define "less reserved"
   18063                 :             :  * categories of keywords.
   18064                 :             :  *
   18065                 :             :  * Make sure that each keyword's category in kwlist.h matches where
   18066                 :             :  * it is listed here.  (Someday we may be able to generate these lists and
   18067                 :             :  * kwlist.h's table from one source of truth.)
   18068                 :             :  */
   18069                 :             : 
   18070                 :             : /* "Unreserved" keywords --- available for use as any kind of name.
   18071                 :             :  */
   18072                 :             : unreserved_keyword:
   18073                 :             :               ABORT_P
   18074                 :             :             | ABSENT
   18075                 :             :             | ABSOLUTE_P
   18076                 :             :             | ACCESS
   18077                 :             :             | ACTION
   18078                 :             :             | ADD_P
   18079                 :             :             | ADMIN
   18080                 :             :             | AFTER
   18081                 :             :             | AGGREGATE
   18082                 :             :             | ALSO
   18083                 :             :             | ALTER
   18084                 :             :             | ALWAYS
   18085                 :             :             | ASENSITIVE
   18086                 :             :             | ASSERTION
   18087                 :             :             | ASSIGNMENT
   18088                 :             :             | AT
   18089                 :             :             | ATOMIC
   18090                 :             :             | ATTACH
   18091                 :             :             | ATTRIBUTE
   18092                 :             :             | BACKWARD
   18093                 :             :             | BEFORE
   18094                 :             :             | BEGIN_P
   18095                 :             :             | BREADTH
   18096                 :             :             | BY
   18097                 :             :             | CACHE
   18098                 :             :             | CALL
   18099                 :             :             | CALLED
   18100                 :             :             | CASCADE
   18101                 :             :             | CASCADED
   18102                 :             :             | CATALOG_P
   18103                 :             :             | CHAIN
   18104                 :             :             | CHARACTERISTICS
   18105                 :             :             | CHECKPOINT
   18106                 :             :             | CLASS
   18107                 :             :             | CLOSE
   18108                 :             :             | CLUSTER
   18109                 :             :             | COLUMNS
   18110                 :             :             | COMMENT
   18111                 :             :             | COMMENTS
   18112                 :             :             | COMMIT
   18113                 :             :             | COMMITTED
   18114                 :             :             | COMPRESSION
   18115                 :             :             | CONDITIONAL
   18116                 :             :             | CONFIGURATION
   18117                 :             :             | CONFLICT
   18118                 :             :             | CONNECTION
   18119                 :             :             | CONSTRAINTS
   18120                 :             :             | CONTENT_P
   18121                 :             :             | CONTINUE_P
   18122                 :             :             | CONVERSION_P
   18123                 :             :             | COPY
   18124                 :             :             | COST
   18125                 :             :             | CSV
   18126                 :             :             | CUBE
   18127                 :             :             | CURRENT_P
   18128                 :             :             | CURSOR
   18129                 :             :             | CYCLE
   18130                 :             :             | DATA_P
   18131                 :             :             | DATABASE
   18132                 :             :             | DAY_P
   18133                 :             :             | DEALLOCATE
   18134                 :             :             | DECLARE
   18135                 :             :             | DEFAULTS
   18136                 :             :             | DEFERRED
   18137                 :             :             | DEFINER
   18138                 :             :             | DELETE_P
   18139                 :             :             | DELIMITER
   18140                 :             :             | DELIMITERS
   18141                 :             :             | DEPENDS
   18142                 :             :             | DEPTH
   18143                 :             :             | DETACH
   18144                 :             :             | DICTIONARY
   18145                 :             :             | DISABLE_P
   18146                 :             :             | DISCARD
   18147                 :             :             | DOCUMENT_P
   18148                 :             :             | DOMAIN_P
   18149                 :             :             | DOUBLE_P
   18150                 :             :             | DROP
   18151                 :             :             | EACH
   18152                 :             :             | EMPTY_P
   18153                 :             :             | ENABLE_P
   18154                 :             :             | ENCODING
   18155                 :             :             | ENCRYPTED
   18156                 :             :             | ENFORCED
   18157                 :             :             | ENUM_P
   18158                 :             :             | ERROR_P
   18159                 :             :             | ESCAPE
   18160                 :             :             | EVENT
   18161                 :             :             | EXCLUDE
   18162                 :             :             | EXCLUDING
   18163                 :             :             | EXCLUSIVE
   18164                 :             :             | EXECUTE
   18165                 :             :             | EXPLAIN
   18166                 :             :             | EXPRESSION
   18167                 :             :             | EXTENSION
   18168                 :             :             | EXTERNAL
   18169                 :             :             | FAMILY
   18170                 :             :             | FILTER
   18171                 :             :             | FINALIZE
   18172                 :             :             | FIRST_P
   18173                 :             :             | FOLLOWING
   18174                 :             :             | FORCE
   18175                 :             :             | FORMAT
   18176                 :             :             | FORWARD
   18177                 :             :             | FUNCTION
   18178                 :             :             | FUNCTIONS
   18179                 :             :             | GENERATED
   18180                 :             :             | GLOBAL
   18181                 :             :             | GRANTED
   18182                 :             :             | GROUPS
   18183                 :             :             | HANDLER
   18184                 :             :             | HEADER_P
   18185                 :             :             | HOLD
   18186                 :             :             | HOUR_P
   18187                 :             :             | IDENTITY_P
   18188                 :             :             | IF_P
   18189                 :             :             | IGNORE_P
   18190                 :             :             | IMMEDIATE
   18191                 :             :             | IMMUTABLE
   18192                 :             :             | IMPLICIT_P
   18193                 :             :             | IMPORT_P
   18194                 :             :             | INCLUDE
   18195                 :             :             | INCLUDING
   18196                 :             :             | INCREMENT
   18197                 :             :             | INDENT
   18198                 :             :             | INDEX
   18199                 :             :             | INDEXES
   18200                 :             :             | INHERIT
   18201                 :             :             | INHERITS
   18202                 :             :             | INLINE_P
   18203                 :             :             | INPUT_P
   18204                 :             :             | INSENSITIVE
   18205                 :             :             | INSERT
   18206                 :             :             | INSTEAD
   18207                 :             :             | INVOKER
   18208                 :             :             | ISOLATION
   18209                 :             :             | KEEP
   18210                 :             :             | KEY
   18211                 :             :             | KEYS
   18212                 :             :             | LABEL
   18213                 :             :             | LANGUAGE
   18214                 :             :             | LARGE_P
   18215                 :             :             | LAST_P
   18216                 :             :             | LEAKPROOF
   18217                 :             :             | LEVEL
   18218                 :             :             | LISTEN
   18219                 :             :             | LOAD
   18220                 :             :             | LOCAL
   18221                 :             :             | LOCATION
   18222                 :             :             | LOCK_P
   18223                 :             :             | LOCKED
   18224                 :             :             | LOGGED
   18225                 :             :             | LSN_P
   18226                 :             :             | MAPPING
   18227                 :             :             | MATCH
   18228                 :             :             | MATCHED
   18229                 :             :             | MATERIALIZED
   18230                 :             :             | MAXVALUE
   18231                 :             :             | MERGE
   18232                 :             :             | METHOD
   18233                 :             :             | MINUTE_P
   18234                 :             :             | MINVALUE
   18235                 :             :             | MODE
   18236                 :             :             | MONTH_P
   18237                 :             :             | MOVE
   18238                 :             :             | NAME_P
   18239                 :             :             | NAMES
   18240                 :             :             | NESTED
   18241                 :             :             | NEW
   18242                 :             :             | NEXT
   18243                 :             :             | NFC
   18244                 :             :             | NFD
   18245                 :             :             | NFKC
   18246                 :             :             | NFKD
   18247                 :             :             | NO
   18248                 :             :             | NORMALIZED
   18249                 :             :             | NOTHING
   18250                 :             :             | NOTIFY
   18251                 :             :             | NOWAIT
   18252                 :             :             | NULLS_P
   18253                 :             :             | OBJECT_P
   18254                 :             :             | OBJECTS_P
   18255                 :             :             | OF
   18256                 :             :             | OFF
   18257                 :             :             | OIDS
   18258                 :             :             | OLD
   18259                 :             :             | OMIT
   18260                 :             :             | OPERATOR
   18261                 :             :             | OPTION
   18262                 :             :             | OPTIONS
   18263                 :             :             | ORDINALITY
   18264                 :             :             | OTHERS
   18265                 :             :             | OVER
   18266                 :             :             | OVERRIDING
   18267                 :             :             | OWNED
   18268                 :             :             | OWNER
   18269                 :             :             | PARALLEL
   18270                 :             :             | PARAMETER
   18271                 :             :             | PARSER
   18272                 :             :             | PARTIAL
   18273                 :             :             | PARTITION
   18274                 :             :             | PASSING
   18275                 :             :             | PASSWORD
   18276                 :             :             | PATH
   18277                 :             :             | PERIOD
   18278                 :             :             | PLAN
   18279                 :             :             | PLANS
   18280                 :             :             | POLICY
   18281                 :             :             | PRECEDING
   18282                 :             :             | PREPARE
   18283                 :             :             | PREPARED
   18284                 :             :             | PRESERVE
   18285                 :             :             | PRIOR
   18286                 :             :             | PRIVILEGES
   18287                 :             :             | PROCEDURAL
   18288                 :             :             | PROCEDURE
   18289                 :             :             | PROCEDURES
   18290                 :             :             | PROGRAM
   18291                 :             :             | PUBLICATION
   18292                 :             :             | QUOTE
   18293                 :             :             | QUOTES
   18294                 :             :             | RANGE
   18295                 :             :             | READ
   18296                 :             :             | REASSIGN
   18297                 :             :             | RECURSIVE
   18298                 :             :             | REF_P
   18299                 :             :             | REFERENCING
   18300                 :             :             | REFRESH
   18301                 :             :             | REINDEX
   18302                 :             :             | RELATIVE_P
   18303                 :             :             | RELEASE
   18304                 :             :             | RENAME
   18305                 :             :             | REPACK
   18306                 :             :             | REPEATABLE
   18307                 :             :             | REPLACE
   18308                 :             :             | REPLICA
   18309                 :             :             | RESET
   18310                 :             :             | RESPECT_P
   18311                 :             :             | RESTART
   18312                 :             :             | RESTRICT
   18313                 :             :             | RETURN
   18314                 :             :             | RETURNS
   18315                 :             :             | REVOKE
   18316                 :             :             | ROLE
   18317                 :             :             | ROLLBACK
   18318                 :             :             | ROLLUP
   18319                 :             :             | ROUTINE
   18320                 :             :             | ROUTINES
   18321                 :             :             | ROWS
   18322                 :             :             | RULE
   18323                 :             :             | SAVEPOINT
   18324                 :             :             | SCALAR
   18325                 :             :             | SCHEMA
   18326                 :             :             | SCHEMAS
   18327                 :             :             | SCROLL
   18328                 :             :             | SEARCH
   18329                 :             :             | SECOND_P
   18330                 :             :             | SECURITY
   18331                 :             :             | SEQUENCE
   18332                 :             :             | SEQUENCES
   18333                 :             :             | SERIALIZABLE
   18334                 :             :             | SERVER
   18335                 :             :             | SESSION
   18336                 :             :             | SET
   18337                 :             :             | SETS
   18338                 :             :             | SHARE
   18339                 :             :             | SHOW
   18340                 :             :             | SIMPLE
   18341                 :             :             | SKIP
   18342                 :             :             | SNAPSHOT
   18343                 :             :             | SOURCE
   18344                 :             :             | SQL_P
   18345                 :             :             | STABLE
   18346                 :             :             | STANDALONE_P
   18347                 :             :             | START
   18348                 :             :             | STATEMENT
   18349                 :             :             | STATISTICS
   18350                 :             :             | STDIN
   18351                 :             :             | STDOUT
   18352                 :             :             | STORAGE
   18353                 :             :             | STORED
   18354                 :             :             | STRICT_P
   18355                 :             :             | STRING_P
   18356                 :             :             | STRIP_P
   18357                 :             :             | SUBSCRIPTION
   18358                 :             :             | SUPPORT
   18359                 :             :             | SYSID
   18360                 :             :             | SYSTEM_P
   18361                 :             :             | TABLES
   18362                 :             :             | TABLESPACE
   18363                 :             :             | TARGET
   18364                 :             :             | TEMP
   18365                 :             :             | TEMPLATE
   18366                 :             :             | TEMPORARY
   18367                 :             :             | TEXT_P
   18368                 :             :             | TIES
   18369                 :             :             | TRANSACTION
   18370                 :             :             | TRANSFORM
   18371                 :             :             | TRIGGER
   18372                 :             :             | TRUNCATE
   18373                 :             :             | TRUSTED
   18374                 :             :             | TYPE_P
   18375                 :             :             | TYPES_P
   18376                 :             :             | UESCAPE
   18377                 :             :             | UNBOUNDED
   18378                 :             :             | UNCOMMITTED
   18379                 :             :             | UNCONDITIONAL
   18380                 :             :             | UNENCRYPTED
   18381                 :             :             | UNKNOWN
   18382                 :             :             | UNLISTEN
   18383                 :             :             | UNLOGGED
   18384                 :             :             | UNTIL
   18385                 :             :             | UPDATE
   18386                 :             :             | VACUUM
   18387                 :             :             | VALID
   18388                 :             :             | VALIDATE
   18389                 :             :             | VALIDATOR
   18390                 :             :             | VALUE_P
   18391                 :             :             | VARYING
   18392                 :             :             | VERSION_P
   18393                 :             :             | VIEW
   18394                 :             :             | VIEWS
   18395                 :             :             | VIRTUAL
   18396                 :             :             | VOLATILE
   18397                 :             :             | WAIT
   18398                 :             :             | WHITESPACE_P
   18399                 :             :             | WITHIN
   18400                 :             :             | WITHOUT
   18401                 :             :             | WORK
   18402                 :             :             | WRAPPER
   18403                 :             :             | WRITE
   18404                 :             :             | XML_P
   18405                 :             :             | YEAR_P
   18406                 :             :             | YES_P
   18407                 :             :             | ZONE
   18408                 :             :         ;
   18409                 :             : 
   18410                 :             : /* Column identifier --- keywords that can be column, table, etc names.
   18411                 :             :  *
   18412                 :             :  * Many of these keywords will in fact be recognized as type or function
   18413                 :             :  * names too; but they have special productions for the purpose, and so
   18414                 :             :  * can't be treated as "generic" type or function names.
   18415                 :             :  *
   18416                 :             :  * The type names appearing here are not usable as function names
   18417                 :             :  * because they can be followed by '(' in typename productions, which
   18418                 :             :  * looks too much like a function call for an LR(1) parser.
   18419                 :             :  */
   18420                 :             : col_name_keyword:
   18421                 :             :               BETWEEN
   18422                 :             :             | BIGINT
   18423                 :             :             | BIT
   18424                 :             :             | BOOLEAN_P
   18425                 :             :             | CHAR_P
   18426                 :             :             | CHARACTER
   18427                 :             :             | COALESCE
   18428                 :             :             | DEC
   18429                 :             :             | DECIMAL_P
   18430                 :             :             | EXISTS
   18431                 :             :             | EXTRACT
   18432                 :             :             | FLOAT_P
   18433                 :             :             | GREATEST
   18434                 :             :             | GROUPING
   18435                 :             :             | INOUT
   18436                 :             :             | INT_P
   18437                 :             :             | INTEGER
   18438                 :             :             | INTERVAL
   18439                 :             :             | JSON
   18440                 :             :             | JSON_ARRAY
   18441                 :             :             | JSON_ARRAYAGG
   18442                 :             :             | JSON_EXISTS
   18443                 :             :             | JSON_OBJECT
   18444                 :             :             | JSON_OBJECTAGG
   18445                 :             :             | JSON_QUERY
   18446                 :             :             | JSON_SCALAR
   18447                 :             :             | JSON_SERIALIZE
   18448                 :             :             | JSON_TABLE
   18449                 :             :             | JSON_VALUE
   18450                 :             :             | LEAST
   18451                 :             :             | MERGE_ACTION
   18452                 :             :             | NATIONAL
   18453                 :             :             | NCHAR
   18454                 :             :             | NONE
   18455                 :             :             | NORMALIZE
   18456                 :             :             | NULLIF
   18457                 :             :             | NUMERIC
   18458                 :             :             | OUT_P
   18459                 :             :             | OVERLAY
   18460                 :             :             | POSITION
   18461                 :             :             | PRECISION
   18462                 :             :             | REAL
   18463                 :             :             | ROW
   18464                 :             :             | SETOF
   18465                 :             :             | SMALLINT
   18466                 :             :             | SUBSTRING
   18467                 :             :             | TIME
   18468                 :             :             | TIMESTAMP
   18469                 :             :             | TREAT
   18470                 :             :             | TRIM
   18471                 :             :             | VALUES
   18472                 :             :             | VARCHAR
   18473                 :             :             | XMLATTRIBUTES
   18474                 :             :             | XMLCONCAT
   18475                 :             :             | XMLELEMENT
   18476                 :             :             | XMLEXISTS
   18477                 :             :             | XMLFOREST
   18478                 :             :             | XMLNAMESPACES
   18479                 :             :             | XMLPARSE
   18480                 :             :             | XMLPI
   18481                 :             :             | XMLROOT
   18482                 :             :             | XMLSERIALIZE
   18483                 :             :             | XMLTABLE
   18484                 :             :         ;
   18485                 :             : 
   18486                 :             : /* Type/function identifier --- keywords that can be type or function names.
   18487                 :             :  *
   18488                 :             :  * Most of these are keywords that are used as operators in expressions;
   18489                 :             :  * in general such keywords can't be column names because they would be
   18490                 :             :  * ambiguous with variables, but they are unambiguous as function identifiers.
   18491                 :             :  *
   18492                 :             :  * Do not include POSITION, SUBSTRING, etc here since they have explicit
   18493                 :             :  * productions in a_expr to support the goofy SQL9x argument syntax.
   18494                 :             :  * - thomas 2000-11-28
   18495                 :             :  */
   18496                 :             : type_func_name_keyword:
   18497                 :             :               AUTHORIZATION
   18498                 :             :             | BINARY
   18499                 :             :             | COLLATION
   18500                 :             :             | CONCURRENTLY
   18501                 :             :             | CROSS
   18502                 :             :             | CURRENT_SCHEMA
   18503                 :             :             | FREEZE
   18504                 :             :             | FULL
   18505                 :             :             | ILIKE
   18506                 :             :             | INNER_P
   18507                 :             :             | IS
   18508                 :             :             | ISNULL
   18509                 :             :             | JOIN
   18510                 :             :             | LEFT
   18511                 :             :             | LIKE
   18512                 :             :             | NATURAL
   18513                 :             :             | NOTNULL
   18514                 :             :             | OUTER_P
   18515                 :             :             | OVERLAPS
   18516                 :             :             | RIGHT
   18517                 :             :             | SIMILAR
   18518                 :             :             | TABLESAMPLE
   18519                 :             :             | VERBOSE
   18520                 :             :         ;
   18521                 :             : 
   18522                 :             : /* Reserved keyword --- these keywords are usable only as a ColLabel.
   18523                 :             :  *
   18524                 :             :  * Keywords appear here if they could not be distinguished from variable,
   18525                 :             :  * type, or function names in some contexts.  Don't put things here unless
   18526                 :             :  * forced to.
   18527                 :             :  */
   18528                 :             : reserved_keyword:
   18529                 :             :               ALL
   18530                 :             :             | ANALYSE
   18531                 :             :             | ANALYZE
   18532                 :             :             | AND
   18533                 :             :             | ANY
   18534                 :             :             | ARRAY
   18535                 :             :             | AS
   18536                 :             :             | ASC
   18537                 :             :             | ASYMMETRIC
   18538                 :             :             | BOTH
   18539                 :             :             | CASE
   18540                 :             :             | CAST
   18541                 :             :             | CHECK
   18542                 :             :             | COLLATE
   18543                 :             :             | COLUMN
   18544                 :             :             | CONSTRAINT
   18545                 :             :             | CREATE
   18546                 :             :             | CURRENT_CATALOG
   18547                 :             :             | CURRENT_DATE
   18548                 :             :             | CURRENT_ROLE
   18549                 :             :             | CURRENT_TIME
   18550                 :             :             | CURRENT_TIMESTAMP
   18551                 :             :             | CURRENT_USER
   18552                 :             :             | DEFAULT
   18553                 :             :             | DEFERRABLE
   18554                 :             :             | DESC
   18555                 :             :             | DISTINCT
   18556                 :             :             | DO
   18557                 :             :             | ELSE
   18558                 :             :             | END_P
   18559                 :             :             | EXCEPT
   18560                 :             :             | FALSE_P
   18561                 :             :             | FETCH
   18562                 :             :             | FOR
   18563                 :             :             | FOREIGN
   18564                 :             :             | FROM
   18565                 :             :             | GRANT
   18566                 :             :             | GROUP_P
   18567                 :             :             | HAVING
   18568                 :             :             | IN_P
   18569                 :             :             | INITIALLY
   18570                 :             :             | INTERSECT
   18571                 :             :             | INTO
   18572                 :             :             | LATERAL_P
   18573                 :             :             | LEADING
   18574                 :             :             | LIMIT
   18575                 :             :             | LOCALTIME
   18576                 :             :             | LOCALTIMESTAMP
   18577                 :             :             | NOT
   18578                 :             :             | NULL_P
   18579                 :             :             | OFFSET
   18580                 :             :             | ON
   18581                 :             :             | ONLY
   18582                 :             :             | OR
   18583                 :             :             | ORDER
   18584                 :             :             | PLACING
   18585                 :             :             | PRIMARY
   18586                 :             :             | REFERENCES
   18587                 :             :             | RETURNING
   18588                 :             :             | SELECT
   18589                 :             :             | SESSION_USER
   18590                 :             :             | SOME
   18591                 :             :             | SYMMETRIC
   18592                 :             :             | SYSTEM_USER
   18593                 :             :             | TABLE
   18594                 :             :             | THEN
   18595                 :             :             | TO
   18596                 :             :             | TRAILING
   18597                 :             :             | TRUE_P
   18598                 :             :             | UNION
   18599                 :             :             | UNIQUE
   18600                 :             :             | USER
   18601                 :             :             | USING
   18602                 :             :             | VARIADIC
   18603                 :             :             | WHEN
   18604                 :             :             | WHERE
   18605                 :             :             | WINDOW
   18606                 :             :             | WITH
   18607                 :             :         ;
   18608                 :             : 
   18609                 :             : /*
   18610                 :             :  * While all keywords can be used as column labels when preceded by AS,
   18611                 :             :  * not all of them can be used as a "bare" column label without AS.
   18612                 :             :  * Those that can be used as a bare label must be listed here,
   18613                 :             :  * in addition to appearing in one of the category lists above.
   18614                 :             :  *
   18615                 :             :  * Always add a new keyword to this list if possible.  Mark it BARE_LABEL
   18616                 :             :  * in kwlist.h if it is included here, or AS_LABEL if it is not.
   18617                 :             :  */
   18618                 :             : bare_label_keyword:
   18619                 :             :               ABORT_P
   18620                 :             :             | ABSENT
   18621                 :             :             | ABSOLUTE_P
   18622                 :             :             | ACCESS
   18623                 :             :             | ACTION
   18624                 :             :             | ADD_P
   18625                 :             :             | ADMIN
   18626                 :             :             | AFTER
   18627                 :             :             | AGGREGATE
   18628                 :             :             | ALL
   18629                 :             :             | ALSO
   18630                 :             :             | ALTER
   18631                 :             :             | ALWAYS
   18632                 :             :             | ANALYSE
   18633                 :             :             | ANALYZE
   18634                 :             :             | AND
   18635                 :             :             | ANY
   18636                 :             :             | ASC
   18637                 :             :             | ASENSITIVE
   18638                 :             :             | ASSERTION
   18639                 :             :             | ASSIGNMENT
   18640                 :             :             | ASYMMETRIC
   18641                 :             :             | AT
   18642                 :             :             | ATOMIC
   18643                 :             :             | ATTACH
   18644                 :             :             | ATTRIBUTE
   18645                 :             :             | AUTHORIZATION
   18646                 :             :             | BACKWARD
   18647                 :             :             | BEFORE
   18648                 :             :             | BEGIN_P
   18649                 :             :             | BETWEEN
   18650                 :             :             | BIGINT
   18651                 :             :             | BINARY
   18652                 :             :             | BIT
   18653                 :             :             | BOOLEAN_P
   18654                 :             :             | BOTH
   18655                 :             :             | BREADTH
   18656                 :             :             | BY
   18657                 :             :             | CACHE
   18658                 :             :             | CALL
   18659                 :             :             | CALLED
   18660                 :             :             | CASCADE
   18661                 :             :             | CASCADED
   18662                 :             :             | CASE
   18663                 :             :             | CAST
   18664                 :             :             | CATALOG_P
   18665                 :             :             | CHAIN
   18666                 :             :             | CHARACTERISTICS
   18667                 :             :             | CHECK
   18668                 :             :             | CHECKPOINT
   18669                 :             :             | CLASS
   18670                 :             :             | CLOSE
   18671                 :             :             | CLUSTER
   18672                 :             :             | COALESCE
   18673                 :             :             | COLLATE
   18674                 :             :             | COLLATION
   18675                 :             :             | COLUMN
   18676                 :             :             | COLUMNS
   18677                 :             :             | COMMENT
   18678                 :             :             | COMMENTS
   18679                 :             :             | COMMIT
   18680                 :             :             | COMMITTED
   18681                 :             :             | COMPRESSION
   18682                 :             :             | CONCURRENTLY
   18683                 :             :             | CONDITIONAL
   18684                 :             :             | CONFIGURATION
   18685                 :             :             | CONFLICT
   18686                 :             :             | CONNECTION
   18687                 :             :             | CONSTRAINT
   18688                 :             :             | CONSTRAINTS
   18689                 :             :             | CONTENT_P
   18690                 :             :             | CONTINUE_P
   18691                 :             :             | CONVERSION_P
   18692                 :             :             | COPY
   18693                 :             :             | COST
   18694                 :             :             | CROSS
   18695                 :             :             | CSV
   18696                 :             :             | CUBE
   18697                 :             :             | CURRENT_P
   18698                 :             :             | CURRENT_CATALOG
   18699                 :             :             | CURRENT_DATE
   18700                 :             :             | CURRENT_ROLE
   18701                 :             :             | CURRENT_SCHEMA
   18702                 :             :             | CURRENT_TIME
   18703                 :             :             | CURRENT_TIMESTAMP
   18704                 :             :             | CURRENT_USER
   18705                 :             :             | CURSOR
   18706                 :             :             | CYCLE
   18707                 :             :             | DATA_P
   18708                 :             :             | DATABASE
   18709                 :             :             | DEALLOCATE
   18710                 :             :             | DEC
   18711                 :             :             | DECIMAL_P
   18712                 :             :             | DECLARE
   18713                 :             :             | DEFAULT
   18714                 :             :             | DEFAULTS
   18715                 :             :             | DEFERRABLE
   18716                 :             :             | DEFERRED
   18717                 :             :             | DEFINER
   18718                 :             :             | DELETE_P
   18719                 :             :             | DELIMITER
   18720                 :             :             | DELIMITERS
   18721                 :             :             | DEPENDS
   18722                 :             :             | DEPTH
   18723                 :             :             | DESC
   18724                 :             :             | DETACH
   18725                 :             :             | DICTIONARY
   18726                 :             :             | DISABLE_P
   18727                 :             :             | DISCARD
   18728                 :             :             | DISTINCT
   18729                 :             :             | DO
   18730                 :             :             | DOCUMENT_P
   18731                 :             :             | DOMAIN_P
   18732                 :             :             | DOUBLE_P
   18733                 :             :             | DROP
   18734                 :             :             | EACH
   18735                 :             :             | ELSE
   18736                 :             :             | EMPTY_P
   18737                 :             :             | ENABLE_P
   18738                 :             :             | ENCODING
   18739                 :             :             | ENCRYPTED
   18740                 :             :             | END_P
   18741                 :             :             | ENFORCED
   18742                 :             :             | ENUM_P
   18743                 :             :             | ERROR_P
   18744                 :             :             | ESCAPE
   18745                 :             :             | EVENT
   18746                 :             :             | EXCLUDE
   18747                 :             :             | EXCLUDING
   18748                 :             :             | EXCLUSIVE
   18749                 :             :             | EXECUTE
   18750                 :             :             | EXISTS
   18751                 :             :             | EXPLAIN
   18752                 :             :             | EXPRESSION
   18753                 :             :             | EXTENSION
   18754                 :             :             | EXTERNAL
   18755                 :             :             | EXTRACT
   18756                 :             :             | FALSE_P
   18757                 :             :             | FAMILY
   18758                 :             :             | FINALIZE
   18759                 :             :             | FIRST_P
   18760                 :             :             | FLOAT_P
   18761                 :             :             | FOLLOWING
   18762                 :             :             | FORCE
   18763                 :             :             | FOREIGN
   18764                 :             :             | FORMAT
   18765                 :             :             | FORWARD
   18766                 :             :             | FREEZE
   18767                 :             :             | FULL
   18768                 :             :             | FUNCTION
   18769                 :             :             | FUNCTIONS
   18770                 :             :             | GENERATED
   18771                 :             :             | GLOBAL
   18772                 :             :             | GRANTED
   18773                 :             :             | GREATEST
   18774                 :             :             | GROUPING
   18775                 :             :             | GROUPS
   18776                 :             :             | HANDLER
   18777                 :             :             | HEADER_P
   18778                 :             :             | HOLD
   18779                 :             :             | IDENTITY_P
   18780                 :             :             | IF_P
   18781                 :             :             | ILIKE
   18782                 :             :             | IMMEDIATE
   18783                 :             :             | IMMUTABLE
   18784                 :             :             | IMPLICIT_P
   18785                 :             :             | IMPORT_P
   18786                 :             :             | IN_P
   18787                 :             :             | INCLUDE
   18788                 :             :             | INCLUDING
   18789                 :             :             | INCREMENT
   18790                 :             :             | INDENT
   18791                 :             :             | INDEX
   18792                 :             :             | INDEXES
   18793                 :             :             | INHERIT
   18794                 :             :             | INHERITS
   18795                 :             :             | INITIALLY
   18796                 :             :             | INLINE_P
   18797                 :             :             | INNER_P
   18798                 :             :             | INOUT
   18799                 :             :             | INPUT_P
   18800                 :             :             | INSENSITIVE
   18801                 :             :             | INSERT
   18802                 :             :             | INSTEAD
   18803                 :             :             | INT_P
   18804                 :             :             | INTEGER
   18805                 :             :             | INTERVAL
   18806                 :             :             | INVOKER
   18807                 :             :             | IS
   18808                 :             :             | ISOLATION
   18809                 :             :             | JOIN
   18810                 :             :             | JSON
   18811                 :             :             | JSON_ARRAY
   18812                 :             :             | JSON_ARRAYAGG
   18813                 :             :             | JSON_EXISTS
   18814                 :             :             | JSON_OBJECT
   18815                 :             :             | JSON_OBJECTAGG
   18816                 :             :             | JSON_QUERY
   18817                 :             :             | JSON_SCALAR
   18818                 :             :             | JSON_SERIALIZE
   18819                 :             :             | JSON_TABLE
   18820                 :             :             | JSON_VALUE
   18821                 :             :             | KEEP
   18822                 :             :             | KEY
   18823                 :             :             | KEYS
   18824                 :             :             | LABEL
   18825                 :             :             | LANGUAGE
   18826                 :             :             | LARGE_P
   18827                 :             :             | LAST_P
   18828                 :             :             | LATERAL_P
   18829                 :             :             | LEADING
   18830                 :             :             | LEAKPROOF
   18831                 :             :             | LEAST
   18832                 :             :             | LEFT
   18833                 :             :             | LEVEL
   18834                 :             :             | LIKE
   18835                 :             :             | LISTEN
   18836                 :             :             | LOAD
   18837                 :             :             | LOCAL
   18838                 :             :             | LOCALTIME
   18839                 :             :             | LOCALTIMESTAMP
   18840                 :             :             | LOCATION
   18841                 :             :             | LOCK_P
   18842                 :             :             | LOCKED
   18843                 :             :             | LOGGED
   18844                 :             :             | LSN_P
   18845                 :             :             | MAPPING
   18846                 :             :             | MATCH
   18847                 :             :             | MATCHED
   18848                 :             :             | MATERIALIZED
   18849                 :             :             | MAXVALUE
   18850                 :             :             | MERGE
   18851                 :             :             | MERGE_ACTION
   18852                 :             :             | METHOD
   18853                 :             :             | MINVALUE
   18854                 :             :             | MODE
   18855                 :             :             | MOVE
   18856                 :             :             | NAME_P
   18857                 :             :             | NAMES
   18858                 :             :             | NATIONAL
   18859                 :             :             | NATURAL
   18860                 :             :             | NCHAR
   18861                 :             :             | NESTED
   18862                 :             :             | NEW
   18863                 :             :             | NEXT
   18864                 :             :             | NFC
   18865                 :             :             | NFD
   18866                 :             :             | NFKC
   18867                 :             :             | NFKD
   18868                 :             :             | NO
   18869                 :             :             | NONE
   18870                 :             :             | NORMALIZE
   18871                 :             :             | NORMALIZED
   18872                 :             :             | NOT
   18873                 :             :             | NOTHING
   18874                 :             :             | NOTIFY
   18875                 :             :             | NOWAIT
   18876                 :             :             | NULL_P
   18877                 :             :             | NULLIF
   18878                 :             :             | NULLS_P
   18879                 :             :             | NUMERIC
   18880                 :             :             | OBJECT_P
   18881                 :             :             | OBJECTS_P
   18882                 :             :             | OF
   18883                 :             :             | OFF
   18884                 :             :             | OIDS
   18885                 :             :             | OLD
   18886                 :             :             | OMIT
   18887                 :             :             | ONLY
   18888                 :             :             | OPERATOR
   18889                 :             :             | OPTION
   18890                 :             :             | OPTIONS
   18891                 :             :             | OR
   18892                 :             :             | ORDINALITY
   18893                 :             :             | OTHERS
   18894                 :             :             | OUT_P
   18895                 :             :             | OUTER_P
   18896                 :             :             | OVERLAY
   18897                 :             :             | OVERRIDING
   18898                 :             :             | OWNED
   18899                 :             :             | OWNER
   18900                 :             :             | PARALLEL
   18901                 :             :             | PARAMETER
   18902                 :             :             | PARSER
   18903                 :             :             | PARTIAL
   18904                 :             :             | PARTITION
   18905                 :             :             | PASSING
   18906                 :             :             | PASSWORD
   18907                 :             :             | PATH
   18908                 :             :             | PERIOD
   18909                 :             :             | PLACING
   18910                 :             :             | PLAN
   18911                 :             :             | PLANS
   18912                 :             :             | POLICY
   18913                 :             :             | POSITION
   18914                 :             :             | PRECEDING
   18915                 :             :             | PREPARE
   18916                 :             :             | PREPARED
   18917                 :             :             | PRESERVE
   18918                 :             :             | PRIMARY
   18919                 :             :             | PRIOR
   18920                 :             :             | PRIVILEGES
   18921                 :             :             | PROCEDURAL
   18922                 :             :             | PROCEDURE
   18923                 :             :             | PROCEDURES
   18924                 :             :             | PROGRAM
   18925                 :             :             | PUBLICATION
   18926                 :             :             | QUOTE
   18927                 :             :             | QUOTES
   18928                 :             :             | RANGE
   18929                 :             :             | READ
   18930                 :             :             | REAL
   18931                 :             :             | REASSIGN
   18932                 :             :             | RECURSIVE
   18933                 :             :             | REF_P
   18934                 :             :             | REFERENCES
   18935                 :             :             | REFERENCING
   18936                 :             :             | REFRESH
   18937                 :             :             | REINDEX
   18938                 :             :             | RELATIVE_P
   18939                 :             :             | RELEASE
   18940                 :             :             | RENAME
   18941                 :             :             | REPACK
   18942                 :             :             | REPEATABLE
   18943                 :             :             | REPLACE
   18944                 :             :             | REPLICA
   18945                 :             :             | RESET
   18946                 :             :             | RESTART
   18947                 :             :             | RESTRICT
   18948                 :             :             | RETURN
   18949                 :             :             | RETURNS
   18950                 :             :             | REVOKE
   18951                 :             :             | RIGHT
   18952                 :             :             | ROLE
   18953                 :             :             | ROLLBACK
   18954                 :             :             | ROLLUP
   18955                 :             :             | ROUTINE
   18956                 :             :             | ROUTINES
   18957                 :             :             | ROW
   18958                 :             :             | ROWS
   18959                 :             :             | RULE
   18960                 :             :             | SAVEPOINT
   18961                 :             :             | SCALAR
   18962                 :             :             | SCHEMA
   18963                 :             :             | SCHEMAS
   18964                 :             :             | SCROLL
   18965                 :             :             | SEARCH
   18966                 :             :             | SECURITY
   18967                 :             :             | SELECT
   18968                 :             :             | SEQUENCE
   18969                 :             :             | SEQUENCES
   18970                 :             :             | SERIALIZABLE
   18971                 :             :             | SERVER
   18972                 :             :             | SESSION
   18973                 :             :             | SESSION_USER
   18974                 :             :             | SET
   18975                 :             :             | SETOF
   18976                 :             :             | SETS
   18977                 :             :             | SHARE
   18978                 :             :             | SHOW
   18979                 :             :             | SIMILAR
   18980                 :             :             | SIMPLE
   18981                 :             :             | SKIP
   18982                 :             :             | SMALLINT
   18983                 :             :             | SNAPSHOT
   18984                 :             :             | SOME
   18985                 :             :             | SOURCE
   18986                 :             :             | SQL_P
   18987                 :             :             | STABLE
   18988                 :             :             | STANDALONE_P
   18989                 :             :             | START
   18990                 :             :             | STATEMENT
   18991                 :             :             | STATISTICS
   18992                 :             :             | STDIN
   18993                 :             :             | STDOUT
   18994                 :             :             | STORAGE
   18995                 :             :             | STORED
   18996                 :             :             | STRICT_P
   18997                 :             :             | STRING_P
   18998                 :             :             | STRIP_P
   18999                 :             :             | SUBSCRIPTION
   19000                 :             :             | SUBSTRING
   19001                 :             :             | SUPPORT
   19002                 :             :             | SYMMETRIC
   19003                 :             :             | SYSID
   19004                 :             :             | SYSTEM_P
   19005                 :             :             | SYSTEM_USER
   19006                 :             :             | TABLE
   19007                 :             :             | TABLES
   19008                 :             :             | TABLESAMPLE
   19009                 :             :             | TABLESPACE
   19010                 :             :             | TARGET
   19011                 :             :             | TEMP
   19012                 :             :             | TEMPLATE
   19013                 :             :             | TEMPORARY
   19014                 :             :             | TEXT_P
   19015                 :             :             | THEN
   19016                 :             :             | TIES
   19017                 :             :             | TIME
   19018                 :             :             | TIMESTAMP
   19019                 :             :             | TRAILING
   19020                 :             :             | TRANSACTION
   19021                 :             :             | TRANSFORM
   19022                 :             :             | TREAT
   19023                 :             :             | TRIGGER
   19024                 :             :             | TRIM
   19025                 :             :             | TRUE_P
   19026                 :             :             | TRUNCATE
   19027                 :             :             | TRUSTED
   19028                 :             :             | TYPE_P
   19029                 :             :             | TYPES_P
   19030                 :             :             | UESCAPE
   19031                 :             :             | UNBOUNDED
   19032                 :             :             | UNCOMMITTED
   19033                 :             :             | UNCONDITIONAL
   19034                 :             :             | UNENCRYPTED
   19035                 :             :             | UNIQUE
   19036                 :             :             | UNKNOWN
   19037                 :             :             | UNLISTEN
   19038                 :             :             | UNLOGGED
   19039                 :             :             | UNTIL
   19040                 :             :             | UPDATE
   19041                 :             :             | USER
   19042                 :             :             | USING
   19043                 :             :             | VACUUM
   19044                 :             :             | VALID
   19045                 :             :             | VALIDATE
   19046                 :             :             | VALIDATOR
   19047                 :             :             | VALUE_P
   19048                 :             :             | VALUES
   19049                 :             :             | VARCHAR
   19050                 :             :             | VARIADIC
   19051                 :             :             | VERBOSE
   19052                 :             :             | VERSION_P
   19053                 :             :             | VIEW
   19054                 :             :             | VIEWS
   19055                 :             :             | VIRTUAL
   19056                 :             :             | VOLATILE
   19057                 :             :             | WAIT
   19058                 :             :             | WHEN
   19059                 :             :             | WHITESPACE_P
   19060                 :             :             | WORK
   19061                 :             :             | WRAPPER
   19062                 :             :             | WRITE
   19063                 :             :             | XML_P
   19064                 :             :             | XMLATTRIBUTES
   19065                 :             :             | XMLCONCAT
   19066                 :             :             | XMLELEMENT
   19067                 :             :             | XMLEXISTS
   19068                 :             :             | XMLFOREST
   19069                 :             :             | XMLNAMESPACES
   19070                 :             :             | XMLPARSE
   19071                 :             :             | XMLPI
   19072                 :             :             | XMLROOT
   19073                 :             :             | XMLSERIALIZE
   19074                 :             :             | XMLTABLE
   19075                 :             :             | YES_P
   19076                 :             :             | ZONE
   19077                 :             :         ;
   19078                 :             : 
   19079                 :             : %%
   19080                 :             : 
   19081                 :             : /*
   19082                 :             :  * The signature of this function is required by bison.  However, we
   19083                 :             :  * ignore the passed yylloc and instead use the last token position
   19084                 :             :  * available from the scanner.
   19085                 :             :  */
   19086                 :             : static void
   19087                 :         465 : base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner, const char *msg)
   19088                 :             : {
   19089                 :         465 :     parser_yyerror(msg);
   19090                 :             : }
   19091                 :             : 
   19092                 :             : static RawStmt *
   19093                 :      517552 : makeRawStmt(Node *stmt, int stmt_location)
   19094                 :             : {
   19095                 :      517552 :     RawStmt    *rs = makeNode(RawStmt);
   19096                 :             : 
   19097                 :      517552 :     rs->stmt = stmt;
   19098                 :      517552 :     rs->stmt_location = stmt_location;
   19099                 :      517552 :     rs->stmt_len = 0;            /* might get changed later */
   19100                 :      517552 :     return rs;
   19101                 :             : }
   19102                 :             : 
   19103                 :             : /* Adjust a RawStmt to reflect that it doesn't run to the end of the string */
   19104                 :             : static void
   19105                 :      386672 : updateRawStmtEnd(RawStmt *rs, int end_location)
   19106                 :             : {
   19107                 :             :     /*
   19108                 :             :      * If we already set the length, don't change it.  This is for situations
   19109                 :             :      * like "select foo ;; select bar" where the same statement will be last
   19110                 :             :      * in the string for more than one semicolon.
   19111                 :             :      */
   19112         [ +  + ]:      386672 :     if (rs->stmt_len > 0)
   19113                 :         337 :         return;
   19114                 :             : 
   19115                 :             :     /* OK, update length of RawStmt */
   19116                 :      386335 :     rs->stmt_len = end_location - rs->stmt_location;
   19117                 :             : }
   19118                 :             : 
   19119                 :             : static Node *
   19120                 :     1157320 : makeColumnRef(char *colname, List *indirection,
   19121                 :             :               int location, core_yyscan_t yyscanner)
   19122                 :             : {
   19123                 :             :     /*
   19124                 :             :      * Generate a ColumnRef node, with an A_Indirection node added if there is
   19125                 :             :      * any subscripting in the specified indirection list.  However, any field
   19126                 :             :      * selection at the start of the indirection list must be transposed into
   19127                 :             :      * the "fields" part of the ColumnRef node.
   19128                 :             :      */
   19129                 :     1157320 :     ColumnRef  *c = makeNode(ColumnRef);
   19130                 :     1157320 :     int         nfields = 0;
   19131                 :             :     ListCell   *l;
   19132                 :             : 
   19133                 :     1157320 :     c->location = location;
   19134   [ +  +  +  +  :     1845894 :     foreach(l, indirection)
                   +  + ]
   19135                 :             :     {
   19136         [ +  + ]:      694998 :         if (IsA(lfirst(l), A_Indices))
   19137                 :             :         {
   19138                 :        6424 :             A_Indirection *i = makeNode(A_Indirection);
   19139                 :             : 
   19140         [ +  + ]:        6424 :             if (nfields == 0)
   19141                 :             :             {
   19142                 :             :                 /* easy case - all indirection goes to A_Indirection */
   19143                 :        4606 :                 c->fields = list_make1(makeString(colname));
   19144                 :        4606 :                 i->indirection = check_indirection(indirection, yyscanner);
   19145                 :             :             }
   19146                 :             :             else
   19147                 :             :             {
   19148                 :             :                 /* got to split the list in two */
   19149                 :        1818 :                 i->indirection = check_indirection(list_copy_tail(indirection,
   19150                 :             :                                                                   nfields),
   19151                 :             :                                                    yyscanner);
   19152                 :        1818 :                 indirection = list_truncate(indirection, nfields);
   19153                 :        1818 :                 c->fields = lcons(makeString(colname), indirection);
   19154                 :             :             }
   19155                 :        6424 :             i->arg = (Node *) c;
   19156                 :        6424 :             return (Node *) i;
   19157                 :             :         }
   19158         [ +  + ]:      688574 :         else if (IsA(lfirst(l), A_Star))
   19159                 :             :         {
   19160                 :             :             /* We only allow '*' at the end of a ColumnRef */
   19161         [ -  + ]:        3783 :             if (lnext(indirection, l) != NULL)
   19162                 :           0 :                 parser_yyerror("improper use of \"*\"");
   19163                 :             :         }
   19164                 :      688574 :         nfields++;
   19165                 :             :     }
   19166                 :             :     /* No subscripting, so all indirection gets added to field list */
   19167                 :     1150896 :     c->fields = lcons(makeString(colname), indirection);
   19168                 :     1150896 :     return (Node *) c;
   19169                 :             : }
   19170                 :             : 
   19171                 :             : static Node *
   19172                 :      193635 : makeTypeCast(Node *arg, TypeName *typename, int location)
   19173                 :             : {
   19174                 :      193635 :     TypeCast   *n = makeNode(TypeCast);
   19175                 :             : 
   19176                 :      193635 :     n->arg = arg;
   19177                 :      193635 :     n->typeName = typename;
   19178                 :      193635 :     n->location = location;
   19179                 :      193635 :     return (Node *) n;
   19180                 :             : }
   19181                 :             : 
   19182                 :             : static Node *
   19183                 :       10668 : makeStringConstCast(char *str, int location, TypeName *typename)
   19184                 :             : {
   19185                 :       10668 :     Node       *s = makeStringConst(str, location);
   19186                 :             : 
   19187                 :       10668 :     return makeTypeCast(s, typename, -1);
   19188                 :             : }
   19189                 :             : 
   19190                 :             : static Node *
   19191                 :      267504 : makeIntConst(int val, int location)
   19192                 :             : {
   19193                 :      267504 :     A_Const    *n = makeNode(A_Const);
   19194                 :             : 
   19195                 :      267504 :     n->val.ival.type = T_Integer;
   19196                 :      267504 :     n->val.ival.ival = val;
   19197                 :      267504 :     n->location = location;
   19198                 :             : 
   19199                 :      267504 :     return (Node *) n;
   19200                 :             : }
   19201                 :             : 
   19202                 :             : static Node *
   19203                 :        8079 : makeFloatConst(char *str, int location)
   19204                 :             : {
   19205                 :        8079 :     A_Const    *n = makeNode(A_Const);
   19206                 :             : 
   19207                 :        8079 :     n->val.fval.type = T_Float;
   19208                 :        8079 :     n->val.fval.fval = str;
   19209                 :        8079 :     n->location = location;
   19210                 :             : 
   19211                 :        8079 :     return (Node *) n;
   19212                 :             : }
   19213                 :             : 
   19214                 :             : static Node *
   19215                 :       39186 : makeBoolAConst(bool state, int location)
   19216                 :             : {
   19217                 :       39186 :     A_Const    *n = makeNode(A_Const);
   19218                 :             : 
   19219                 :       39186 :     n->val.boolval.type = T_Boolean;
   19220                 :       39186 :     n->val.boolval.boolval = state;
   19221                 :       39186 :     n->location = location;
   19222                 :             : 
   19223                 :       39186 :     return (Node *) n;
   19224                 :             : }
   19225                 :             : 
   19226                 :             : static Node *
   19227                 :        2727 : makeBitStringConst(char *str, int location)
   19228                 :             : {
   19229                 :        2727 :     A_Const    *n = makeNode(A_Const);
   19230                 :             : 
   19231                 :        2727 :     n->val.bsval.type = T_BitString;
   19232                 :        2727 :     n->val.bsval.bsval = str;
   19233                 :        2727 :     n->location = location;
   19234                 :             : 
   19235                 :        2727 :     return (Node *) n;
   19236                 :             : }
   19237                 :             : 
   19238                 :             : static Node *
   19239                 :       43026 : makeNullAConst(int location)
   19240                 :             : {
   19241                 :       43026 :     A_Const    *n = makeNode(A_Const);
   19242                 :             : 
   19243                 :       43026 :     n->isnull = true;
   19244                 :       43026 :     n->location = location;
   19245                 :             : 
   19246                 :       43026 :     return (Node *) n;
   19247                 :             : }
   19248                 :             : 
   19249                 :             : static Node *
   19250                 :        3169 : makeAConst(Node *v, int location)
   19251                 :             : {
   19252                 :             :     Node       *n;
   19253                 :             : 
   19254      [ +  +  - ]:        3169 :     switch (v->type)
   19255                 :             :     {
   19256                 :         136 :         case T_Float:
   19257                 :         136 :             n = makeFloatConst(castNode(Float, v)->fval, location);
   19258                 :         136 :             break;
   19259                 :             : 
   19260                 :        3033 :         case T_Integer:
   19261                 :        3033 :             n = makeIntConst(castNode(Integer, v)->ival, location);
   19262                 :        3033 :             break;
   19263                 :             : 
   19264                 :           0 :         default:
   19265                 :             :             /* currently not used */
   19266                 :             :             Assert(false);
   19267                 :           0 :             n = NULL;
   19268                 :             :     }
   19269                 :             : 
   19270                 :        3169 :     return n;
   19271                 :             : }
   19272                 :             : 
   19273                 :             : /* makeRoleSpec
   19274                 :             :  * Create a RoleSpec with the given type
   19275                 :             :  */
   19276                 :             : static RoleSpec *
   19277                 :       15937 : makeRoleSpec(RoleSpecType type, int location)
   19278                 :             : {
   19279                 :       15937 :     RoleSpec   *spec = makeNode(RoleSpec);
   19280                 :             : 
   19281                 :       15937 :     spec->roletype = type;
   19282                 :       15937 :     spec->location = location;
   19283                 :             : 
   19284                 :       15937 :     return spec;
   19285                 :             : }
   19286                 :             : 
   19287                 :             : /* check_qualified_name --- check the result of qualified_name production
   19288                 :             :  *
   19289                 :             :  * It's easiest to let the grammar production for qualified_name allow
   19290                 :             :  * subscripts and '*', which we then must reject here.
   19291                 :             :  */
   19292                 :             : static void
   19293                 :      159071 : check_qualified_name(List *names, core_yyscan_t yyscanner)
   19294                 :             : {
   19295                 :             :     ListCell   *i;
   19296                 :             : 
   19297   [ +  -  +  +  :      318142 :     foreach(i, names)
                   +  + ]
   19298                 :             :     {
   19299         [ -  + ]:      159071 :         if (!IsA(lfirst(i), String))
   19300                 :           0 :             parser_yyerror("syntax error");
   19301                 :             :     }
   19302                 :      159071 : }
   19303                 :             : 
   19304                 :             : /* check_func_name --- check the result of func_name production
   19305                 :             :  *
   19306                 :             :  * It's easiest to let the grammar production for func_name allow subscripts
   19307                 :             :  * and '*', which we then must reject here.
   19308                 :             :  */
   19309                 :             : static List *
   19310                 :       86979 : check_func_name(List *names, core_yyscan_t yyscanner)
   19311                 :             : {
   19312                 :             :     ListCell   *i;
   19313                 :             : 
   19314   [ +  -  +  +  :      260937 :     foreach(i, names)
                   +  + ]
   19315                 :             :     {
   19316         [ -  + ]:      173958 :         if (!IsA(lfirst(i), String))
   19317                 :           0 :             parser_yyerror("syntax error");
   19318                 :             :     }
   19319                 :       86979 :     return names;
   19320                 :             : }
   19321                 :             : 
   19322                 :             : /* check_indirection --- check the result of indirection production
   19323                 :             :  *
   19324                 :             :  * We only allow '*' at the end of the list, but it's hard to enforce that
   19325                 :             :  * in the grammar, so do it here.
   19326                 :             :  */
   19327                 :             : static List *
   19328                 :       53052 : check_indirection(List *indirection, core_yyscan_t yyscanner)
   19329                 :             : {
   19330                 :             :     ListCell   *l;
   19331                 :             : 
   19332   [ +  +  +  +  :       72577 :     foreach(l, indirection)
                   +  + ]
   19333                 :             :     {
   19334         [ +  + ]:       19525 :         if (IsA(lfirst(l), A_Star))
   19335                 :             :         {
   19336         [ -  + ]:         908 :             if (lnext(indirection, l) != NULL)
   19337                 :           0 :                 parser_yyerror("improper use of \"*\"");
   19338                 :             :         }
   19339                 :             :     }
   19340                 :       53052 :     return indirection;
   19341                 :             : }
   19342                 :             : 
   19343                 :             : /* extractArgTypes()
   19344                 :             :  * Given a list of FunctionParameter nodes, extract a list of just the
   19345                 :             :  * argument types (TypeNames) for input parameters only.  This is what
   19346                 :             :  * is needed to look up an existing function, which is what is wanted by
   19347                 :             :  * the productions that use this call.
   19348                 :             :  */
   19349                 :             : static List *
   19350                 :        5572 : extractArgTypes(List *parameters)
   19351                 :             : {
   19352                 :        5572 :     List       *result = NIL;
   19353                 :             :     ListCell   *i;
   19354                 :             : 
   19355   [ +  +  +  +  :       13840 :     foreach(i, parameters)
                   +  + ]
   19356                 :             :     {
   19357                 :        8268 :         FunctionParameter *p = (FunctionParameter *) lfirst(i);
   19358                 :             : 
   19359   [ +  +  +  - ]:        8268 :         if (p->mode != FUNC_PARAM_OUT && p->mode != FUNC_PARAM_TABLE)
   19360                 :        8175 :             result = lappend(result, p->argType);
   19361                 :             :     }
   19362                 :        5572 :     return result;
   19363                 :             : }
   19364                 :             : 
   19365                 :             : /* extractAggrArgTypes()
   19366                 :             :  * As above, but work from the output of the aggr_args production.
   19367                 :             :  */
   19368                 :             : static List *
   19369                 :         220 : extractAggrArgTypes(List *aggrargs)
   19370                 :             : {
   19371                 :             :     Assert(list_length(aggrargs) == 2);
   19372                 :         220 :     return extractArgTypes((List *) linitial(aggrargs));
   19373                 :             : }
   19374                 :             : 
   19375                 :             : /* makeOrderedSetArgs()
   19376                 :             :  * Build the result of the aggr_args production (which see the comments for).
   19377                 :             :  * This handles only the case where both given lists are nonempty, so that
   19378                 :             :  * we have to deal with multiple VARIADIC arguments.
   19379                 :             :  */
   19380                 :             : static List *
   19381                 :          20 : makeOrderedSetArgs(List *directargs, List *orderedargs,
   19382                 :             :                    core_yyscan_t yyscanner)
   19383                 :             : {
   19384                 :          20 :     FunctionParameter *lastd = (FunctionParameter *) llast(directargs);
   19385                 :             :     Integer    *ndirectargs;
   19386                 :             : 
   19387                 :             :     /* No restriction unless last direct arg is VARIADIC */
   19388         [ +  + ]:          20 :     if (lastd->mode == FUNC_PARAM_VARIADIC)
   19389                 :             :     {
   19390                 :          10 :         FunctionParameter *firsto = (FunctionParameter *) linitial(orderedargs);
   19391                 :             : 
   19392                 :             :         /*
   19393                 :             :          * We ignore the names, though the aggr_arg production allows them; it
   19394                 :             :          * doesn't allow default values, so those need not be checked.
   19395                 :             :          */
   19396         [ +  - ]:          10 :         if (list_length(orderedargs) != 1 ||
   19397         [ +  - ]:          10 :             firsto->mode != FUNC_PARAM_VARIADIC ||
   19398         [ -  + ]:          10 :             !equal(lastd->argType, firsto->argType))
   19399         [ #  # ]:           0 :             ereport(ERROR,
   19400                 :             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19401                 :             :                      errmsg("an ordered-set aggregate with a VARIADIC direct argument must have one VARIADIC aggregated argument of the same data type"),
   19402                 :             :                      parser_errposition(firsto->location)));
   19403                 :             : 
   19404                 :             :         /* OK, drop the duplicate VARIADIC argument from the internal form */
   19405                 :          10 :         orderedargs = NIL;
   19406                 :             :     }
   19407                 :             : 
   19408                 :             :     /* don't merge into the next line, as list_concat changes directargs */
   19409                 :          20 :     ndirectargs = makeInteger(list_length(directargs));
   19410                 :             : 
   19411                 :          20 :     return list_make2(list_concat(directargs, orderedargs),
   19412                 :             :                       ndirectargs);
   19413                 :             : }
   19414                 :             : 
   19415                 :             : /* insertSelectOptions()
   19416                 :             :  * Insert ORDER BY, etc into an already-constructed SelectStmt.
   19417                 :             :  *
   19418                 :             :  * This routine is just to avoid duplicating code in SelectStmt productions.
   19419                 :             :  */
   19420                 :             : static void
   19421                 :       57664 : insertSelectOptions(SelectStmt *stmt,
   19422                 :             :                     List *sortClause, List *lockingClause,
   19423                 :             :                     SelectLimit *limitClause,
   19424                 :             :                     WithClause *withClause,
   19425                 :             :                     core_yyscan_t yyscanner)
   19426                 :             : {
   19427                 :             :     Assert(IsA(stmt, SelectStmt));
   19428                 :             : 
   19429                 :             :     /*
   19430                 :             :      * Tests here are to reject constructs like
   19431                 :             :      *  (SELECT foo ORDER BY bar) ORDER BY baz
   19432                 :             :      */
   19433         [ +  + ]:       57664 :     if (sortClause)
   19434                 :             :     {
   19435         [ -  + ]:       49683 :         if (stmt->sortClause)
   19436         [ #  # ]:           0 :             ereport(ERROR,
   19437                 :             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19438                 :             :                      errmsg("multiple ORDER BY clauses not allowed"),
   19439                 :             :                      parser_errposition(exprLocation((Node *) sortClause))));
   19440                 :       49683 :         stmt->sortClause = sortClause;
   19441                 :             :     }
   19442                 :             :     /* We can handle multiple locking clauses, though */
   19443                 :       57664 :     stmt->lockingClause = list_concat(stmt->lockingClause, lockingClause);
   19444   [ +  +  +  + ]:       57664 :     if (limitClause && limitClause->limitOffset)
   19445                 :             :     {
   19446         [ -  + ]:         610 :         if (stmt->limitOffset)
   19447         [ #  # ]:           0 :             ereport(ERROR,
   19448                 :             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19449                 :             :                      errmsg("multiple OFFSET clauses not allowed"),
   19450                 :             :                      parser_errposition(limitClause->offsetLoc)));
   19451                 :         610 :         stmt->limitOffset = limitClause->limitOffset;
   19452                 :             :     }
   19453   [ +  +  +  + ]:       57664 :     if (limitClause && limitClause->limitCount)
   19454                 :             :     {
   19455         [ -  + ]:        2920 :         if (stmt->limitCount)
   19456         [ #  # ]:           0 :             ereport(ERROR,
   19457                 :             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19458                 :             :                      errmsg("multiple LIMIT clauses not allowed"),
   19459                 :             :                      parser_errposition(limitClause->countLoc)));
   19460                 :        2920 :         stmt->limitCount = limitClause->limitCount;
   19461                 :             :     }
   19462         [ +  + ]:       57664 :     if (limitClause)
   19463                 :             :     {
   19464                 :             :         /* If there was a conflict, we must have detected it above */
   19465                 :             :         Assert(!stmt->limitOption);
   19466   [ +  +  +  + ]:        3318 :         if (!stmt->sortClause && limitClause->limitOption == LIMIT_OPTION_WITH_TIES)
   19467         [ +  - ]:           4 :             ereport(ERROR,
   19468                 :             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19469                 :             :                      errmsg("WITH TIES cannot be specified without ORDER BY clause"),
   19470                 :             :                      parser_errposition(limitClause->optionLoc)));
   19471   [ +  +  +  + ]:        3314 :         if (limitClause->limitOption == LIMIT_OPTION_WITH_TIES && stmt->lockingClause)
   19472                 :             :         {
   19473                 :             :             ListCell   *lc;
   19474                 :             : 
   19475   [ +  -  +  -  :           4 :             foreach(lc, stmt->lockingClause)
                   +  - ]
   19476                 :             :             {
   19477                 :           4 :                 LockingClause *lock = lfirst_node(LockingClause, lc);
   19478                 :             : 
   19479         [ +  - ]:           4 :                 if (lock->waitPolicy == LockWaitSkip)
   19480         [ +  - ]:           4 :                     ereport(ERROR,
   19481                 :             :                             (errcode(ERRCODE_SYNTAX_ERROR),
   19482                 :             :                              errmsg("%s and %s options cannot be used together",
   19483                 :             :                                     "SKIP LOCKED", "WITH TIES"),
   19484                 :             :                              parser_errposition(limitClause->optionLoc)));
   19485                 :             :             }
   19486                 :             :         }
   19487                 :        3310 :         stmt->limitOption = limitClause->limitOption;
   19488                 :             :     }
   19489         [ +  + ]:       57656 :     if (withClause)
   19490                 :             :     {
   19491         [ -  + ]:        2055 :         if (stmt->withClause)
   19492         [ #  # ]:           0 :             ereport(ERROR,
   19493                 :             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19494                 :             :                      errmsg("multiple WITH clauses not allowed"),
   19495                 :             :                      parser_errposition(exprLocation((Node *) withClause))));
   19496                 :        2055 :         stmt->withClause = withClause;
   19497                 :             :     }
   19498                 :       57656 : }
   19499                 :             : 
   19500                 :             : static Node *
   19501                 :       13058 : makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg)
   19502                 :             : {
   19503                 :       13058 :     SelectStmt *n = makeNode(SelectStmt);
   19504                 :             : 
   19505                 :       13058 :     n->op = op;
   19506                 :       13058 :     n->all = all;
   19507                 :       13058 :     n->larg = (SelectStmt *) larg;
   19508                 :       13058 :     n->rarg = (SelectStmt *) rarg;
   19509                 :       13058 :     return (Node *) n;
   19510                 :             : }
   19511                 :             : 
   19512                 :             : /* SystemFuncName()
   19513                 :             :  * Build a properly-qualified reference to a built-in function.
   19514                 :             :  */
   19515                 :             : List *
   19516                 :       13063 : SystemFuncName(char *name)
   19517                 :             : {
   19518                 :       13063 :     return list_make2(makeString("pg_catalog"), makeString(name));
   19519                 :             : }
   19520                 :             : 
   19521                 :             : /* SystemTypeName()
   19522                 :             :  * Build a properly-qualified reference to a built-in type.
   19523                 :             :  *
   19524                 :             :  * typmod is defaulted, but may be changed afterwards by caller.
   19525                 :             :  * Likewise for the location.
   19526                 :             :  */
   19527                 :             : TypeName *
   19528                 :       72227 : SystemTypeName(char *name)
   19529                 :             : {
   19530                 :       72227 :     return makeTypeNameFromNameList(list_make2(makeString("pg_catalog"),
   19531                 :             :                                                makeString(name)));
   19532                 :             : }
   19533                 :             : 
   19534                 :             : /* doNegate()
   19535                 :             :  * Handle negation of a numeric constant.
   19536                 :             :  *
   19537                 :             :  * Formerly, we did this here because the optimizer couldn't cope with
   19538                 :             :  * indexquals that looked like "var = -4" --- it wants "var = const"
   19539                 :             :  * and a unary minus operator applied to a constant didn't qualify.
   19540                 :             :  * As of Postgres 7.0, that problem doesn't exist anymore because there
   19541                 :             :  * is a constant-subexpression simplifier in the optimizer.  However,
   19542                 :             :  * there's still a good reason for doing this here, which is that we can
   19543                 :             :  * postpone committing to a particular internal representation for simple
   19544                 :             :  * negative constants.  It's better to leave "-123.456" in string form
   19545                 :             :  * until we know what the desired type is.
   19546                 :             :  */
   19547                 :             : static Node *
   19548                 :        6445 : doNegate(Node *n, int location)
   19549                 :             : {
   19550         [ +  + ]:        6445 :     if (IsA(n, A_Const))
   19551                 :             :     {
   19552                 :        5773 :         A_Const    *con = (A_Const *) n;
   19553                 :             : 
   19554                 :             :         /* report the constant's location as that of the '-' sign */
   19555                 :        5773 :         con->location = location;
   19556                 :             : 
   19557         [ +  + ]:        5773 :         if (IsA(&con->val, Integer))
   19558                 :             :         {
   19559                 :        5117 :             con->val.ival.ival = -con->val.ival.ival;
   19560                 :        5117 :             return n;
   19561                 :             :         }
   19562         [ +  - ]:         656 :         if (IsA(&con->val, Float))
   19563                 :             :         {
   19564                 :         656 :             doNegateFloat(&con->val.fval);
   19565                 :         656 :             return n;
   19566                 :             :         }
   19567                 :             :     }
   19568                 :             : 
   19569                 :         672 :     return (Node *) makeSimpleA_Expr(AEXPR_OP, "-", NULL, n, location);
   19570                 :             : }
   19571                 :             : 
   19572                 :             : static void
   19573                 :         669 : doNegateFloat(Float *v)
   19574                 :             : {
   19575                 :         669 :     char       *oldval = v->fval;
   19576                 :             : 
   19577         [ -  + ]:         669 :     if (*oldval == '+')
   19578                 :           0 :         oldval++;
   19579         [ -  + ]:         669 :     if (*oldval == '-')
   19580                 :           0 :         v->fval = oldval + 1;    /* just strip the '-' */
   19581                 :             :     else
   19582                 :         669 :         v->fval = psprintf("-%s", oldval);
   19583                 :         669 : }
   19584                 :             : 
   19585                 :             : static Node *
   19586                 :      153043 : makeAndExpr(Node *lexpr, Node *rexpr, int location)
   19587                 :             : {
   19588                 :             :     /* Flatten "a AND b AND c ..." to a single BoolExpr on sight */
   19589         [ +  + ]:      153043 :     if (IsA(lexpr, BoolExpr))
   19590                 :             :     {
   19591                 :       71615 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19592                 :             : 
   19593         [ +  + ]:       71615 :         if (blexpr->boolop == AND_EXPR)
   19594                 :             :         {
   19595                 :       68027 :             blexpr->args = lappend(blexpr->args, rexpr);
   19596                 :       68027 :             return (Node *) blexpr;
   19597                 :             :         }
   19598                 :             :     }
   19599                 :       85016 :     return (Node *) makeBoolExpr(AND_EXPR, list_make2(lexpr, rexpr), location);
   19600                 :             : }
   19601                 :             : 
   19602                 :             : static Node *
   19603                 :       13990 : makeOrExpr(Node *lexpr, Node *rexpr, int location)
   19604                 :             : {
   19605                 :             :     /* Flatten "a OR b OR c ..." to a single BoolExpr on sight */
   19606         [ +  + ]:       13990 :     if (IsA(lexpr, BoolExpr))
   19607                 :             :     {
   19608                 :        3594 :         BoolExpr   *blexpr = (BoolExpr *) lexpr;
   19609                 :             : 
   19610         [ +  + ]:        3594 :         if (blexpr->boolop == OR_EXPR)
   19611                 :             :         {
   19612                 :        2604 :             blexpr->args = lappend(blexpr->args, rexpr);
   19613                 :        2604 :             return (Node *) blexpr;
   19614                 :             :         }
   19615                 :             :     }
   19616                 :       11386 :     return (Node *) makeBoolExpr(OR_EXPR, list_make2(lexpr, rexpr), location);
   19617                 :             : }
   19618                 :             : 
   19619                 :             : static Node *
   19620                 :       17214 : makeNotExpr(Node *expr, int location)
   19621                 :             : {
   19622                 :       17214 :     return (Node *) makeBoolExpr(NOT_EXPR, list_make1(expr), location);
   19623                 :             : }
   19624                 :             : 
   19625                 :             : static Node *
   19626                 :        5924 : makeAArrayExpr(List *elements, int location, int location_end)
   19627                 :             : {
   19628                 :        5924 :     A_ArrayExpr *n = makeNode(A_ArrayExpr);
   19629                 :             : 
   19630                 :        5924 :     n->elements = elements;
   19631                 :        5924 :     n->location = location;
   19632                 :        5924 :     n->list_start = location;
   19633                 :        5924 :     n->list_end = location_end;
   19634                 :        5924 :     return (Node *) n;
   19635                 :             : }
   19636                 :             : 
   19637                 :             : static Node *
   19638                 :        1645 : makeSQLValueFunction(SQLValueFunctionOp op, int32 typmod, int location)
   19639                 :             : {
   19640                 :        1645 :     SQLValueFunction *svf = makeNode(SQLValueFunction);
   19641                 :             : 
   19642                 :        1645 :     svf->op = op;
   19643                 :             :     /* svf->type will be filled during parse analysis */
   19644                 :        1645 :     svf->typmod = typmod;
   19645                 :        1645 :     svf->location = location;
   19646                 :        1645 :     return (Node *) svf;
   19647                 :             : }
   19648                 :             : 
   19649                 :             : static Node *
   19650                 :         399 : makeXmlExpr(XmlExprOp op, char *name, List *named_args, List *args,
   19651                 :             :             int location)
   19652                 :             : {
   19653                 :         399 :     XmlExpr    *x = makeNode(XmlExpr);
   19654                 :             : 
   19655                 :         399 :     x->op = op;
   19656                 :         399 :     x->name = name;
   19657                 :             : 
   19658                 :             :     /*
   19659                 :             :      * named_args is a list of ResTarget; it'll be split apart into separate
   19660                 :             :      * expression and name lists in transformXmlExpr().
   19661                 :             :      */
   19662                 :         399 :     x->named_args = named_args;
   19663                 :         399 :     x->arg_names = NIL;
   19664                 :         399 :     x->args = args;
   19665                 :             :     /* xmloption, if relevant, must be filled in by caller */
   19666                 :             :     /* type and typmod will be filled in during parse analysis */
   19667                 :         399 :     x->type = InvalidOid;        /* marks the node as not analyzed */
   19668                 :         399 :     x->location = location;
   19669                 :         399 :     return (Node *) x;
   19670                 :             : }
   19671                 :             : 
   19672                 :             : /*
   19673                 :             :  * Merge the input and output parameters of a table function.
   19674                 :             :  */
   19675                 :             : static List *
   19676                 :         141 : mergeTableFuncParameters(List *func_args, List *columns, core_yyscan_t yyscanner)
   19677                 :             : {
   19678                 :             :     ListCell   *lc;
   19679                 :             : 
   19680                 :             :     /* Explicit OUT and INOUT parameters shouldn't be used in this syntax */
   19681   [ +  +  +  +  :         303 :     foreach(lc, func_args)
                   +  + ]
   19682                 :             :     {
   19683                 :         162 :         FunctionParameter *p = (FunctionParameter *) lfirst(lc);
   19684                 :             : 
   19685         [ -  + ]:         162 :         if (p->mode != FUNC_PARAM_DEFAULT &&
   19686         [ #  # ]:           0 :             p->mode != FUNC_PARAM_IN &&
   19687         [ #  # ]:           0 :             p->mode != FUNC_PARAM_VARIADIC)
   19688         [ #  # ]:           0 :             ereport(ERROR,
   19689                 :             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19690                 :             :                      errmsg("OUT and INOUT arguments aren't allowed in TABLE functions"),
   19691                 :             :                      parser_errposition(p->location)));
   19692                 :             :     }
   19693                 :             : 
   19694                 :         141 :     return list_concat(func_args, columns);
   19695                 :             : }
   19696                 :             : 
   19697                 :             : /*
   19698                 :             :  * Determine return type of a TABLE function.  A single result column
   19699                 :             :  * returns setof that column's type; otherwise return setof record.
   19700                 :             :  */
   19701                 :             : static TypeName *
   19702                 :         141 : TableFuncTypeName(List *columns)
   19703                 :             : {
   19704                 :             :     TypeName   *result;
   19705                 :             : 
   19706         [ +  + ]:         141 :     if (list_length(columns) == 1)
   19707                 :             :     {
   19708                 :          40 :         FunctionParameter *p = (FunctionParameter *) linitial(columns);
   19709                 :             : 
   19710                 :          40 :         result = copyObject(p->argType);
   19711                 :             :     }
   19712                 :             :     else
   19713                 :         101 :         result = SystemTypeName("record");
   19714                 :             : 
   19715                 :         141 :     result->setof = true;
   19716                 :             : 
   19717                 :         141 :     return result;
   19718                 :             : }
   19719                 :             : 
   19720                 :             : /*
   19721                 :             :  * Convert a list of (dotted) names to a RangeVar (like
   19722                 :             :  * makeRangeVarFromNameList, but with position support).  The
   19723                 :             :  * "AnyName" refers to the any_name production in the grammar.
   19724                 :             :  */
   19725                 :             : static RangeVar *
   19726                 :        2548 : makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner)
   19727                 :             : {
   19728                 :        2548 :     RangeVar   *r = makeNode(RangeVar);
   19729                 :             : 
   19730   [ +  +  -  - ]:        2548 :     switch (list_length(names))
   19731                 :             :     {
   19732                 :        2498 :         case 1:
   19733                 :        2498 :             r->catalogname = NULL;
   19734                 :        2498 :             r->schemaname = NULL;
   19735                 :        2498 :             r->relname = strVal(linitial(names));
   19736                 :        2498 :             break;
   19737                 :          50 :         case 2:
   19738                 :          50 :             r->catalogname = NULL;
   19739                 :          50 :             r->schemaname = strVal(linitial(names));
   19740                 :          50 :             r->relname = strVal(lsecond(names));
   19741                 :          50 :             break;
   19742                 :           0 :         case 3:
   19743                 :           0 :             r->catalogname = strVal(linitial(names));
   19744                 :           0 :             r->schemaname = strVal(lsecond(names));
   19745                 :           0 :             r->relname = strVal(lthird(names));
   19746                 :           0 :             break;
   19747                 :           0 :         default:
   19748         [ #  # ]:           0 :             ereport(ERROR,
   19749                 :             :                     (errcode(ERRCODE_SYNTAX_ERROR),
   19750                 :             :                      errmsg("improper qualified name (too many dotted names): %s",
   19751                 :             :                             NameListToString(names)),
   19752                 :             :                      parser_errposition(position)));
   19753                 :             :             break;
   19754                 :             :     }
   19755                 :             : 
   19756                 :        2548 :     r->relpersistence = RELPERSISTENCE_PERMANENT;
   19757                 :        2548 :     r->location = position;
   19758                 :             : 
   19759                 :        2548 :     return r;
   19760                 :             : }
   19761                 :             : 
   19762                 :             : /*
   19763                 :             :  * Convert a relation_name with name and namelist to a RangeVar using
   19764                 :             :  * makeRangeVar.
   19765                 :             :  */
   19766                 :             : static RangeVar *
   19767                 :      159071 : makeRangeVarFromQualifiedName(char *name, List *namelist, int location,
   19768                 :             :                               core_yyscan_t yyscanner)
   19769                 :             : {
   19770                 :             :     RangeVar   *r;
   19771                 :             : 
   19772                 :      159071 :     check_qualified_name(namelist, yyscanner);
   19773                 :      159071 :     r = makeRangeVar(NULL, NULL, location);
   19774                 :             : 
   19775      [ +  -  - ]:      159071 :     switch (list_length(namelist))
   19776                 :             :     {
   19777                 :      159071 :         case 1:
   19778                 :      159071 :             r->catalogname = NULL;
   19779                 :      159071 :             r->schemaname = name;
   19780                 :      159071 :             r->relname = strVal(linitial(namelist));
   19781                 :      159071 :             break;
   19782                 :           0 :         case 2:
   19783                 :           0 :             r->catalogname = name;
   19784                 :           0 :             r->schemaname = strVal(linitial(namelist));
   19785                 :           0 :             r->relname = strVal(lsecond(namelist));
   19786                 :           0 :             break;
   19787                 :           0 :         default:
   19788         [ #  # ]:           0 :             ereport(ERROR,
   19789                 :             :                     errcode(ERRCODE_SYNTAX_ERROR),
   19790                 :             :                     errmsg("improper qualified name (too many dotted names): %s",
   19791                 :             :                            NameListToString(lcons(makeString(name), namelist))),
   19792                 :             :                     parser_errposition(location));
   19793                 :             :             break;
   19794                 :             :     }
   19795                 :             : 
   19796                 :      159071 :     return r;
   19797                 :             : }
   19798                 :             : 
   19799                 :             : /* Separate Constraint nodes from COLLATE clauses in a ColQualList */
   19800                 :             : static void
   19801                 :       45253 : SplitColQualList(List *qualList,
   19802                 :             :                  List **constraintList, CollateClause **collClause,
   19803                 :             :                  core_yyscan_t yyscanner)
   19804                 :             : {
   19805                 :             :     ListCell   *cell;
   19806                 :             : 
   19807                 :       45253 :     *collClause = NULL;
   19808   [ +  +  +  +  :       58358 :     foreach(cell, qualList)
                   +  + ]
   19809                 :             :     {
   19810                 :       13105 :         Node       *n = (Node *) lfirst(cell);
   19811                 :             : 
   19812         [ +  + ]:       13105 :         if (IsA(n, Constraint))
   19813                 :             :         {
   19814                 :             :             /* keep it in list */
   19815                 :       12573 :             continue;
   19816                 :             :         }
   19817         [ +  - ]:         532 :         if (IsA(n, CollateClause))
   19818                 :             :         {
   19819                 :         532 :             CollateClause *c = (CollateClause *) n;
   19820                 :             : 
   19821         [ -  + ]:         532 :             if (*collClause)
   19822         [ #  # ]:           0 :                 ereport(ERROR,
   19823                 :             :                         (errcode(ERRCODE_SYNTAX_ERROR),
   19824                 :             :                          errmsg("multiple COLLATE clauses not allowed"),
   19825                 :             :                          parser_errposition(c->location)));
   19826                 :         532 :             *collClause = c;
   19827                 :             :         }
   19828                 :             :         else
   19829         [ #  # ]:           0 :             elog(ERROR, "unexpected node type %d", (int) n->type);
   19830                 :             :         /* remove non-Constraint nodes from qualList */
   19831                 :         532 :         qualList = foreach_delete_current(qualList, cell);
   19832                 :             :     }
   19833                 :       45253 :     *constraintList = qualList;
   19834                 :       45253 : }
   19835                 :             : 
   19836                 :             : /*
   19837                 :             :  * Process result of ConstraintAttributeSpec, and set appropriate bool flags
   19838                 :             :  * in the output command node.  Pass NULL for any flags the particular
   19839                 :             :  * command doesn't support.
   19840                 :             :  */
   19841                 :             : static void
   19842                 :       11334 : processCASbits(int cas_bits, int location, const char *constrType,
   19843                 :             :                bool *deferrable, bool *initdeferred, bool *is_enforced,
   19844                 :             :                bool *not_valid, bool *no_inherit, core_yyscan_t yyscanner)
   19845                 :             : {
   19846                 :             :     /* defaults */
   19847         [ +  + ]:       11334 :     if (deferrable)
   19848                 :        9875 :         *deferrable = false;
   19849         [ +  + ]:       11334 :     if (initdeferred)
   19850                 :        9875 :         *initdeferred = false;
   19851         [ +  + ]:       11334 :     if (not_valid)
   19852                 :        2648 :         *not_valid = false;
   19853         [ +  + ]:       11334 :     if (is_enforced)
   19854                 :        2435 :         *is_enforced = true;
   19855                 :             : 
   19856         [ +  + ]:       11334 :     if (cas_bits & (CAS_DEFERRABLE | CAS_INITIALLY_DEFERRED))
   19857                 :             :     {
   19858         [ +  - ]:         174 :         if (deferrable)
   19859                 :         174 :             *deferrable = true;
   19860                 :             :         else
   19861         [ #  # ]:           0 :             ereport(ERROR,
   19862                 :             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19863                 :             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19864                 :             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19865                 :             :                             constrType),
   19866                 :             :                      parser_errposition(location)));
   19867                 :             :     }
   19868                 :             : 
   19869         [ +  + ]:       11334 :     if (cas_bits & CAS_INITIALLY_DEFERRED)
   19870                 :             :     {
   19871         [ +  - ]:         105 :         if (initdeferred)
   19872                 :         105 :             *initdeferred = true;
   19873                 :             :         else
   19874         [ #  # ]:           0 :             ereport(ERROR,
   19875                 :             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19876                 :             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19877                 :             :                      errmsg("%s constraints cannot be marked DEFERRABLE",
   19878                 :             :                             constrType),
   19879                 :             :                      parser_errposition(location)));
   19880                 :             :     }
   19881                 :             : 
   19882         [ +  + ]:       11334 :     if (cas_bits & CAS_NOT_VALID)
   19883                 :             :     {
   19884         [ +  - ]:         424 :         if (not_valid)
   19885                 :         424 :             *not_valid = true;
   19886                 :             :         else
   19887         [ #  # ]:           0 :             ereport(ERROR,
   19888                 :             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19889                 :             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19890                 :             :                      errmsg("%s constraints cannot be marked NOT VALID",
   19891                 :             :                             constrType),
   19892                 :             :                      parser_errposition(location)));
   19893                 :             :     }
   19894                 :             : 
   19895         [ +  + ]:       11334 :     if (cas_bits & CAS_NO_INHERIT)
   19896                 :             :     {
   19897         [ +  - ]:         167 :         if (no_inherit)
   19898                 :         167 :             *no_inherit = true;
   19899                 :             :         else
   19900         [ #  # ]:           0 :             ereport(ERROR,
   19901                 :             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19902                 :             :             /* translator: %s is CHECK, UNIQUE, or similar */
   19903                 :             :                      errmsg("%s constraints cannot be marked NO INHERIT",
   19904                 :             :                             constrType),
   19905                 :             :                      parser_errposition(location)));
   19906                 :             :     }
   19907                 :             : 
   19908         [ +  + ]:       11334 :     if (cas_bits & CAS_NOT_ENFORCED)
   19909                 :             :     {
   19910         [ +  + ]:         191 :         if (is_enforced)
   19911                 :         187 :             *is_enforced = false;
   19912                 :             :         else
   19913         [ +  - ]:           4 :             ereport(ERROR,
   19914                 :             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19915                 :             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19916                 :             :                      errmsg("%s constraints cannot be marked NOT ENFORCED",
   19917                 :             :                             constrType),
   19918                 :             :                      parser_errposition(location)));
   19919                 :             : 
   19920                 :             :         /*
   19921                 :             :          * NB: The validated status is irrelevant when the constraint is set to
   19922                 :             :          * NOT ENFORCED, but for consistency, it should be set accordingly.
   19923                 :             :          * This ensures that if the constraint is later changed to ENFORCED, it
   19924                 :             :          * will automatically be in the correct NOT VALIDATED state.
   19925                 :             :          */
   19926         [ +  + ]:         187 :         if (not_valid)
   19927                 :          91 :             *not_valid = true;
   19928                 :             :     }
   19929                 :             : 
   19930         [ +  + ]:       11330 :     if (cas_bits & CAS_ENFORCED)
   19931                 :             :     {
   19932         [ +  + ]:         136 :         if (is_enforced)
   19933                 :         132 :             *is_enforced = true;
   19934                 :             :         else
   19935         [ +  - ]:           4 :             ereport(ERROR,
   19936                 :             :                     (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
   19937                 :             :                      /* translator: %s is CHECK, UNIQUE, or similar */
   19938                 :             :                      errmsg("%s constraints cannot be marked ENFORCED",
   19939                 :             :                             constrType),
   19940                 :             :                      parser_errposition(location)));
   19941                 :             :     }
   19942                 :       11326 : }
   19943                 :             : 
   19944                 :             : /*
   19945                 :             :  * Parse a user-supplied partition strategy string into parse node
   19946                 :             :  * PartitionStrategy representation, or die trying.
   19947                 :             :  */
   19948                 :             : static PartitionStrategy
   19949                 :        3417 : parsePartitionStrategy(char *strategy, int location, core_yyscan_t yyscanner)
   19950                 :             : {
   19951         [ +  + ]:        3417 :     if (pg_strcasecmp(strategy, "list") == 0)
   19952                 :        1614 :         return PARTITION_STRATEGY_LIST;
   19953         [ +  + ]:        1803 :     else if (pg_strcasecmp(strategy, "range") == 0)
   19954                 :        1628 :         return PARTITION_STRATEGY_RANGE;
   19955         [ +  + ]:         175 :     else if (pg_strcasecmp(strategy, "hash") == 0)
   19956                 :         171 :         return PARTITION_STRATEGY_HASH;
   19957                 :             : 
   19958         [ +  - ]:           4 :     ereport(ERROR,
   19959                 :             :             (errcode(ERRCODE_INVALID_PARAMETER_VALUE),
   19960                 :             :              errmsg("unrecognized partitioning strategy \"%s\"", strategy),
   19961                 :             :              parser_errposition(location)));
   19962                 :             :     return PARTITION_STRATEGY_LIST; /* keep compiler quiet */
   19963                 :             : 
   19964                 :             : }
   19965                 :             : 
   19966                 :             : /*
   19967                 :             :  * Process all_objects_list to set all_tables and/or all_sequences.
   19968                 :             :  * Also, checks if the pub_object_type has been specified more than once.
   19969                 :             :  */
   19970                 :             : static void
   19971                 :         211 : preprocess_pub_all_objtype_list(List *all_objects_list, List **pubobjects,
   19972                 :             :                                 bool *all_tables, bool *all_sequences,
   19973                 :             :                                 core_yyscan_t yyscanner)
   19974                 :             : {
   19975         [ -  + ]:         211 :     if (!all_objects_list)
   19976                 :           0 :         return;
   19977                 :             : 
   19978                 :         211 :     *all_tables = false;
   19979                 :         211 :     *all_sequences = false;
   19980                 :             : 
   19981   [ +  -  +  +  :         642 :     foreach_ptr(PublicationAllObjSpec, obj, all_objects_list)
                   +  + ]
   19982                 :             :     {
   19983         [ +  + ]:         236 :         if (obj->pubobjtype == PUBLICATION_ALL_TABLES)
   19984                 :             :         {
   19985         [ +  + ]:         186 :             if (*all_tables)
   19986         [ +  - ]:           4 :                 ereport(ERROR,
   19987                 :             :                         errcode(ERRCODE_SYNTAX_ERROR),
   19988                 :             :                         errmsg("invalid publication object list"),
   19989                 :             :                         errdetail("ALL TABLES can be specified only once."),
   19990                 :             :                         parser_errposition(obj->location));
   19991                 :             : 
   19992                 :         182 :             *all_tables = true;
   19993                 :         182 :             *pubobjects = list_concat(*pubobjects, obj->except_tables);
   19994                 :             :         }
   19995         [ +  - ]:          50 :         else if (obj->pubobjtype == PUBLICATION_ALL_SEQUENCES)
   19996                 :             :         {
   19997         [ +  + ]:          50 :             if (*all_sequences)
   19998         [ +  - ]:           4 :                 ereport(ERROR,
   19999                 :             :                     errcode(ERRCODE_SYNTAX_ERROR),
   20000                 :             :                         errmsg("invalid publication object list"),
   20001                 :             :                         errdetail("ALL SEQUENCES can be specified only once."),
   20002                 :             :                         parser_errposition(obj->location));
   20003                 :             : 
   20004                 :          46 :             *all_sequences = true;
   20005                 :             :         }
   20006                 :             :     }
   20007                 :             : }
   20008                 :             : 
   20009                 :             : /*
   20010                 :             :  * Process pubobjspec_list to check for errors in any of the objects and
   20011                 :             :  * convert PUBLICATIONOBJ_CONTINUATION into appropriate PublicationObjSpecType.
   20012                 :             :  */
   20013                 :             : static void
   20014                 :        1089 : preprocess_pubobj_list(List *pubobjspec_list, core_yyscan_t yyscanner)
   20015                 :             : {
   20016                 :             :     ListCell   *cell;
   20017                 :             :     PublicationObjSpec *pubobj;
   20018                 :        1089 :     PublicationObjSpecType prevobjtype = PUBLICATIONOBJ_CONTINUATION;
   20019                 :             : 
   20020         [ -  + ]:        1089 :     if (!pubobjspec_list)
   20021                 :           0 :         return;
   20022                 :             : 
   20023                 :        1089 :     pubobj = (PublicationObjSpec *) linitial(pubobjspec_list);
   20024         [ +  + ]:        1089 :     if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   20025         [ +  - ]:           8 :         ereport(ERROR,
   20026                 :             :                 errcode(ERRCODE_SYNTAX_ERROR),
   20027                 :             :                 errmsg("invalid publication object list"),
   20028                 :             :                 errdetail("One of TABLE or TABLES IN SCHEMA must be specified before a standalone table or schema name."),
   20029                 :             :                 parser_errposition(pubobj->location));
   20030                 :             : 
   20031   [ +  -  +  +  :        2311 :     foreach(cell, pubobjspec_list)
                   +  + ]
   20032                 :             :     {
   20033                 :        1246 :         pubobj = (PublicationObjSpec *) lfirst(cell);
   20034                 :             : 
   20035         [ +  + ]:        1246 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_CONTINUATION)
   20036                 :         112 :             pubobj->pubobjtype = prevobjtype;
   20037                 :             : 
   20038         [ +  + ]:        1246 :         if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLE)
   20039                 :             :         {
   20040                 :             :             /* relation name or pubtable must be set for this type of object */
   20041   [ +  +  +  + ]:         949 :             if (!pubobj->name && !pubobj->pubtable)
   20042         [ +  - ]:           4 :                 ereport(ERROR,
   20043                 :             :                         errcode(ERRCODE_SYNTAX_ERROR),
   20044                 :             :                         errmsg("invalid table name"),
   20045                 :             :                         parser_errposition(pubobj->location));
   20046                 :             : 
   20047         [ +  + ]:         945 :             if (pubobj->name)
   20048                 :             :             {
   20049                 :             :                 /* convert it to PublicationTable */
   20050                 :          37 :                 PublicationTable *pubtable = makeNode(PublicationTable);
   20051                 :             : 
   20052                 :          37 :                 pubtable->relation =
   20053                 :          37 :                     makeRangeVar(NULL, pubobj->name, pubobj->location);
   20054                 :          37 :                 pubobj->pubtable = pubtable;
   20055                 :          37 :                 pubobj->name = NULL;
   20056                 :             :             }
   20057                 :             :         }
   20058         [ +  + ]:         297 :         else if (pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_SCHEMA ||
   20059         [ +  - ]:          16 :                  pubobj->pubobjtype == PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA)
   20060                 :             :         {
   20061                 :             :             /* WHERE clause is not allowed on a schema object */
   20062   [ +  +  +  + ]:         297 :             if (pubobj->pubtable && pubobj->pubtable->whereClause)
   20063         [ +  - ]:           4 :                 ereport(ERROR,
   20064                 :             :                         errcode(ERRCODE_SYNTAX_ERROR),
   20065                 :             :                         errmsg("WHERE clause not allowed for schema"),
   20066                 :             :                         parser_errposition(pubobj->location));
   20067                 :             : 
   20068                 :             :             /* Column list is not allowed on a schema object */
   20069   [ +  +  +  + ]:         293 :             if (pubobj->pubtable && pubobj->pubtable->columns)
   20070         [ +  - ]:           4 :                 ereport(ERROR,
   20071                 :             :                         errcode(ERRCODE_SYNTAX_ERROR),
   20072                 :             :                         errmsg("column specification not allowed for schema"),
   20073                 :             :                         parser_errposition(pubobj->location));
   20074                 :             : 
   20075                 :             :             /*
   20076                 :             :              * We can distinguish between the different type of schema objects
   20077                 :             :              * based on whether name and pubtable is set.
   20078                 :             :              */
   20079         [ +  + ]:         289 :             if (pubobj->name)
   20080                 :         269 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_SCHEMA;
   20081   [ +  -  +  + ]:          20 :             else if (!pubobj->name && !pubobj->pubtable)
   20082                 :          16 :                 pubobj->pubobjtype = PUBLICATIONOBJ_TABLES_IN_CUR_SCHEMA;
   20083                 :             :             else
   20084         [ +  - ]:           4 :                 ereport(ERROR,
   20085                 :             :                         errcode(ERRCODE_SYNTAX_ERROR),
   20086                 :             :                         errmsg("invalid schema name"),
   20087                 :             :                         parser_errposition(pubobj->location));
   20088                 :             :         }
   20089                 :             : 
   20090                 :        1230 :         prevobjtype = pubobj->pubobjtype;
   20091                 :             :     }
   20092                 :             : }
   20093                 :             : 
   20094                 :             : /*----------
   20095                 :             :  * Recursive view transformation
   20096                 :             :  *
   20097                 :             :  * Convert
   20098                 :             :  *
   20099                 :             :  *     CREATE RECURSIVE VIEW relname (aliases) AS query
   20100                 :             :  *
   20101                 :             :  * to
   20102                 :             :  *
   20103                 :             :  *     CREATE VIEW relname (aliases) AS
   20104                 :             :  *         WITH RECURSIVE relname (aliases) AS (query)
   20105                 :             :  *         SELECT aliases FROM relname
   20106                 :             :  *
   20107                 :             :  * Actually, just the WITH ... part, which is then inserted into the original
   20108                 :             :  * view definition as the query.
   20109                 :             :  * ----------
   20110                 :             :  */
   20111                 :             : static Node *
   20112                 :           9 : makeRecursiveViewSelect(char *relname, List *aliases, Node *query)
   20113                 :             : {
   20114                 :           9 :     SelectStmt *s = makeNode(SelectStmt);
   20115                 :           9 :     WithClause *w = makeNode(WithClause);
   20116                 :           9 :     CommonTableExpr *cte = makeNode(CommonTableExpr);
   20117                 :           9 :     List       *tl = NIL;
   20118                 :             :     ListCell   *lc;
   20119                 :             : 
   20120                 :             :     /* create common table expression */
   20121                 :           9 :     cte->ctename = relname;
   20122                 :           9 :     cte->aliascolnames = aliases;
   20123                 :           9 :     cte->ctematerialized = CTEMaterializeDefault;
   20124                 :           9 :     cte->ctequery = query;
   20125                 :           9 :     cte->location = -1;
   20126                 :             : 
   20127                 :             :     /* create WITH clause and attach CTE */
   20128                 :           9 :     w->recursive = true;
   20129                 :           9 :     w->ctes = list_make1(cte);
   20130                 :           9 :     w->location = -1;
   20131                 :             : 
   20132                 :             :     /*
   20133                 :             :      * create target list for the new SELECT from the alias list of the
   20134                 :             :      * recursive view specification
   20135                 :             :      */
   20136   [ +  -  +  +  :          18 :     foreach(lc, aliases)
                   +  + ]
   20137                 :             :     {
   20138                 :           9 :         ResTarget  *rt = makeNode(ResTarget);
   20139                 :             : 
   20140                 :           9 :         rt->name = NULL;
   20141                 :           9 :         rt->indirection = NIL;
   20142                 :           9 :         rt->val = makeColumnRef(strVal(lfirst(lc)), NIL, -1, 0);
   20143                 :           9 :         rt->location = -1;
   20144                 :             : 
   20145                 :           9 :         tl = lappend(tl, rt);
   20146                 :             :     }
   20147                 :             : 
   20148                 :             :     /*
   20149                 :             :      * create new SELECT combining WITH clause, target list, and fake FROM
   20150                 :             :      * clause
   20151                 :             :      */
   20152                 :           9 :     s->withClause = w;
   20153                 :           9 :     s->targetList = tl;
   20154                 :           9 :     s->fromClause = list_make1(makeRangeVar(NULL, relname, -1));
   20155                 :             : 
   20156                 :           9 :     return (Node *) s;
   20157                 :             : }
   20158                 :             : 
   20159                 :             : /* parser_init()
   20160                 :             :  * Initialize to parse one query string
   20161                 :             :  */
   20162                 :             : void
   20163                 :      494007 : parser_init(base_yy_extra_type *yyext)
   20164                 :             : {
   20165                 :      494007 :     yyext->parsetree = NIL;      /* in case grammar forgets to set it */
   20166                 :      494007 : }
        

Generated by: LCOV version 2.0-1