PageRenderTime 81ms CodeModel.GetById 33ms RepoModel.GetById 0ms app.codeStats 1ms

/src/backend/parser/gram.y

https://bitbucket.org/gencer/postgres
Happy | 13995 lines | 13015 code | 980 blank | 0 comment | 0 complexity | 49316f1c06db37f1aa54936ab75ef001 MD5 | raw file
Possible License(s): AGPL-3.0

Large files files are truncated, but you can click here to view the full file

  1. %{
  2. /*#define YYDEBUG 1*/
  3. /*-------------------------------------------------------------------------
  4. *
  5. * gram.y
  6. * POSTGRESQL BISON rules/actions
  7. *
  8. * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
  9. * Portions Copyright (c) 1994, Regents of the University of California
  10. *
  11. *
  12. * IDENTIFICATION
  13. * src/backend/parser/gram.y
  14. *
  15. * HISTORY
  16. * AUTHOR DATE MAJOR EVENT
  17. * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
  18. * Andrew Yu Oct, 1994 lispy code conversion
  19. *
  20. * NOTES
  21. * CAPITALS are used to represent terminal symbols.
  22. * non-capitals are used to represent non-terminals.
  23. *
  24. * In general, nothing in this file should initiate database accesses
  25. * nor depend on changeable state (such as SET variables). If you do
  26. * database accesses, your code will fail when we have aborted the
  27. * current transaction and are just parsing commands to find the next
  28. * ROLLBACK or COMMIT. If you make use of SET variables, then you
  29. * will do the wrong thing in multi-query strings like this:
  30. * SET SQL_inheritance TO off; SELECT * FROM foo;
  31. * because the entire string is parsed by gram.y before the SET gets
  32. * executed. Anything that depends on the database or changeable state
  33. * should be handled during parse analysis so that it happens at the
  34. * right time not the wrong time. The handling of SQL_inheritance is
  35. * a good example.
  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. #include <ctype.h>
  48. #include <limits.h>
  49. #include "catalog/index.h"
  50. #include "catalog/namespace.h"
  51. #include "catalog/pg_trigger.h"
  52. #include "commands/defrem.h"
  53. #include "commands/trigger.h"
  54. #include "nodes/makefuncs.h"
  55. #include "nodes/nodeFuncs.h"
  56. #include "parser/gramparse.h"
  57. #include "parser/parser.h"
  58. #include "storage/lmgr.h"
  59. #include "utils/date.h"
  60. #include "utils/datetime.h"
  61. #include "utils/numeric.h"
  62. #include "utils/xml.h"
  63. /*
  64. * Location tracking support --- simpler than bison's default, since we only
  65. * want to track the start position not the end position of each nonterminal.
  66. */
  67. #define YYLLOC_DEFAULT(Current, Rhs, N) \
  68. do { \
  69. if ((N) > 0) \
  70. (Current) = (Rhs)[1]; \
  71. else \
  72. (Current) = (-1); \
  73. } while (0)
  74. /*
  75. * The above macro assigns -1 (unknown) as the parse location of any
  76. * nonterminal that was reduced from an empty rule. This is problematic
  77. * for nonterminals defined like
  78. * OptFooList: / * EMPTY * / { ... } | OptFooList Foo { ... } ;
  79. * because we'll set -1 as the location during the first reduction and then
  80. * copy it during each subsequent reduction, leaving us with -1 for the
  81. * location even when the list is not empty. To fix that, do this in the
  82. * action for the nonempty rule(s):
  83. * if (@$ < 0) @$ = @2;
  84. * (Although we have many nonterminals that follow this pattern, we only
  85. * bother with fixing @$ like this when the nonterminal's parse location
  86. * is actually referenced in some rule.)
  87. */
  88. /*
  89. * Bison doesn't allocate anything that needs to live across parser calls,
  90. * so we can easily have it use palloc instead of malloc. This prevents
  91. * memory leaks if we error out during parsing. Note this only works with
  92. * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
  93. * if possible, so there's not really much problem anyhow, at least if
  94. * you're building with gcc.
  95. */
  96. #define YYMALLOC palloc
  97. #define YYFREE pfree
  98. /* Private struct for the result of privilege_target production */
  99. typedef struct PrivTarget
  100. {
  101. GrantTargetType targtype;
  102. GrantObjectType objtype;
  103. List *objs;
  104. } PrivTarget;
  105. /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
  106. #define CAS_NOT_DEFERRABLE 0x01
  107. #define CAS_DEFERRABLE 0x02
  108. #define CAS_INITIALLY_IMMEDIATE 0x04
  109. #define CAS_INITIALLY_DEFERRED 0x08
  110. #define CAS_NOT_VALID 0x10
  111. #define CAS_NO_INHERIT 0x20
  112. #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
  113. #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
  114. static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
  115. const char *msg);
  116. static Node *makeColumnRef(char *colname, List *indirection,
  117. int location, core_yyscan_t yyscanner);
  118. static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
  119. static Node *makeStringConst(char *str, int location);
  120. static Node *makeStringConstCast(char *str, int location, TypeName *typename);
  121. static Node *makeIntConst(int val, int location);
  122. static Node *makeFloatConst(char *str, int location);
  123. static Node *makeBitStringConst(char *str, int location);
  124. static Node *makeNullAConst(int location);
  125. static Node *makeAConst(Value *v, int location);
  126. static Node *makeBoolAConst(bool state, int location);
  127. static void check_qualified_name(List *names, core_yyscan_t yyscanner);
  128. static List *check_func_name(List *names, core_yyscan_t yyscanner);
  129. static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
  130. static List *extractArgTypes(List *parameters);
  131. static List *extractAggrArgTypes(List *aggrargs);
  132. static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
  133. core_yyscan_t yyscanner);
  134. static void insertSelectOptions(SelectStmt *stmt,
  135. List *sortClause, List *lockingClause,
  136. Node *limitOffset, Node *limitCount,
  137. WithClause *withClause,
  138. core_yyscan_t yyscanner);
  139. static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
  140. static Node *doNegate(Node *n, int location);
  141. static void doNegateFloat(Value *v);
  142. static Node *makeAArrayExpr(List *elements, int location);
  143. static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
  144. List *args, int location);
  145. static List *mergeTableFuncParameters(List *func_args, List *columns);
  146. static TypeName *TableFuncTypeName(List *columns);
  147. static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
  148. static void SplitColQualList(List *qualList,
  149. List **constraintList, CollateClause **collClause,
  150. core_yyscan_t yyscanner);
  151. static void processCASbits(int cas_bits, int location, const char *constrType,
  152. bool *deferrable, bool *initdeferred, bool *not_valid,
  153. bool *no_inherit, core_yyscan_t yyscanner);
  154. static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
  155. %}
  156. %pure-parser
  157. %expect 0
  158. %name-prefix="base_yy"
  159. %locations
  160. %parse-param {core_yyscan_t yyscanner}
  161. %lex-param {core_yyscan_t yyscanner}
  162. %union
  163. {
  164. core_YYSTYPE core_yystype;
  165. /* these fields must match core_YYSTYPE: */
  166. int ival;
  167. char *str;
  168. const char *keyword;
  169. char chr;
  170. bool boolean;
  171. JoinType jtype;
  172. DropBehavior dbehavior;
  173. OnCommitAction oncommit;
  174. List *list;
  175. Node *node;
  176. Value *value;
  177. ObjectType objtype;
  178. TypeName *typnam;
  179. FunctionParameter *fun_param;
  180. FunctionParameterMode fun_param_mode;
  181. FuncWithArgs *funwithargs;
  182. DefElem *defelt;
  183. SortBy *sortby;
  184. WindowDef *windef;
  185. JoinExpr *jexpr;
  186. IndexElem *ielem;
  187. Alias *alias;
  188. RangeVar *range;
  189. IntoClause *into;
  190. WithClause *with;
  191. A_Indices *aind;
  192. ResTarget *target;
  193. struct PrivTarget *privtarget;
  194. AccessPriv *accesspriv;
  195. InsertStmt *istmt;
  196. VariableSetStmt *vsetstmt;
  197. }
  198. %type <node> stmt schema_stmt
  199. AlterEventTrigStmt
  200. AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
  201. AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
  202. AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
  203. AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt
  204. AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
  205. AlterRoleStmt AlterRoleSetStmt
  206. AlterDefaultPrivilegesStmt DefACLAction
  207. AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
  208. ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
  209. CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
  210. CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
  211. CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
  212. CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
  213. CreateAssertStmt CreateTrigStmt CreateEventTrigStmt
  214. CreateUserStmt CreateUserMappingStmt CreateRoleStmt
  215. CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
  216. DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
  217. DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
  218. DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
  219. DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
  220. GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
  221. LockStmt NotifyStmt ExplainableStmt PreparableStmt
  222. CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
  223. RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
  224. RuleActionStmt RuleActionStmtOrEmpty RuleStmt
  225. SecLabelStmt SelectStmt TransactionStmt TruncateStmt
  226. UnlistenStmt UpdateStmt VacuumStmt
  227. VariableResetStmt VariableSetStmt VariableShowStmt
  228. ViewStmt CheckPointStmt CreateConversionStmt
  229. DeallocateStmt PrepareStmt ExecuteStmt
  230. DropOwnedStmt ReassignOwnedStmt
  231. AlterTSConfigurationStmt AlterTSDictionaryStmt
  232. CreateMatViewStmt RefreshMatViewStmt
  233. %type <node> select_no_parens select_with_parens select_clause
  234. simple_select values_clause
  235. %type <node> alter_column_default opclass_item opclass_drop alter_using
  236. %type <ival> add_drop opt_asc_desc opt_nulls_order
  237. %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
  238. replica_identity
  239. %type <list> alter_table_cmds alter_type_cmds
  240. %type <dbehavior> opt_drop_behavior
  241. %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
  242. transaction_mode_list
  243. create_extension_opt_list alter_extension_opt_list
  244. %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
  245. transaction_mode_item
  246. create_extension_opt_item alter_extension_opt_item
  247. %type <ival> opt_lock lock_type cast_context
  248. %type <ival> vacuum_option_list vacuum_option_elem
  249. %type <boolean> opt_force opt_or_replace
  250. opt_grant_grant_option opt_grant_admin_option
  251. opt_nowait opt_if_exists opt_with_data
  252. %type <list> OptRoleList AlterOptRoleList
  253. %type <defelt> CreateOptRoleElem AlterOptRoleElem
  254. %type <str> opt_type
  255. %type <str> foreign_server_version opt_foreign_server_version
  256. %type <str> auth_ident
  257. %type <str> opt_in_database
  258. %type <str> OptSchemaName
  259. %type <list> OptSchemaEltList
  260. %type <boolean> TriggerForSpec TriggerForType
  261. %type <ival> TriggerActionTime
  262. %type <list> TriggerEvents TriggerOneEvent
  263. %type <value> TriggerFuncArg
  264. %type <node> TriggerWhen
  265. %type <list> event_trigger_when_list event_trigger_value_list
  266. %type <defelt> event_trigger_when_item
  267. %type <chr> enable_trigger
  268. %type <str> copy_file_name
  269. database_name access_method_clause access_method attr_name
  270. name cursor_name file_name
  271. index_name opt_index_name cluster_index_specification
  272. %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
  273. opt_class opt_inline_handler opt_validator validator_clause
  274. opt_collate
  275. %type <range> qualified_name OptConstrFromTable
  276. %type <str> all_Op MathOp
  277. %type <str> iso_level opt_encoding
  278. %type <node> grantee
  279. %type <list> grantee_list
  280. %type <accesspriv> privilege
  281. %type <list> privileges privilege_list
  282. %type <privtarget> privilege_target
  283. %type <funwithargs> function_with_argtypes
  284. %type <list> function_with_argtypes_list
  285. %type <ival> defacl_privilege_target
  286. %type <defelt> DefACLOption
  287. %type <list> DefACLOptionList
  288. %type <list> stmtblock stmtmulti
  289. OptTableElementList TableElementList OptInherit definition
  290. OptTypedTableElementList TypedTableElementList
  291. reloptions opt_reloptions
  292. OptWith opt_distinct opt_definition func_args func_args_list
  293. func_args_with_defaults func_args_with_defaults_list
  294. aggr_args aggr_args_list
  295. func_as createfunc_opt_list alterfunc_opt_list
  296. old_aggr_definition old_aggr_list
  297. oper_argtypes RuleActionList RuleActionMulti
  298. opt_column_list columnList opt_name_list
  299. sort_clause opt_sort_clause sortby_list index_params
  300. name_list role_list from_clause from_list opt_array_bounds
  301. qualified_name_list any_name any_name_list
  302. any_operator expr_list attrs
  303. target_list opt_target_list insert_column_list set_target_list
  304. set_clause_list set_clause multiple_set_clause
  305. ctext_expr_list ctext_row def_list indirection opt_indirection
  306. reloption_list group_clause TriggerFuncArgs select_limit
  307. opt_select_limit opclass_item_list opclass_drop_list
  308. opclass_purpose opt_opfamily transaction_mode_list_or_empty
  309. OptTableFuncElementList TableFuncElementList opt_type_modifiers
  310. prep_type_clause
  311. execute_param_clause using_clause returning_clause
  312. opt_enum_val_list enum_val_list table_func_column_list
  313. create_generic_options alter_generic_options
  314. relation_expr_list dostmt_opt_list
  315. %type <list> opt_fdw_options fdw_options
  316. %type <defelt> fdw_option
  317. %type <range> OptTempTableName
  318. %type <into> into_clause create_as_target create_mv_target
  319. %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
  320. %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
  321. %type <fun_param_mode> arg_class
  322. %type <typnam> func_return func_type
  323. %type <boolean> opt_trusted opt_restart_seqs
  324. %type <ival> OptTemp
  325. %type <ival> OptNoLog
  326. %type <oncommit> OnCommitOption
  327. %type <ival> for_locking_strength
  328. %type <node> for_locking_item
  329. %type <list> for_locking_clause opt_for_locking_clause for_locking_items
  330. %type <list> locked_rels_list
  331. %type <boolean> opt_all
  332. %type <node> join_outer join_qual
  333. %type <jtype> join_type
  334. %type <list> extract_list overlay_list position_list
  335. %type <list> substr_list trim_list
  336. %type <list> opt_interval interval_second
  337. %type <node> overlay_placing substr_from substr_for
  338. %type <boolean> opt_instead
  339. %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
  340. %type <boolean> opt_freeze opt_default opt_recheck
  341. %type <defelt> opt_binary opt_oids copy_delimiter
  342. %type <boolean> copy_from opt_program
  343. %type <ival> opt_column event cursor_options opt_hold opt_set_data
  344. %type <objtype> reindex_type drop_type comment_type security_label_type
  345. %type <node> fetch_args limit_clause select_limit_value
  346. offset_clause select_offset_value
  347. select_offset_value2 opt_select_fetch_first_value
  348. %type <ival> row_or_rows first_or_next
  349. %type <list> OptSeqOptList SeqOptList
  350. %type <defelt> SeqOptElem
  351. %type <istmt> insert_rest
  352. %type <vsetstmt> generic_set set_rest set_rest_more SetResetClause FunctionSetResetClause
  353. %type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
  354. %type <node> columnDef columnOptions
  355. %type <defelt> def_elem reloption_elem old_aggr_elem
  356. %type <node> def_arg columnElem where_clause where_or_current_clause
  357. a_expr b_expr c_expr AexprConst indirection_el
  358. columnref in_expr having_clause func_table array_expr
  359. ExclusionWhereClause
  360. %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
  361. %type <boolean> opt_ordinality
  362. %type <list> ExclusionConstraintList ExclusionConstraintElem
  363. %type <list> func_arg_list
  364. %type <node> func_arg_expr
  365. %type <list> row type_list array_expr_list
  366. %type <node> case_expr case_arg when_clause case_default
  367. %type <list> when_clause_list
  368. %type <ival> sub_type
  369. %type <node> ctext_expr
  370. %type <value> NumericOnly
  371. %type <list> NumericOnly_list
  372. %type <alias> alias_clause opt_alias_clause
  373. %type <list> func_alias_clause
  374. %type <sortby> sortby
  375. %type <ielem> index_elem
  376. %type <node> table_ref
  377. %type <jexpr> joined_table
  378. %type <range> relation_expr
  379. %type <range> relation_expr_opt_alias
  380. %type <target> target_el single_set_clause set_target insert_column_item
  381. %type <str> generic_option_name
  382. %type <node> generic_option_arg
  383. %type <defelt> generic_option_elem alter_generic_option_elem
  384. %type <list> generic_option_list alter_generic_option_list
  385. %type <str> explain_option_name
  386. %type <node> explain_option_arg
  387. %type <defelt> explain_option_elem
  388. %type <list> explain_option_list
  389. %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
  390. %type <defelt> copy_generic_opt_elem
  391. %type <list> copy_generic_opt_list copy_generic_opt_arg_list
  392. %type <list> copy_options
  393. %type <typnam> Typename SimpleTypename ConstTypename
  394. GenericType Numeric opt_float
  395. Character ConstCharacter
  396. CharacterWithLength CharacterWithoutLength
  397. ConstDatetime ConstInterval
  398. Bit ConstBit BitWithLength BitWithoutLength
  399. %type <str> character
  400. %type <str> extract_arg
  401. %type <str> opt_charset
  402. %type <boolean> opt_varying opt_timezone opt_no_inherit
  403. %type <ival> Iconst SignedIconst
  404. %type <str> Sconst comment_text notify_payload
  405. %type <str> RoleId opt_granted_by opt_boolean_or_string
  406. %type <list> var_list
  407. %type <str> ColId ColLabel var_name type_function_name param_name
  408. %type <str> NonReservedWord NonReservedWord_or_Sconst
  409. %type <node> var_value zone_value
  410. %type <keyword> unreserved_keyword type_func_name_keyword
  411. %type <keyword> col_name_keyword reserved_keyword
  412. %type <node> TableConstraint TableLikeClause
  413. %type <ival> TableLikeOptionList TableLikeOption
  414. %type <list> ColQualList
  415. %type <node> ColConstraint ColConstraintElem ConstraintAttr
  416. %type <ival> key_actions key_delete key_match key_update key_action
  417. %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
  418. %type <str> ExistingIndex
  419. %type <list> constraints_set_list
  420. %type <boolean> constraints_set_mode
  421. %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
  422. %type <ival> opt_check_option
  423. %type <str> opt_provider security_label
  424. %type <target> xml_attribute_el
  425. %type <list> xml_attribute_list xml_attributes
  426. %type <node> xml_root_version opt_xml_root_standalone
  427. %type <node> xmlexists_argument
  428. %type <ival> document_or_content
  429. %type <boolean> xml_whitespace_option
  430. %type <node> func_application func_expr_common_subexpr
  431. %type <node> func_expr func_expr_windowless
  432. %type <node> common_table_expr
  433. %type <with> with_clause opt_with_clause
  434. %type <list> cte_list
  435. %type <list> within_group_clause
  436. %type <node> filter_clause
  437. %type <list> window_clause window_definition_list opt_partition_clause
  438. %type <windef> window_definition over_clause window_specification
  439. opt_frame_clause frame_extent frame_bound
  440. %type <str> opt_existing_window_name
  441. %type <boolean> opt_if_not_exists
  442. /*
  443. * Non-keyword token types. These are hard-wired into the "flex" lexer.
  444. * They must be listed first so that their numeric codes do not depend on
  445. * the set of keywords. PL/pgsql depends on this so that it can share the
  446. * same lexer. If you add/change tokens here, fix PL/pgsql to match!
  447. *
  448. * DOT_DOT is unused in the core SQL grammar, and so will always provoke
  449. * parse errors. It is needed by PL/pgsql.
  450. */
  451. %token <str> IDENT FCONST SCONST BCONST XCONST Op
  452. %token <ival> ICONST PARAM
  453. %token TYPECAST DOT_DOT COLON_EQUALS
  454. /*
  455. * If you want to make any keyword changes, update the keyword table in
  456. * src/include/parser/kwlist.h and add new keywords to the appropriate one
  457. * of the reserved-or-not-so-reserved keyword lists, below; search
  458. * this file for "Keyword category lists".
  459. */
  460. /* ordinary key words in alphabetical order */
  461. %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
  462. AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
  463. ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
  464. BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
  465. BOOLEAN_P BOTH BY
  466. CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
  467. CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
  468. CLUSTER COALESCE COLLATE COLLATION COLUMN COMMENT COMMENTS COMMIT
  469. COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
  470. CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE
  471. CROSS CSV CURRENT_P
  472. CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
  473. CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
  474. DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
  475. DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
  476. DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
  477. EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EVENT EXCEPT
  478. EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
  479. EXTENSION EXTERNAL EXTRACT
  480. FALSE_P FAMILY FETCH FILTER FIRST_P FLOAT_P FOLLOWING FOR
  481. FORCE FOREIGN FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
  482. GLOBAL GRANT GRANTED GREATEST GROUP_P
  483. HANDLER HAVING HEADER_P HOLD HOUR_P
  484. IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
  485. INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
  486. INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
  487. INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
  488. JOIN
  489. KEY
  490. LABEL LANGUAGE LARGE_P LAST_P LATERAL_P LC_COLLATE_P LC_CTYPE_P
  491. LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
  492. LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P
  493. MAPPING MATCH MATERIALIZED MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
  494. NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NONE
  495. NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
  496. NULLS_P NUMERIC
  497. OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
  498. ORDER ORDINALITY OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
  499. PARSER PARTIAL PARTITION PASSING PASSWORD PLACING PLANS POSITION
  500. PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
  501. PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROGRAM
  502. QUOTE
  503. RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REFRESH REINDEX
  504. RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
  505. RESET RESTART RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK
  506. ROW ROWS RULE
  507. SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
  508. SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
  509. SHOW SIMILAR SIMPLE SMALLINT SNAPSHOT SOME STABLE STANDALONE_P START
  510. STATEMENT STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING
  511. SYMMETRIC SYSID SYSTEM_P
  512. TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
  513. TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
  514. TRUNCATE TRUSTED TYPE_P TYPES_P
  515. UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNLOGGED
  516. UNTIL UPDATE USER USING
  517. VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
  518. VERBOSE VERSION_P VIEW VIEWS VOLATILE
  519. WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
  520. XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLPARSE
  521. XMLPI XMLROOT XMLSERIALIZE
  522. YEAR_P YES_P
  523. ZONE
  524. /*
  525. * The grammar thinks these are keywords, but they are not in the kwlist.h
  526. * list and so can never be entered directly. The filter in parser.c
  527. * creates these tokens when required.
  528. */
  529. %token NULLS_FIRST NULLS_LAST WITH_ORDINALITY WITH_TIME
  530. /* Precedence: lowest to highest */
  531. %nonassoc SET /* see relation_expr_opt_alias */
  532. %left UNION EXCEPT
  533. %left INTERSECT
  534. %left OR
  535. %left AND
  536. %right NOT
  537. %right '='
  538. %nonassoc '<' '>'
  539. %nonassoc LIKE ILIKE SIMILAR
  540. %nonassoc ESCAPE
  541. %nonassoc OVERLAPS
  542. %nonassoc BETWEEN
  543. %nonassoc IN_P
  544. %left POSTFIXOP /* dummy for postfix Op rules */
  545. /*
  546. * To support target_el without AS, we must give IDENT an explicit priority
  547. * between POSTFIXOP and Op. We can safely assign the same priority to
  548. * various unreserved keywords as needed to resolve ambiguities (this can't
  549. * have any bad effects since obviously the keywords will still behave the
  550. * same as if they weren't keywords). We need to do this for PARTITION,
  551. * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
  552. * so that they can follow a_expr without creating postfix-operator problems;
  553. * and for NULL so that it can follow b_expr in ColQualList without creating
  554. * postfix-operator problems.
  555. *
  556. * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
  557. * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
  558. * there is no principled way to distinguish these from the productions
  559. * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
  560. * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
  561. * appear to cause UNBOUNDED to be treated differently from other unreserved
  562. * keywords anywhere else in the grammar, but it's definitely risky. We can
  563. * blame any funny behavior of UNBOUNDED on the SQL standard, though.
  564. */
  565. %nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
  566. %nonassoc IDENT NULL_P PARTITION RANGE ROWS PRECEDING FOLLOWING
  567. %left Op OPERATOR /* multi-character ops and user-defined operators */
  568. %nonassoc NOTNULL
  569. %nonassoc ISNULL
  570. %nonassoc IS /* sets precedence for IS NULL, etc */
  571. %left '+' '-'
  572. %left '*' '/' '%'
  573. %left '^'
  574. /* Unary Operators */
  575. %left AT /* sets precedence for AT TIME ZONE */
  576. %left COLLATE
  577. %right UMINUS
  578. %left '[' ']'
  579. %left '(' ')'
  580. %left TYPECAST
  581. %left '.'
  582. /*
  583. * These might seem to be low-precedence, but actually they are not part
  584. * of the arithmetic hierarchy at all in their use as JOIN operators.
  585. * We make them high-precedence to support their use as function names.
  586. * They wouldn't be given a precedence at all, were it not that we need
  587. * left-associativity among the JOIN rules themselves.
  588. */
  589. %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
  590. /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
  591. %right PRESERVE STRIP_P
  592. %%
  593. /*
  594. * The target production for the whole parse.
  595. */
  596. stmtblock: stmtmulti
  597. {
  598. pg_yyget_extra(yyscanner)->parsetree = $1;
  599. }
  600. ;
  601. /* the thrashing around here is to discard "empty" statements... */
  602. stmtmulti: stmtmulti ';' stmt
  603. {
  604. if ($3 != NULL)
  605. $$ = lappend($1, $3);
  606. else
  607. $$ = $1;
  608. }
  609. | stmt
  610. {
  611. if ($1 != NULL)
  612. $$ = list_make1($1);
  613. else
  614. $$ = NIL;
  615. }
  616. ;
  617. stmt :
  618. AlterEventTrigStmt
  619. | AlterDatabaseStmt
  620. | AlterDatabaseSetStmt
  621. | AlterDefaultPrivilegesStmt
  622. | AlterDomainStmt
  623. | AlterEnumStmt
  624. | AlterExtensionStmt
  625. | AlterExtensionContentsStmt
  626. | AlterFdwStmt
  627. | AlterForeignServerStmt
  628. | AlterForeignTableStmt
  629. | AlterFunctionStmt
  630. | AlterGroupStmt
  631. | AlterObjectSchemaStmt
  632. | AlterOwnerStmt
  633. | AlterSeqStmt
  634. | AlterSystemStmt
  635. | AlterTableStmt
  636. | AlterCompositeTypeStmt
  637. | AlterRoleSetStmt
  638. | AlterRoleStmt
  639. | AlterTSConfigurationStmt
  640. | AlterTSDictionaryStmt
  641. | AlterUserMappingStmt
  642. | AlterUserSetStmt
  643. | AlterUserStmt
  644. | AnalyzeStmt
  645. | CheckPointStmt
  646. | ClosePortalStmt
  647. | ClusterStmt
  648. | CommentStmt
  649. | ConstraintsSetStmt
  650. | CopyStmt
  651. | CreateAsStmt
  652. | CreateAssertStmt
  653. | CreateCastStmt
  654. | CreateConversionStmt
  655. | CreateDomainStmt
  656. | CreateExtensionStmt
  657. | CreateFdwStmt
  658. | CreateForeignServerStmt
  659. | CreateForeignTableStmt
  660. | CreateFunctionStmt
  661. | CreateGroupStmt
  662. | CreateMatViewStmt
  663. | CreateOpClassStmt
  664. | CreateOpFamilyStmt
  665. | AlterOpFamilyStmt
  666. | CreatePLangStmt
  667. | CreateSchemaStmt
  668. | CreateSeqStmt
  669. | CreateStmt
  670. | CreateTableSpaceStmt
  671. | CreateTrigStmt
  672. | CreateEventTrigStmt
  673. | CreateRoleStmt
  674. | CreateUserStmt
  675. | CreateUserMappingStmt
  676. | CreatedbStmt
  677. | DeallocateStmt
  678. | DeclareCursorStmt
  679. | DefineStmt
  680. | DeleteStmt
  681. | DiscardStmt
  682. | DoStmt
  683. | DropAssertStmt
  684. | DropCastStmt
  685. | DropFdwStmt
  686. | DropForeignServerStmt
  687. | DropGroupStmt
  688. | DropOpClassStmt
  689. | DropOpFamilyStmt
  690. | DropOwnedStmt
  691. | DropPLangStmt
  692. | DropRuleStmt
  693. | DropStmt
  694. | DropTableSpaceStmt
  695. | DropTrigStmt
  696. | DropRoleStmt
  697. | DropUserStmt
  698. | DropUserMappingStmt
  699. | DropdbStmt
  700. | ExecuteStmt
  701. | ExplainStmt
  702. | FetchStmt
  703. | GrantStmt
  704. | GrantRoleStmt
  705. | IndexStmt
  706. | InsertStmt
  707. | ListenStmt
  708. | RefreshMatViewStmt
  709. | LoadStmt
  710. | LockStmt
  711. | NotifyStmt
  712. | PrepareStmt
  713. | ReassignOwnedStmt
  714. | ReindexStmt
  715. | RemoveAggrStmt
  716. | RemoveFuncStmt
  717. | RemoveOperStmt
  718. | RenameStmt
  719. | RevokeStmt
  720. | RevokeRoleStmt
  721. | RuleStmt
  722. | SecLabelStmt
  723. | SelectStmt
  724. | TransactionStmt
  725. | TruncateStmt
  726. | UnlistenStmt
  727. | UpdateStmt
  728. | VacuumStmt
  729. | VariableResetStmt
  730. | VariableSetStmt
  731. | VariableShowStmt
  732. | ViewStmt
  733. | /*EMPTY*/
  734. { $$ = NULL; }
  735. ;
  736. /*****************************************************************************
  737. *
  738. * Create a new Postgres DBMS role
  739. *
  740. *****************************************************************************/
  741. CreateRoleStmt:
  742. CREATE ROLE RoleId opt_with OptRoleList
  743. {
  744. CreateRoleStmt *n = makeNode(CreateRoleStmt);
  745. n->stmt_type = ROLESTMT_ROLE;
  746. n->role = $3;
  747. n->options = $5;
  748. $$ = (Node *)n;
  749. }
  750. ;
  751. opt_with: WITH {}
  752. | /*EMPTY*/ {}
  753. ;
  754. /*
  755. * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
  756. * for backwards compatibility). Note: the only option required by SQL99
  757. * is "WITH ADMIN name".
  758. */
  759. OptRoleList:
  760. OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
  761. | /* EMPTY */ { $$ = NIL; }
  762. ;
  763. AlterOptRoleList:
  764. AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
  765. | /* EMPTY */ { $$ = NIL; }
  766. ;
  767. AlterOptRoleElem:
  768. PASSWORD Sconst
  769. {
  770. $$ = makeDefElem("password",
  771. (Node *)makeString($2));
  772. }
  773. | PASSWORD NULL_P
  774. {
  775. $$ = makeDefElem("password", NULL);
  776. }
  777. | ENCRYPTED PASSWORD Sconst
  778. {
  779. $$ = makeDefElem("encryptedPassword",
  780. (Node *)makeString($3));
  781. }
  782. | UNENCRYPTED PASSWORD Sconst
  783. {
  784. $$ = makeDefElem("unencryptedPassword",
  785. (Node *)makeString($3));
  786. }
  787. | INHERIT
  788. {
  789. $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
  790. }
  791. | CONNECTION LIMIT SignedIconst
  792. {
  793. $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
  794. }
  795. | VALID UNTIL Sconst
  796. {
  797. $$ = makeDefElem("validUntil", (Node *)makeString($3));
  798. }
  799. /* Supported but not documented for roles, for use by ALTER GROUP. */
  800. | USER role_list
  801. {
  802. $$ = makeDefElem("rolemembers", (Node *)$2);
  803. }
  804. | IDENT
  805. {
  806. /*
  807. * We handle identifiers that aren't parser keywords with
  808. * the following special-case codes, to avoid bloating the
  809. * size of the main parser.
  810. */
  811. if (strcmp($1, "superuser") == 0)
  812. $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
  813. else if (strcmp($1, "nosuperuser") == 0)
  814. $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
  815. else if (strcmp($1, "createuser") == 0)
  816. {
  817. /* For backwards compatibility, synonym for SUPERUSER */
  818. $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
  819. }
  820. else if (strcmp($1, "nocreateuser") == 0)
  821. {
  822. /* For backwards compatibility, synonym for SUPERUSER */
  823. $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
  824. }
  825. else if (strcmp($1, "createrole") == 0)
  826. $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
  827. else if (strcmp($1, "nocreaterole") == 0)
  828. $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
  829. else if (strcmp($1, "replication") == 0)
  830. $$ = makeDefElem("isreplication", (Node *)makeInteger(TRUE));
  831. else if (strcmp($1, "noreplication") == 0)
  832. $$ = makeDefElem("isreplication", (Node *)makeInteger(FALSE));
  833. else if (strcmp($1, "createdb") == 0)
  834. $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
  835. else if (strcmp($1, "nocreatedb") == 0)
  836. $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
  837. else if (strcmp($1, "login") == 0)
  838. $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
  839. else if (strcmp($1, "nologin") == 0)
  840. $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
  841. else if (strcmp($1, "noinherit") == 0)
  842. {
  843. /*
  844. * Note that INHERIT is a keyword, so it's handled by main parser, but
  845. * NOINHERIT is handled here.
  846. */
  847. $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
  848. }
  849. else
  850. ereport(ERROR,
  851. (errcode(ERRCODE_SYNTAX_ERROR),
  852. errmsg("unrecognized role option \"%s\"", $1),
  853. parser_errposition(@1)));
  854. }
  855. ;
  856. CreateOptRoleElem:
  857. AlterOptRoleElem { $$ = $1; }
  858. /* The following are not supported by ALTER ROLE/USER/GROUP */
  859. | SYSID Iconst
  860. {
  861. $$ = makeDefElem("sysid", (Node *)makeInteger($2));
  862. }
  863. | ADMIN role_list
  864. {
  865. $$ = makeDefElem("adminmembers", (Node *)$2);
  866. }
  867. | ROLE role_list
  868. {
  869. $$ = makeDefElem("rolemembers", (Node *)$2);
  870. }
  871. | IN_P ROLE role_list
  872. {
  873. $$ = makeDefElem("addroleto", (Node *)$3);
  874. }
  875. | IN_P GROUP_P role_list
  876. {
  877. $$ = makeDefElem("addroleto", (Node *)$3);
  878. }
  879. ;
  880. /*****************************************************************************
  881. *
  882. * Create a new Postgres DBMS user (role with implied login ability)
  883. *
  884. *****************************************************************************/
  885. CreateUserStmt:
  886. CREATE USER RoleId opt_with OptRoleList
  887. {
  888. CreateRoleStmt *n = makeNode(CreateRoleStmt);
  889. n->stmt_type = ROLESTMT_USER;
  890. n->role = $3;
  891. n->options = $5;
  892. $$ = (Node *)n;
  893. }
  894. ;
  895. /*****************************************************************************
  896. *
  897. * Alter a postgresql DBMS role
  898. *
  899. *****************************************************************************/
  900. AlterRoleStmt:
  901. ALTER ROLE RoleId opt_with AlterOptRoleList
  902. {
  903. AlterRoleStmt *n = makeNode(AlterRoleStmt);
  904. n->role = $3;
  905. n->action = +1; /* add, if there are members */
  906. n->options = $5;
  907. $$ = (Node *)n;
  908. }
  909. ;
  910. opt_in_database:
  911. /* EMPTY */ { $$ = NULL; }
  912. | IN_P DATABASE database_name { $$ = $3; }
  913. ;
  914. AlterRoleSetStmt:
  915. ALTER ROLE RoleId opt_in_database SetResetClause
  916. {
  917. AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
  918. n->role = $3;
  919. n->database = $4;
  920. n->setstmt = $5;
  921. $$ = (Node *)n;
  922. }
  923. | ALTER ROLE ALL opt_in_database SetResetClause
  924. {
  925. AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
  926. n->role = NULL;
  927. n->database = $4;
  928. n->setstmt = $5;
  929. $$ = (Node *)n;
  930. }
  931. ;
  932. /*****************************************************************************
  933. *
  934. * Alter a postgresql DBMS user
  935. *
  936. *****************************************************************************/
  937. AlterUserStmt:
  938. ALTER USER RoleId opt_with AlterOptRoleList
  939. {
  940. AlterRoleStmt *n = makeNode(AlterRoleStmt);
  941. n->role = $3;
  942. n->action = +1; /* add, if there are members */
  943. n->options = $5;
  944. $$ = (Node *)n;
  945. }
  946. ;
  947. AlterUserSetStmt:
  948. ALTER USER RoleId SetResetClause
  949. {
  950. AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
  951. n->role = $3;
  952. n->database = NULL;
  953. n->setstmt = $4;
  954. $$ = (Node *)n;
  955. }
  956. ;
  957. /*****************************************************************************
  958. *
  959. * Drop a postgresql DBMS role
  960. *
  961. * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
  962. * might own objects in multiple databases, there is presently no way to
  963. * implement either cascading or restricting. Caveat DBA.
  964. *****************************************************************************/
  965. DropRoleStmt:
  966. DROP ROLE role_list
  967. {
  968. DropRoleStmt *n = makeNode(DropRoleStmt);
  969. n->missing_ok = FALSE;
  970. n->roles = $3;
  971. $$ = (Node *)n;
  972. }
  973. | DROP ROLE IF_P EXISTS role_list
  974. {
  975. DropRoleStmt *n = makeNode(DropRoleStmt);
  976. n->missing_ok = TRUE;
  977. n->roles = $5;
  978. $$ = (Node *)n;
  979. }
  980. ;
  981. /*****************************************************************************
  982. *
  983. * Drop a postgresql DBMS user
  984. *
  985. * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
  986. * might own objects in multiple databases, there is presently no way to
  987. * implement either cascading or restricting. Caveat DBA.
  988. *****************************************************************************/
  989. DropUserStmt:
  990. DROP USER role_list
  991. {
  992. DropRoleStmt *n = makeNode(DropRoleStmt);
  993. n->missing_ok = FALSE;
  994. n->roles = $3;
  995. $$ = (Node *)n;
  996. }
  997. | DROP USER IF_P EXISTS role_list
  998. {
  999. DropRoleStmt *n = makeNode(DropRoleStmt);
  1000. n->roles = $5;
  1001. n->missing_ok = TRUE;
  1002. $$ = (Node *)n;
  1003. }
  1004. ;
  1005. /*****************************************************************************
  1006. *
  1007. * Create a postgresql group (role without login ability)
  1008. *
  1009. *****************************************************************************/
  1010. CreateGroupStmt:
  1011. CREATE GROUP_P RoleId opt_with OptRoleList
  1012. {
  1013. CreateRoleStmt *n = makeNode(CreateRoleStmt);
  1014. n->stmt_type = ROLESTMT_GROUP;
  1015. n->role = $3;
  1016. n->options = $5;
  1017. $$ = (Node *)n;
  1018. }
  1019. ;
  1020. /*****************************************************************************
  1021. *
  1022. * Alter a postgresql group
  1023. *
  1024. *****************************************************************************/
  1025. AlterGroupStmt:
  1026. ALTER GROUP_P RoleId add_drop USER role_list
  1027. {
  1028. AlterRoleStmt *n = makeNode(AlterRoleStmt);
  1029. n->role = $3;
  1030. n->action = $4;
  1031. n->options = list_make1(makeDefElem("rolemembers",
  1032. (Node *)$6));
  1033. $$ = (Node *)n;
  1034. }
  1035. ;
  1036. add_drop: ADD_P { $$ = +1; }
  1037. | DROP { $$ = -1; }
  1038. ;
  1039. /*****************************************************************************
  1040. *
  1041. * Drop a postgresql group
  1042. *
  1043. * XXX see above notes about cascading DROP USER; groups have same problem.
  1044. *****************************************************************************/
  1045. DropGroupStmt:
  1046. DROP GROUP_P role_list
  1047. {
  1048. DropRoleStmt *n = makeNode(DropRoleStmt);
  1049. n->missing_ok = FALSE;
  1050. n->roles = $3;
  1051. $$ = (Node *)n;
  1052. }
  1053. | DROP GROUP_P IF_P EXISTS role_list
  1054. {
  1055. DropRoleStmt *n = makeNode(DropRoleStmt);
  1056. n->missing_ok = TRUE;
  1057. n->roles = $5;
  1058. $$ = (Node *)n;
  1059. }
  1060. ;
  1061. /*****************************************************************************
  1062. *
  1063. * Manipulate a schema
  1064. *
  1065. *****************************************************************************/
  1066. CreateSchemaStmt:
  1067. CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
  1068. {
  1069. CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
  1070. /* One can omit the schema name or the authorization id. */
  1071. if ($3 != NULL)
  1072. n->schemaname = $3;
  1073. else
  1074. n->schemaname = $5;
  1075. n->authid = $5;
  1076. n->schemaElts = $6;
  1077. n->if_not_exists = false;
  1078. $$ = (Node *)n;
  1079. }
  1080. | CREATE SCHEMA ColId OptSchemaEltList
  1081. {
  1082. CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
  1083. /* ...but not both */
  1084. n->schemaname = $3;
  1085. n->authid = NULL;
  1086. n->schemaElts = $4;
  1087. n->if_not_exists = false;
  1088. $$ = (Node *)n;
  1089. }
  1090. | CREATE SCHEMA IF_P NOT EXISTS OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
  1091. {
  1092. CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
  1093. /* One can omit the schema name or the authorization id. */
  1094. if ($6 != NULL)
  1095. n->schemaname = $6;
  1096. else
  1097. n->schemaname = $8;
  1098. n->authid = $8;
  1099. if ($9 != NIL)
  1100. ereport(ERROR,
  1101. (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
  1102. errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
  1103. parser_errposition(@9)));
  1104. n->schemaElts = $9;
  1105. n->if_not_exists = true;
  1106. $$ = (Node *)n;
  1107. }
  1108. | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
  1109. {
  1110. CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
  1111. /* ...but not both */
  1112. n->schemaname = $6;
  1113. n->authid = NULL;
  1114. if ($7 != NIL)
  1115. ereport(ERROR,
  1116. (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
  1117. errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
  1118. parser_errposition(@7)));
  1119. n->schemaElts = $7;
  1120. n->if_not_exists = true;
  1121. $$ = (Node *)n;
  1122. }
  1123. ;
  1124. OptSchemaName:
  1125. ColId { $$ = $1; }
  1126. | /* EMPTY */ { $$ = NULL; }
  1127. ;
  1128. OptSchemaEltList:
  1129. OptSchemaEltList schema_stmt
  1130. {
  1131. if (@$ < 0) /* see comments for YYLLOC_DEFAULT */
  1132. @$ = @2;
  1133. $$ = lappend($1, $2);
  1134. }
  1135. | /* EMPTY */
  1136. { $$ = NIL; }
  1137. ;
  1138. /*
  1139. * schema_stmt are the ones that can show up inside a CREATE SCHEMA
  1140. * statement (in addition to by themselves).
  1141. */
  1142. schema_stmt:
  1143. CreateStmt
  1144. | IndexStmt
  1145. | CreateSeqStmt
  1146. | CreateTrigStmt
  1147. | GrantStmt
  1148. | ViewStmt
  1149. ;
  1150. /*****************************************************************************
  1151. *
  1152. * Set PG internal variable
  1153. * SET name TO 'var_value'
  1154. * Include SQL syntax (thomas 1997-10-22):
  1155. * SET TIME ZONE 'var_value'
  1156. *
  1157. *****************************************************************************/
  1158. VariableSetStmt:
  1159. SET set_rest
  1160. {
  1161. VariableSetStmt *n = $2;
  1162. n->is_local = false;
  1163. $$ = (Node *) n;
  1164. }
  1165. | SET LOCAL set_rest
  1166. {
  1167. VariableSetStmt *n = $3;
  1168. n->is_local = true;
  1169. $$ = (Node *) n;
  1170. }
  1171. | SET SESSION set_rest
  1172. {
  1173. VariableSetStmt *n = $3;
  1174. n->is_local = false;
  1175. $$ = (Node *) n;
  1176. }
  1177. ;
  1178. set_rest:
  1179. TRANSACTION transaction_mode_list
  1180. {
  1181. VariableSetStmt *n = makeNode(VariableSetStmt);
  1182. n->kind = VAR_SET_MULTI;
  1183. n->name = "TRANSACTION";
  1184. n->args = $2;
  1185. $$ = n;
  1186. }
  1187. | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
  1188. {
  1189. VariableSetStmt *n = makeNode(VariableSetStmt);
  1190. n->kind = VAR_SET_MULTI;
  1191. n->name = "SESSION CHARACTERISTICS";
  1192. n->args = $5;
  1193. $$ = n;
  1194. }
  1195. | set_rest_more
  1196. ;
  1197. generic_set:
  1198. var_name TO var_list
  1199. {
  1200. VariableSetStmt *n = makeNode(VariableSetStmt);
  1201. n->kind = VAR_SET_VALUE;
  1202. n->name = $1;
  1203. n->args = $3;
  1204. $$ = n;
  1205. }
  1206. | var_name '=' var_list
  1207. {
  1208. VariableSetStmt *n = makeNode(VariableSetStmt);
  1209. n->kind = VAR_SET_VALUE;
  1210. n->name = $1;
  1211. n->args = $3;
  1212. $$ = n;
  1213. }
  1214. | var_name TO DEFAULT
  1215. {
  1216. VariableSetStmt *n = makeNode(VariableSetStmt);
  1217. n->kind = VAR_SET_DEFAULT;
  1218. n->name = $1;
  1219. $$ = n;
  1220. }
  1221. | var_name '=' DEFAULT
  1222. {
  1223. VariableSetStmt *n = makeNode(VariableSetStmt);
  1224. n->kind = VAR_SET_DEFAULT;
  1225. n->name = $1;
  1226. $$ = n;
  1227. }
  1228. set_rest_more: /* Generic SET syntaxes: */
  1229. generic_set {$$ = $1;}
  1230. | var_name FROM CURRENT_P
  1231. {
  1232. VariableSetStmt *n = makeNode(VariableSetStmt);
  1233. n->kind = VAR_SET_CURRENT;
  1234. n->name = $1;
  1235. $$ = n;
  1236. }
  1237. /* Special syntaxes mandated by SQL standard: */
  1238. | TIME ZONE zone_value
  1239. {
  1240. VariableSetStmt *n = makeNode(VariableSetStmt);
  1241. n->kind = VAR_SET_VALUE;
  1242. n->name = "timezone";
  1243. if ($3 != NULL)
  1244. n->args = list_make1($3);
  1245. else
  1246. n->kind = VAR_SET_DEFAULT;
  1247. $$ = n;
  1248. }
  1249. | CATALOG_P Sconst
  1250. {
  1251. ereport(ERROR,
  1252. (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
  1253. errmsg("current database cannot be changed"),
  1254. parser_errposition(@2)));
  1255. $$ = NULL; /*not reached*/
  1256. }
  1257. | SCHEMA Sconst
  1258. {
  1259. VariableSetStmt *n = makeNode(VariableSetStmt);
  1260. n->kind = VAR_SET_VALUE;
  1261. n->name = "search_path";
  1262. n->args = list_make1(makeStringConst($2, @2));
  1263. $$ = n;
  1264. }
  1265. | NAMES opt_encoding
  1266. {
  1267. VariableSetStmt *n = makeNode(VariableSetStmt);
  1268. n->kind = VAR_SET_VALUE;
  1269. n->name = "client_encoding";
  1270. if ($2 != NULL)
  1271. n->args = list_make1(makeStringConst($2, @2));
  1272. else
  1273. n->kind = VAR_SET_DEFAULT;
  1274. $$ = n;
  1275. }
  1276. | ROLE NonReservedWord_or_Sconst
  1277. {
  1278. VariableSetStmt *n = makeNode(VariableSetStmt);
  1279. n->kind = VAR_SET_VALUE;
  1280. n->name = "role";
  1281. n->args = list_make1(makeStringConst($2, @2));
  1282. $$ = n;
  1283. }
  1284. | SESSION AUTHORIZATION NonReservedWord_or_Sconst
  1285. {
  1286. VariableSetStmt *n = makeNode(VariableSetStmt);
  1287. n->kind = VAR_SET_VALUE;
  1288. n->name = "session_authorization";
  1289. n->args = list_make1(makeStringConst($3, @3));
  1290. $$ = n;
  1291. }
  1292. | SESSION AUTHORIZATION DEFAULT
  1293. {
  1294. VariableSetStmt *n = makeNode(VariableSetStmt);
  1295. n->kind = VAR_SET_DEFAULT;
  1296. n->name = "session_authorization";
  1297. $$ = n;
  1298. }
  1299. | XML_P OPTION document_or_content
  1300. {
  1301. VariableSetStmt *n = makeNode(VariableSetStmt);
  1302. n->kind = VAR_SET_VALUE;
  1303. n->name = "xmloption";
  1304. n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
  1305. $$ = n;
  1306. }
  1307. /* Special syntaxes invented by PostgreSQL: */
  1308. | TRANSACTION SNAPSHOT Sconst
  1309. {
  1310. VariableSetStmt *n = makeNode(VariableSetStmt);
  1311. n->kind = VAR_SET_MULTI;
  1312. n->name = "TRANSACTION SNAPSHOT";
  1313. n->args = list_make1(makeStringConst($3, @3));
  1314. $$ = n;
  1315. }
  1316. ;
  1317. var_name: ColId { $$ = $1; }
  1318. | var_name '.' ColId
  1319. { $$ = psprintf("%s.%s", $1, $3); }
  1320. ;
  1321. var_list: var_value { $$ = list_make1($1); }
  1322. | var_list ',' var_value { $$ = lappend($1, $3); }
  1323. ;
  1324. var_value: opt_boolean_or_string
  1325. { $$ = makeStringConst($1, @1); }
  1326. | NumericOnly
  1327. { $$ = makeAConst($1, @1); }
  1328. ;
  1329. iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
  1330. | READ COMMITTED { $$ = "read committed"; }
  1331. | REPEATABLE READ { $$ = "repeatable read"; }
  1332. | SERIALIZABLE { $$ = "serializable"; }
  1333. ;
  1334. opt_boolean_or_string:
  1335. TRUE_P { $$ = "true"; }
  1336. | FALSE_P { $$ = "false"; }
  1337. | ON { $$ = "on"; }
  1338. /*
  1339. * OFF is also accepted as a boolean value, but is handled by
  1340. * the NonReservedWord rule. The action for booleans and strings
  1341. * is the same, so we don't need to distinguish them here.
  1342. */
  1343. | NonReservedWord_or_Sconst { $$ = $1; }
  1344. ;
  1345. /* Timezone values can be:
  1346. * - a string such as 'pst8pdt'
  1347. * - an identifier such as "pst8pdt"
  1348. * - an integer or floating point number
  1349. * - a time interval per SQL99
  1350. * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
  1351. * so use IDENT (meaning we reject anything that is a key word).
  1352. */
  1353. zone_value:
  1354. Sconst
  1355. {
  1356. $$ = makeStringConst($1, @1);
  1357. }
  1358. | IDENT
  1359. {
  1360. $$ = makeStringConst($1, @1);
  1361. }
  1362. | ConstInterval Sconst opt_interval
  1363. {
  1364. TypeName *t = $1;
  1365. if ($3 != NIL)
  1366. {
  1367. A_Const *n = (A_Const *) linitial($3);
  1368. if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
  1369. ereport(ERROR,
  1370. (errcode(ERRCODE_SYNTAX_ERROR),
  1371. errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
  1372. parser_errposition(@3)));
  1373. }
  1374. t->typmods = $3;
  1375. $$ = makeStringConstCast($2, @2, t);
  1376. }
  1377. | ConstInterval '(' Iconst ')' Sconst opt_interval
  1378. {
  1379. TypeName *t = $1;
  1380. if ($6 != NIL)
  1381. {
  1382. A_Const *n = (A_Const *) linitial($6);
  1383. if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
  1384. ereport(ERROR,
  1385. (errcode(ERRCODE_SYNTAX_ERROR),
  1386. errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
  1387. parser_errposition(@6)));
  1388. if (list_length($6) != 1)
  1389. ereport(ERROR,
  1390. (errcode(ERRCODE_SYNTAX_ERROR),
  1391. errmsg("interval precision specified twice"),
  1392. parser_errposition(@1)));
  1393. t->typmods = lappend($6, makeIntConst($3, @3));
  1394. }
  1395. else
  1396. t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
  1397. makeIntConst($3, @3));
  1398. $$ = makeStringConstCast($5, @5, t);
  1399. }
  1400. | NumericOnly { $$ = makeAConst($1, @1); }
  1401. | DEFAULT { $$ = NULL; }
  1402. | LOCAL { $$ = NULL; }
  1403. ;
  1404. opt_encoding:
  1405. Sconst { $$ = $1; }
  1406. | DEFAULT { $$ = NULL; }
  1407. | /*EMPTY*/ { $$ = NULL; }
  1408. ;
  1409. NonReservedWord_or_Sconst:
  1410. NonReservedWord { $$ = $1; }
  1411. | Sconst { $$ = $1; }
  1412. ;
  1413. VariableResetStmt:
  1414. RESET var_name
  1415. {
  1416. VariableSetStmt *n = makeNode(VariableSetStmt);
  1417. n->kind = VAR_RESET;
  1418. n->name = $2;
  1419. $$ = (Node *) n;
  1420. }
  1421. | RESET TIME ZONE
  1422. {
  1423. VariableSetStmt *n = makeNode(VariableSetStmt);
  1424. n->kind = VAR_RESET;
  1425. n->name = "timezone";
  1426. $$ = (Node *) n;
  1427. }
  1428. | RESET TRANSACTION ISOLATION LEVEL
  1429. {
  1430. VariableSetStmt *n = makeNode(VariableSetStmt);
  1431. n->kind = VAR_RESET;
  1432. n->name = "transaction_isolation";
  1433. $$ = (Node *) n;
  1434. }
  1435. | RESET SESSION AUTHORIZATION
  1436. {
  1437. VariableSetStmt *n = makeNode(VariableSetStmt);
  1438. n->kind = VAR_RESET;
  1439. n->name = "session_authorization";
  1440. $$ = (Node *) n;
  1441. }
  1442. | RESET ALL
  1443. {
  1444. VariableSetStmt *n = makeNode(VariableSetStmt);
  1445. n->kind = VAR_RESET_ALL;
  1446. $$ = (Node *) n;
  1447. }
  1448. ;
  1449. /* SetResetClause allows SET or RESET without LOCAL */
  1450. SetResetClause:
  1451. SET set_rest { $$ = $2; }
  1452. | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
  1453. ;
  1454. /* SetResetClause allows SET or RESET without LOCAL */
  1455. FunctionSetResetClause:
  1456. SET set_rest_more { $$ = $2; }
  1457. | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
  1458. ;
  1459. VariableShowStmt:
  1460. SHOW var_name
  1461. {
  1462. VariableShowStmt *n = makeNode(VariableShowStmt);
  1463. n->name = $2;
  1464. $$ = (Node *) n;
  1465. }
  1466. | SHOW TIME ZONE
  1467. {
  1468. VariableShowStmt *n = makeNode(VariableShowStmt);
  1469. n->name = "timezone";
  1470. $$ = (Node *) n;
  1471. }
  1472. | SHOW TRANSACTION ISOLATION LEVEL
  1473. {
  1474. VariableShowStmt *n = makeNode(VariableShowStmt);
  1475. n->name = "transaction_isolation";
  1476. $$ = (Node *) n;
  1477. }
  1478. | SHOW SESSION AUTHORIZATION
  1479. {
  1480. VariableShowStmt *n = makeNode(VariableShowStmt);
  1481. n->name = "session_authorization";
  1482. $$ = (Node *) n;
  1483. }
  1484. | SHOW ALL
  1485. {
  1486. VariableShowStmt *n = makeNode(VariableShowStmt);
  1487. n->name = "all";
  1488. $$ = (Node *) n;
  1489. }
  1490. ;
  1491. ConstraintsSetStmt:
  1492. SET CONSTRAINTS constraints_set_list constraints_set_mode
  1493. {
  1494. ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
  1495. n->constraints = $3;
  1496. n->deferred = $4;
  1497. $$ = (Node *) n;
  1498. }
  1499. ;
  1500. constraints_set_list:
  1501. ALL { $$ = NIL; }
  1502. | qualified_name_list { $$ = $1; }
  1503. ;
  1504. constraints_set_mode:
  1505. DEFERRED { $$ = TRUE; }
  1506. | IMMEDIATE { $$ = FALSE; }
  1507. ;
  1508. /*
  1509. * Checkpoint statement
  1510. */
  1511. CheckPointStmt:
  1512. CHECKPOINT
  1513. {
  1514. Check

Large files files are truncated, but you can click here to view the full file