/src/backend/parser/gram.y
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
- %{
- /*#define YYDEBUG 1*/
- /*-------------------------------------------------------------------------
- *
- * gram.y
- * POSTGRESQL BISON rules/actions
- *
- * Portions Copyright (c) 1996-2014, PostgreSQL Global Development Group
- * Portions Copyright (c) 1994, Regents of the University of California
- *
- *
- * IDENTIFICATION
- * src/backend/parser/gram.y
- *
- * HISTORY
- * AUTHOR DATE MAJOR EVENT
- * Andrew Yu Sept, 1994 POSTQUEL to SQL conversion
- * Andrew Yu Oct, 1994 lispy code conversion
- *
- * NOTES
- * CAPITALS are used to represent terminal symbols.
- * non-capitals are used to represent non-terminals.
- *
- * In general, nothing in this file should initiate database accesses
- * nor depend on changeable state (such as SET variables). If you do
- * database accesses, your code will fail when we have aborted the
- * current transaction and are just parsing commands to find the next
- * ROLLBACK or COMMIT. If you make use of SET variables, then you
- * will do the wrong thing in multi-query strings like this:
- * SET SQL_inheritance TO off; SELECT * FROM foo;
- * because the entire string is parsed by gram.y before the SET gets
- * executed. Anything that depends on the database or changeable state
- * should be handled during parse analysis so that it happens at the
- * right time not the wrong time. The handling of SQL_inheritance is
- * a good example.
- *
- * WARNINGS
- * If you use a list, make sure the datum is a node so that the printing
- * routines work.
- *
- * Sometimes we assign constants to makeStrings. Make sure we don't free
- * those.
- *
- *-------------------------------------------------------------------------
- */
- #include "postgres.h"
- #include <ctype.h>
- #include <limits.h>
- #include "catalog/index.h"
- #include "catalog/namespace.h"
- #include "catalog/pg_trigger.h"
- #include "commands/defrem.h"
- #include "commands/trigger.h"
- #include "nodes/makefuncs.h"
- #include "nodes/nodeFuncs.h"
- #include "parser/gramparse.h"
- #include "parser/parser.h"
- #include "storage/lmgr.h"
- #include "utils/date.h"
- #include "utils/datetime.h"
- #include "utils/numeric.h"
- #include "utils/xml.h"
- /*
- * Location tracking support --- simpler than bison's default, since we only
- * want to track the start position not the end position of each nonterminal.
- */
- #define YYLLOC_DEFAULT(Current, Rhs, N) \
- do { \
- if ((N) > 0) \
- (Current) = (Rhs)[1]; \
- else \
- (Current) = (-1); \
- } while (0)
- /*
- * The above macro assigns -1 (unknown) as the parse location of any
- * nonterminal that was reduced from an empty rule. This is problematic
- * for nonterminals defined like
- * OptFooList: / * EMPTY * / { ... } | OptFooList Foo { ... } ;
- * because we'll set -1 as the location during the first reduction and then
- * copy it during each subsequent reduction, leaving us with -1 for the
- * location even when the list is not empty. To fix that, do this in the
- * action for the nonempty rule(s):
- * if (@$ < 0) @$ = @2;
- * (Although we have many nonterminals that follow this pattern, we only
- * bother with fixing @$ like this when the nonterminal's parse location
- * is actually referenced in some rule.)
- */
- /*
- * Bison doesn't allocate anything that needs to live across parser calls,
- * so we can easily have it use palloc instead of malloc. This prevents
- * memory leaks if we error out during parsing. Note this only works with
- * bison >= 2.0. However, in bison 1.875 the default is to use alloca()
- * if possible, so there's not really much problem anyhow, at least if
- * you're building with gcc.
- */
- #define YYMALLOC palloc
- #define YYFREE pfree
- /* Private struct for the result of privilege_target production */
- typedef struct PrivTarget
- {
- GrantTargetType targtype;
- GrantObjectType objtype;
- List *objs;
- } PrivTarget;
- /* ConstraintAttributeSpec yields an integer bitmask of these flags: */
- #define CAS_NOT_DEFERRABLE 0x01
- #define CAS_DEFERRABLE 0x02
- #define CAS_INITIALLY_IMMEDIATE 0x04
- #define CAS_INITIALLY_DEFERRED 0x08
- #define CAS_NOT_VALID 0x10
- #define CAS_NO_INHERIT 0x20
- #define parser_yyerror(msg) scanner_yyerror(msg, yyscanner)
- #define parser_errposition(pos) scanner_errposition(pos, yyscanner)
- static void base_yyerror(YYLTYPE *yylloc, core_yyscan_t yyscanner,
- const char *msg);
- static Node *makeColumnRef(char *colname, List *indirection,
- int location, core_yyscan_t yyscanner);
- static Node *makeTypeCast(Node *arg, TypeName *typename, int location);
- static Node *makeStringConst(char *str, int location);
- static Node *makeStringConstCast(char *str, int location, TypeName *typename);
- static Node *makeIntConst(int val, int location);
- static Node *makeFloatConst(char *str, int location);
- static Node *makeBitStringConst(char *str, int location);
- static Node *makeNullAConst(int location);
- static Node *makeAConst(Value *v, int location);
- static Node *makeBoolAConst(bool state, int location);
- static void check_qualified_name(List *names, core_yyscan_t yyscanner);
- static List *check_func_name(List *names, core_yyscan_t yyscanner);
- static List *check_indirection(List *indirection, core_yyscan_t yyscanner);
- static List *extractArgTypes(List *parameters);
- static List *extractAggrArgTypes(List *aggrargs);
- static List *makeOrderedSetArgs(List *directargs, List *orderedargs,
- core_yyscan_t yyscanner);
- static void insertSelectOptions(SelectStmt *stmt,
- List *sortClause, List *lockingClause,
- Node *limitOffset, Node *limitCount,
- WithClause *withClause,
- core_yyscan_t yyscanner);
- static Node *makeSetOp(SetOperation op, bool all, Node *larg, Node *rarg);
- static Node *doNegate(Node *n, int location);
- static void doNegateFloat(Value *v);
- static Node *makeAArrayExpr(List *elements, int location);
- static Node *makeXmlExpr(XmlExprOp op, char *name, List *named_args,
- List *args, int location);
- static List *mergeTableFuncParameters(List *func_args, List *columns);
- static TypeName *TableFuncTypeName(List *columns);
- static RangeVar *makeRangeVarFromAnyName(List *names, int position, core_yyscan_t yyscanner);
- static void SplitColQualList(List *qualList,
- List **constraintList, CollateClause **collClause,
- core_yyscan_t yyscanner);
- static void processCASbits(int cas_bits, int location, const char *constrType,
- bool *deferrable, bool *initdeferred, bool *not_valid,
- bool *no_inherit, core_yyscan_t yyscanner);
- static Node *makeRecursiveViewSelect(char *relname, List *aliases, Node *query);
- %}
- %pure-parser
- %expect 0
- %name-prefix="base_yy"
- %locations
- %parse-param {core_yyscan_t yyscanner}
- %lex-param {core_yyscan_t yyscanner}
- %union
- {
- core_YYSTYPE core_yystype;
- /* these fields must match core_YYSTYPE: */
- int ival;
- char *str;
- const char *keyword;
- char chr;
- bool boolean;
- JoinType jtype;
- DropBehavior dbehavior;
- OnCommitAction oncommit;
- List *list;
- Node *node;
- Value *value;
- ObjectType objtype;
- TypeName *typnam;
- FunctionParameter *fun_param;
- FunctionParameterMode fun_param_mode;
- FuncWithArgs *funwithargs;
- DefElem *defelt;
- SortBy *sortby;
- WindowDef *windef;
- JoinExpr *jexpr;
- IndexElem *ielem;
- Alias *alias;
- RangeVar *range;
- IntoClause *into;
- WithClause *with;
- A_Indices *aind;
- ResTarget *target;
- struct PrivTarget *privtarget;
- AccessPriv *accesspriv;
- InsertStmt *istmt;
- VariableSetStmt *vsetstmt;
- }
- %type <node> stmt schema_stmt
- AlterEventTrigStmt
- AlterDatabaseStmt AlterDatabaseSetStmt AlterDomainStmt AlterEnumStmt
- AlterFdwStmt AlterForeignServerStmt AlterGroupStmt
- AlterObjectSchemaStmt AlterOwnerStmt AlterSeqStmt AlterSystemStmt AlterTableStmt
- AlterExtensionStmt AlterExtensionContentsStmt AlterForeignTableStmt
- AlterCompositeTypeStmt AlterUserStmt AlterUserMappingStmt AlterUserSetStmt
- AlterRoleStmt AlterRoleSetStmt
- AlterDefaultPrivilegesStmt DefACLAction
- AnalyzeStmt ClosePortalStmt ClusterStmt CommentStmt
- ConstraintsSetStmt CopyStmt CreateAsStmt CreateCastStmt
- CreateDomainStmt CreateExtensionStmt CreateGroupStmt CreateOpClassStmt
- CreateOpFamilyStmt AlterOpFamilyStmt CreatePLangStmt
- CreateSchemaStmt CreateSeqStmt CreateStmt CreateTableSpaceStmt
- CreateFdwStmt CreateForeignServerStmt CreateForeignTableStmt
- CreateAssertStmt CreateTrigStmt CreateEventTrigStmt
- CreateUserStmt CreateUserMappingStmt CreateRoleStmt
- CreatedbStmt DeclareCursorStmt DefineStmt DeleteStmt DiscardStmt DoStmt
- DropGroupStmt DropOpClassStmt DropOpFamilyStmt DropPLangStmt DropStmt
- DropAssertStmt DropTrigStmt DropRuleStmt DropCastStmt DropRoleStmt
- DropUserStmt DropdbStmt DropTableSpaceStmt DropFdwStmt
- DropForeignServerStmt DropUserMappingStmt ExplainStmt FetchStmt
- GrantStmt GrantRoleStmt IndexStmt InsertStmt ListenStmt LoadStmt
- LockStmt NotifyStmt ExplainableStmt PreparableStmt
- CreateFunctionStmt AlterFunctionStmt ReindexStmt RemoveAggrStmt
- RemoveFuncStmt RemoveOperStmt RenameStmt RevokeStmt RevokeRoleStmt
- RuleActionStmt RuleActionStmtOrEmpty RuleStmt
- SecLabelStmt SelectStmt TransactionStmt TruncateStmt
- UnlistenStmt UpdateStmt VacuumStmt
- VariableResetStmt VariableSetStmt VariableShowStmt
- ViewStmt CheckPointStmt CreateConversionStmt
- DeallocateStmt PrepareStmt ExecuteStmt
- DropOwnedStmt ReassignOwnedStmt
- AlterTSConfigurationStmt AlterTSDictionaryStmt
- CreateMatViewStmt RefreshMatViewStmt
- %type <node> select_no_parens select_with_parens select_clause
- simple_select values_clause
- %type <node> alter_column_default opclass_item opclass_drop alter_using
- %type <ival> add_drop opt_asc_desc opt_nulls_order
- %type <node> alter_table_cmd alter_type_cmd opt_collate_clause
- replica_identity
- %type <list> alter_table_cmds alter_type_cmds
- %type <dbehavior> opt_drop_behavior
- %type <list> createdb_opt_list alterdb_opt_list copy_opt_list
- transaction_mode_list
- create_extension_opt_list alter_extension_opt_list
- %type <defelt> createdb_opt_item alterdb_opt_item copy_opt_item
- transaction_mode_item
- create_extension_opt_item alter_extension_opt_item
- %type <ival> opt_lock lock_type cast_context
- %type <ival> vacuum_option_list vacuum_option_elem
- %type <boolean> opt_force opt_or_replace
- opt_grant_grant_option opt_grant_admin_option
- opt_nowait opt_if_exists opt_with_data
- %type <list> OptRoleList AlterOptRoleList
- %type <defelt> CreateOptRoleElem AlterOptRoleElem
- %type <str> opt_type
- %type <str> foreign_server_version opt_foreign_server_version
- %type <str> auth_ident
- %type <str> opt_in_database
- %type <str> OptSchemaName
- %type <list> OptSchemaEltList
- %type <boolean> TriggerForSpec TriggerForType
- %type <ival> TriggerActionTime
- %type <list> TriggerEvents TriggerOneEvent
- %type <value> TriggerFuncArg
- %type <node> TriggerWhen
- %type <list> event_trigger_when_list event_trigger_value_list
- %type <defelt> event_trigger_when_item
- %type <chr> enable_trigger
- %type <str> copy_file_name
- database_name access_method_clause access_method attr_name
- name cursor_name file_name
- index_name opt_index_name cluster_index_specification
- %type <list> func_name handler_name qual_Op qual_all_Op subquery_Op
- opt_class opt_inline_handler opt_validator validator_clause
- opt_collate
- %type <range> qualified_name OptConstrFromTable
- %type <str> all_Op MathOp
- %type <str> iso_level opt_encoding
- %type <node> grantee
- %type <list> grantee_list
- %type <accesspriv> privilege
- %type <list> privileges privilege_list
- %type <privtarget> privilege_target
- %type <funwithargs> function_with_argtypes
- %type <list> function_with_argtypes_list
- %type <ival> defacl_privilege_target
- %type <defelt> DefACLOption
- %type <list> DefACLOptionList
- %type <list> stmtblock stmtmulti
- OptTableElementList TableElementList OptInherit definition
- OptTypedTableElementList TypedTableElementList
- reloptions opt_reloptions
- OptWith opt_distinct opt_definition func_args func_args_list
- func_args_with_defaults func_args_with_defaults_list
- aggr_args aggr_args_list
- func_as createfunc_opt_list alterfunc_opt_list
- old_aggr_definition old_aggr_list
- oper_argtypes RuleActionList RuleActionMulti
- opt_column_list columnList opt_name_list
- sort_clause opt_sort_clause sortby_list index_params
- name_list role_list from_clause from_list opt_array_bounds
- qualified_name_list any_name any_name_list
- any_operator expr_list attrs
- target_list opt_target_list insert_column_list set_target_list
- set_clause_list set_clause multiple_set_clause
- ctext_expr_list ctext_row def_list indirection opt_indirection
- reloption_list group_clause TriggerFuncArgs select_limit
- opt_select_limit opclass_item_list opclass_drop_list
- opclass_purpose opt_opfamily transaction_mode_list_or_empty
- OptTableFuncElementList TableFuncElementList opt_type_modifiers
- prep_type_clause
- execute_param_clause using_clause returning_clause
- opt_enum_val_list enum_val_list table_func_column_list
- create_generic_options alter_generic_options
- relation_expr_list dostmt_opt_list
- %type <list> opt_fdw_options fdw_options
- %type <defelt> fdw_option
- %type <range> OptTempTableName
- %type <into> into_clause create_as_target create_mv_target
- %type <defelt> createfunc_opt_item common_func_opt_item dostmt_opt_item
- %type <fun_param> func_arg func_arg_with_default table_func_column aggr_arg
- %type <fun_param_mode> arg_class
- %type <typnam> func_return func_type
- %type <boolean> opt_trusted opt_restart_seqs
- %type <ival> OptTemp
- %type <ival> OptNoLog
- %type <oncommit> OnCommitOption
- %type <ival> for_locking_strength
- %type <node> for_locking_item
- %type <list> for_locking_clause opt_for_locking_clause for_locking_items
- %type <list> locked_rels_list
- %type <boolean> opt_all
- %type <node> join_outer join_qual
- %type <jtype> join_type
- %type <list> extract_list overlay_list position_list
- %type <list> substr_list trim_list
- %type <list> opt_interval interval_second
- %type <node> overlay_placing substr_from substr_for
- %type <boolean> opt_instead
- %type <boolean> opt_unique opt_concurrently opt_verbose opt_full
- %type <boolean> opt_freeze opt_default opt_recheck
- %type <defelt> opt_binary opt_oids copy_delimiter
- %type <boolean> copy_from opt_program
- %type <ival> opt_column event cursor_options opt_hold opt_set_data
- %type <objtype> reindex_type drop_type comment_type security_label_type
- %type <node> fetch_args limit_clause select_limit_value
- offset_clause select_offset_value
- select_offset_value2 opt_select_fetch_first_value
- %type <ival> row_or_rows first_or_next
- %type <list> OptSeqOptList SeqOptList
- %type <defelt> SeqOptElem
- %type <istmt> insert_rest
- %type <vsetstmt> generic_set set_rest set_rest_more SetResetClause FunctionSetResetClause
- %type <node> TableElement TypedTableElement ConstraintElem TableFuncElement
- %type <node> columnDef columnOptions
- %type <defelt> def_elem reloption_elem old_aggr_elem
- %type <node> def_arg columnElem where_clause where_or_current_clause
- a_expr b_expr c_expr AexprConst indirection_el
- columnref in_expr having_clause func_table array_expr
- ExclusionWhereClause
- %type <list> rowsfrom_item rowsfrom_list opt_col_def_list
- %type <boolean> opt_ordinality
- %type <list> ExclusionConstraintList ExclusionConstraintElem
- %type <list> func_arg_list
- %type <node> func_arg_expr
- %type <list> row type_list array_expr_list
- %type <node> case_expr case_arg when_clause case_default
- %type <list> when_clause_list
- %type <ival> sub_type
- %type <node> ctext_expr
- %type <value> NumericOnly
- %type <list> NumericOnly_list
- %type <alias> alias_clause opt_alias_clause
- %type <list> func_alias_clause
- %type <sortby> sortby
- %type <ielem> index_elem
- %type <node> table_ref
- %type <jexpr> joined_table
- %type <range> relation_expr
- %type <range> relation_expr_opt_alias
- %type <target> target_el single_set_clause set_target insert_column_item
- %type <str> generic_option_name
- %type <node> generic_option_arg
- %type <defelt> generic_option_elem alter_generic_option_elem
- %type <list> generic_option_list alter_generic_option_list
- %type <str> explain_option_name
- %type <node> explain_option_arg
- %type <defelt> explain_option_elem
- %type <list> explain_option_list
- %type <node> copy_generic_opt_arg copy_generic_opt_arg_list_item
- %type <defelt> copy_generic_opt_elem
- %type <list> copy_generic_opt_list copy_generic_opt_arg_list
- %type <list> copy_options
- %type <typnam> Typename SimpleTypename ConstTypename
- GenericType Numeric opt_float
- Character ConstCharacter
- CharacterWithLength CharacterWithoutLength
- ConstDatetime ConstInterval
- Bit ConstBit BitWithLength BitWithoutLength
- %type <str> character
- %type <str> extract_arg
- %type <str> opt_charset
- %type <boolean> opt_varying opt_timezone opt_no_inherit
- %type <ival> Iconst SignedIconst
- %type <str> Sconst comment_text notify_payload
- %type <str> RoleId opt_granted_by opt_boolean_or_string
- %type <list> var_list
- %type <str> ColId ColLabel var_name type_function_name param_name
- %type <str> NonReservedWord NonReservedWord_or_Sconst
- %type <node> var_value zone_value
- %type <keyword> unreserved_keyword type_func_name_keyword
- %type <keyword> col_name_keyword reserved_keyword
- %type <node> TableConstraint TableLikeClause
- %type <ival> TableLikeOptionList TableLikeOption
- %type <list> ColQualList
- %type <node> ColConstraint ColConstraintElem ConstraintAttr
- %type <ival> key_actions key_delete key_match key_update key_action
- %type <ival> ConstraintAttributeSpec ConstraintAttributeElem
- %type <str> ExistingIndex
- %type <list> constraints_set_list
- %type <boolean> constraints_set_mode
- %type <str> OptTableSpace OptConsTableSpace OptTableSpaceOwner
- %type <ival> opt_check_option
- %type <str> opt_provider security_label
- %type <target> xml_attribute_el
- %type <list> xml_attribute_list xml_attributes
- %type <node> xml_root_version opt_xml_root_standalone
- %type <node> xmlexists_argument
- %type <ival> document_or_content
- %type <boolean> xml_whitespace_option
- %type <node> func_application func_expr_common_subexpr
- %type <node> func_expr func_expr_windowless
- %type <node> common_table_expr
- %type <with> with_clause opt_with_clause
- %type <list> cte_list
- %type <list> within_group_clause
- %type <node> filter_clause
- %type <list> window_clause window_definition_list opt_partition_clause
- %type <windef> window_definition over_clause window_specification
- opt_frame_clause frame_extent frame_bound
- %type <str> opt_existing_window_name
- %type <boolean> opt_if_not_exists
- /*
- * Non-keyword token types. These are hard-wired into the "flex" lexer.
- * They must be listed first so that their numeric codes do not depend on
- * the set of keywords. PL/pgsql depends on this so that it can share the
- * same lexer. If you add/change tokens here, fix PL/pgsql to match!
- *
- * DOT_DOT is unused in the core SQL grammar, and so will always provoke
- * parse errors. It is needed by PL/pgsql.
- */
- %token <str> IDENT FCONST SCONST BCONST XCONST Op
- %token <ival> ICONST PARAM
- %token TYPECAST DOT_DOT COLON_EQUALS
- /*
- * If you want to make any keyword changes, update the keyword table in
- * src/include/parser/kwlist.h and add new keywords to the appropriate one
- * of the reserved-or-not-so-reserved keyword lists, below; search
- * this file for "Keyword category lists".
- */
- /* ordinary key words in alphabetical order */
- %token <keyword> ABORT_P ABSOLUTE_P ACCESS ACTION ADD_P ADMIN AFTER
- AGGREGATE ALL ALSO ALTER ALWAYS ANALYSE ANALYZE AND ANY ARRAY AS ASC
- ASSERTION ASSIGNMENT ASYMMETRIC AT ATTRIBUTE AUTHORIZATION
- BACKWARD BEFORE BEGIN_P BETWEEN BIGINT BINARY BIT
- BOOLEAN_P BOTH BY
- CACHE CALLED CASCADE CASCADED CASE CAST CATALOG_P CHAIN CHAR_P
- CHARACTER CHARACTERISTICS CHECK CHECKPOINT CLASS CLOSE
- CLUSTER COALESCE COLLATE COLLATION COLUMN COMMENT COMMENTS COMMIT
- COMMITTED CONCURRENTLY CONFIGURATION CONNECTION CONSTRAINT CONSTRAINTS
- CONTENT_P CONTINUE_P CONVERSION_P COPY COST CREATE
- CROSS CSV CURRENT_P
- CURRENT_CATALOG CURRENT_DATE CURRENT_ROLE CURRENT_SCHEMA
- CURRENT_TIME CURRENT_TIMESTAMP CURRENT_USER CURSOR CYCLE
- DATA_P DATABASE DAY_P DEALLOCATE DEC DECIMAL_P DECLARE DEFAULT DEFAULTS
- DEFERRABLE DEFERRED DEFINER DELETE_P DELIMITER DELIMITERS DESC
- DICTIONARY DISABLE_P DISCARD DISTINCT DO DOCUMENT_P DOMAIN_P DOUBLE_P DROP
- EACH ELSE ENABLE_P ENCODING ENCRYPTED END_P ENUM_P ESCAPE EVENT EXCEPT
- EXCLUDE EXCLUDING EXCLUSIVE EXECUTE EXISTS EXPLAIN
- EXTENSION EXTERNAL EXTRACT
- FALSE_P FAMILY FETCH FILTER FIRST_P FLOAT_P FOLLOWING FOR
- FORCE FOREIGN FORWARD FREEZE FROM FULL FUNCTION FUNCTIONS
- GLOBAL GRANT GRANTED GREATEST GROUP_P
- HANDLER HAVING HEADER_P HOLD HOUR_P
- IDENTITY_P IF_P ILIKE IMMEDIATE IMMUTABLE IMPLICIT_P IN_P
- INCLUDING INCREMENT INDEX INDEXES INHERIT INHERITS INITIALLY INLINE_P
- INNER_P INOUT INPUT_P INSENSITIVE INSERT INSTEAD INT_P INTEGER
- INTERSECT INTERVAL INTO INVOKER IS ISNULL ISOLATION
- JOIN
- KEY
- LABEL LANGUAGE LARGE_P LAST_P LATERAL_P LC_COLLATE_P LC_CTYPE_P
- LEADING LEAKPROOF LEAST LEFT LEVEL LIKE LIMIT LISTEN LOAD LOCAL
- LOCALTIME LOCALTIMESTAMP LOCATION LOCK_P
- MAPPING MATCH MATERIALIZED MAXVALUE MINUTE_P MINVALUE MODE MONTH_P MOVE
- NAME_P NAMES NATIONAL NATURAL NCHAR NEXT NO NONE
- NOT NOTHING NOTIFY NOTNULL NOWAIT NULL_P NULLIF
- NULLS_P NUMERIC
- OBJECT_P OF OFF OFFSET OIDS ON ONLY OPERATOR OPTION OPTIONS OR
- ORDER ORDINALITY OUT_P OUTER_P OVER OVERLAPS OVERLAY OWNED OWNER
- PARSER PARTIAL PARTITION PASSING PASSWORD PLACING PLANS POSITION
- PRECEDING PRECISION PRESERVE PREPARE PREPARED PRIMARY
- PRIOR PRIVILEGES PROCEDURAL PROCEDURE PROGRAM
- QUOTE
- RANGE READ REAL REASSIGN RECHECK RECURSIVE REF REFERENCES REFRESH REINDEX
- RELATIVE_P RELEASE RENAME REPEATABLE REPLACE REPLICA
- RESET RESTART RESTRICT RETURNING RETURNS REVOKE RIGHT ROLE ROLLBACK
- ROW ROWS RULE
- SAVEPOINT SCHEMA SCROLL SEARCH SECOND_P SECURITY SELECT SEQUENCE SEQUENCES
- SERIALIZABLE SERVER SESSION SESSION_USER SET SETOF SHARE
- SHOW SIMILAR SIMPLE SMALLINT SNAPSHOT SOME STABLE STANDALONE_P START
- STATEMENT STATISTICS STDIN STDOUT STORAGE STRICT_P STRIP_P SUBSTRING
- SYMMETRIC SYSID SYSTEM_P
- TABLE TABLES TABLESPACE TEMP TEMPLATE TEMPORARY TEXT_P THEN TIME TIMESTAMP
- TO TRAILING TRANSACTION TREAT TRIGGER TRIM TRUE_P
- TRUNCATE TRUSTED TYPE_P TYPES_P
- UNBOUNDED UNCOMMITTED UNENCRYPTED UNION UNIQUE UNKNOWN UNLISTEN UNLOGGED
- UNTIL UPDATE USER USING
- VACUUM VALID VALIDATE VALIDATOR VALUE_P VALUES VARCHAR VARIADIC VARYING
- VERBOSE VERSION_P VIEW VIEWS VOLATILE
- WHEN WHERE WHITESPACE_P WINDOW WITH WITHIN WITHOUT WORK WRAPPER WRITE
- XML_P XMLATTRIBUTES XMLCONCAT XMLELEMENT XMLEXISTS XMLFOREST XMLPARSE
- XMLPI XMLROOT XMLSERIALIZE
- YEAR_P YES_P
- ZONE
- /*
- * The grammar thinks these are keywords, but they are not in the kwlist.h
- * list and so can never be entered directly. The filter in parser.c
- * creates these tokens when required.
- */
- %token NULLS_FIRST NULLS_LAST WITH_ORDINALITY WITH_TIME
- /* Precedence: lowest to highest */
- %nonassoc SET /* see relation_expr_opt_alias */
- %left UNION EXCEPT
- %left INTERSECT
- %left OR
- %left AND
- %right NOT
- %right '='
- %nonassoc '<' '>'
- %nonassoc LIKE ILIKE SIMILAR
- %nonassoc ESCAPE
- %nonassoc OVERLAPS
- %nonassoc BETWEEN
- %nonassoc IN_P
- %left POSTFIXOP /* dummy for postfix Op rules */
- /*
- * To support target_el without AS, we must give IDENT an explicit priority
- * between POSTFIXOP and Op. We can safely assign the same priority to
- * various unreserved keywords as needed to resolve ambiguities (this can't
- * have any bad effects since obviously the keywords will still behave the
- * same as if they weren't keywords). We need to do this for PARTITION,
- * RANGE, ROWS to support opt_existing_window_name; and for RANGE, ROWS
- * so that they can follow a_expr without creating postfix-operator problems;
- * and for NULL so that it can follow b_expr in ColQualList without creating
- * postfix-operator problems.
- *
- * The frame_bound productions UNBOUNDED PRECEDING and UNBOUNDED FOLLOWING
- * are even messier: since UNBOUNDED is an unreserved keyword (per spec!),
- * there is no principled way to distinguish these from the productions
- * a_expr PRECEDING/FOLLOWING. We hack this up by giving UNBOUNDED slightly
- * lower precedence than PRECEDING and FOLLOWING. At present this doesn't
- * appear to cause UNBOUNDED to be treated differently from other unreserved
- * keywords anywhere else in the grammar, but it's definitely risky. We can
- * blame any funny behavior of UNBOUNDED on the SQL standard, though.
- */
- %nonassoc UNBOUNDED /* ideally should have same precedence as IDENT */
- %nonassoc IDENT NULL_P PARTITION RANGE ROWS PRECEDING FOLLOWING
- %left Op OPERATOR /* multi-character ops and user-defined operators */
- %nonassoc NOTNULL
- %nonassoc ISNULL
- %nonassoc IS /* sets precedence for IS NULL, etc */
- %left '+' '-'
- %left '*' '/' '%'
- %left '^'
- /* Unary Operators */
- %left AT /* sets precedence for AT TIME ZONE */
- %left COLLATE
- %right UMINUS
- %left '[' ']'
- %left '(' ')'
- %left TYPECAST
- %left '.'
- /*
- * These might seem to be low-precedence, but actually they are not part
- * of the arithmetic hierarchy at all in their use as JOIN operators.
- * We make them high-precedence to support their use as function names.
- * They wouldn't be given a precedence at all, were it not that we need
- * left-associativity among the JOIN rules themselves.
- */
- %left JOIN CROSS LEFT FULL RIGHT INNER_P NATURAL
- /* kluge to keep xml_whitespace_option from causing shift/reduce conflicts */
- %right PRESERVE STRIP_P
- %%
- /*
- * The target production for the whole parse.
- */
- stmtblock: stmtmulti
- {
- pg_yyget_extra(yyscanner)->parsetree = $1;
- }
- ;
- /* the thrashing around here is to discard "empty" statements... */
- stmtmulti: stmtmulti ';' stmt
- {
- if ($3 != NULL)
- $$ = lappend($1, $3);
- else
- $$ = $1;
- }
- | stmt
- {
- if ($1 != NULL)
- $$ = list_make1($1);
- else
- $$ = NIL;
- }
- ;
- stmt :
- AlterEventTrigStmt
- | AlterDatabaseStmt
- | AlterDatabaseSetStmt
- | AlterDefaultPrivilegesStmt
- | AlterDomainStmt
- | AlterEnumStmt
- | AlterExtensionStmt
- | AlterExtensionContentsStmt
- | AlterFdwStmt
- | AlterForeignServerStmt
- | AlterForeignTableStmt
- | AlterFunctionStmt
- | AlterGroupStmt
- | AlterObjectSchemaStmt
- | AlterOwnerStmt
- | AlterSeqStmt
- | AlterSystemStmt
- | AlterTableStmt
- | AlterCompositeTypeStmt
- | AlterRoleSetStmt
- | AlterRoleStmt
- | AlterTSConfigurationStmt
- | AlterTSDictionaryStmt
- | AlterUserMappingStmt
- | AlterUserSetStmt
- | AlterUserStmt
- | AnalyzeStmt
- | CheckPointStmt
- | ClosePortalStmt
- | ClusterStmt
- | CommentStmt
- | ConstraintsSetStmt
- | CopyStmt
- | CreateAsStmt
- | CreateAssertStmt
- | CreateCastStmt
- | CreateConversionStmt
- | CreateDomainStmt
- | CreateExtensionStmt
- | CreateFdwStmt
- | CreateForeignServerStmt
- | CreateForeignTableStmt
- | CreateFunctionStmt
- | CreateGroupStmt
- | CreateMatViewStmt
- | CreateOpClassStmt
- | CreateOpFamilyStmt
- | AlterOpFamilyStmt
- | CreatePLangStmt
- | CreateSchemaStmt
- | CreateSeqStmt
- | CreateStmt
- | CreateTableSpaceStmt
- | CreateTrigStmt
- | CreateEventTrigStmt
- | CreateRoleStmt
- | CreateUserStmt
- | CreateUserMappingStmt
- | CreatedbStmt
- | DeallocateStmt
- | DeclareCursorStmt
- | DefineStmt
- | DeleteStmt
- | DiscardStmt
- | DoStmt
- | DropAssertStmt
- | DropCastStmt
- | DropFdwStmt
- | DropForeignServerStmt
- | DropGroupStmt
- | DropOpClassStmt
- | DropOpFamilyStmt
- | DropOwnedStmt
- | DropPLangStmt
- | DropRuleStmt
- | DropStmt
- | DropTableSpaceStmt
- | DropTrigStmt
- | DropRoleStmt
- | DropUserStmt
- | DropUserMappingStmt
- | DropdbStmt
- | ExecuteStmt
- | ExplainStmt
- | FetchStmt
- | GrantStmt
- | GrantRoleStmt
- | IndexStmt
- | InsertStmt
- | ListenStmt
- | RefreshMatViewStmt
- | LoadStmt
- | LockStmt
- | NotifyStmt
- | PrepareStmt
- | ReassignOwnedStmt
- | ReindexStmt
- | RemoveAggrStmt
- | RemoveFuncStmt
- | RemoveOperStmt
- | RenameStmt
- | RevokeStmt
- | RevokeRoleStmt
- | RuleStmt
- | SecLabelStmt
- | SelectStmt
- | TransactionStmt
- | TruncateStmt
- | UnlistenStmt
- | UpdateStmt
- | VacuumStmt
- | VariableResetStmt
- | VariableSetStmt
- | VariableShowStmt
- | ViewStmt
- | /*EMPTY*/
- { $$ = NULL; }
- ;
- /*****************************************************************************
- *
- * Create a new Postgres DBMS role
- *
- *****************************************************************************/
- CreateRoleStmt:
- CREATE ROLE RoleId opt_with OptRoleList
- {
- CreateRoleStmt *n = makeNode(CreateRoleStmt);
- n->stmt_type = ROLESTMT_ROLE;
- n->role = $3;
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
- opt_with: WITH {}
- | /*EMPTY*/ {}
- ;
- /*
- * Options for CREATE ROLE and ALTER ROLE (also used by CREATE/ALTER USER
- * for backwards compatibility). Note: the only option required by SQL99
- * is "WITH ADMIN name".
- */
- OptRoleList:
- OptRoleList CreateOptRoleElem { $$ = lappend($1, $2); }
- | /* EMPTY */ { $$ = NIL; }
- ;
- AlterOptRoleList:
- AlterOptRoleList AlterOptRoleElem { $$ = lappend($1, $2); }
- | /* EMPTY */ { $$ = NIL; }
- ;
- AlterOptRoleElem:
- PASSWORD Sconst
- {
- $$ = makeDefElem("password",
- (Node *)makeString($2));
- }
- | PASSWORD NULL_P
- {
- $$ = makeDefElem("password", NULL);
- }
- | ENCRYPTED PASSWORD Sconst
- {
- $$ = makeDefElem("encryptedPassword",
- (Node *)makeString($3));
- }
- | UNENCRYPTED PASSWORD Sconst
- {
- $$ = makeDefElem("unencryptedPassword",
- (Node *)makeString($3));
- }
- | INHERIT
- {
- $$ = makeDefElem("inherit", (Node *)makeInteger(TRUE));
- }
- | CONNECTION LIMIT SignedIconst
- {
- $$ = makeDefElem("connectionlimit", (Node *)makeInteger($3));
- }
- | VALID UNTIL Sconst
- {
- $$ = makeDefElem("validUntil", (Node *)makeString($3));
- }
- /* Supported but not documented for roles, for use by ALTER GROUP. */
- | USER role_list
- {
- $$ = makeDefElem("rolemembers", (Node *)$2);
- }
- | IDENT
- {
- /*
- * We handle identifiers that aren't parser keywords with
- * the following special-case codes, to avoid bloating the
- * size of the main parser.
- */
- if (strcmp($1, "superuser") == 0)
- $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
- else if (strcmp($1, "nosuperuser") == 0)
- $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
- else if (strcmp($1, "createuser") == 0)
- {
- /* For backwards compatibility, synonym for SUPERUSER */
- $$ = makeDefElem("superuser", (Node *)makeInteger(TRUE));
- }
- else if (strcmp($1, "nocreateuser") == 0)
- {
- /* For backwards compatibility, synonym for SUPERUSER */
- $$ = makeDefElem("superuser", (Node *)makeInteger(FALSE));
- }
- else if (strcmp($1, "createrole") == 0)
- $$ = makeDefElem("createrole", (Node *)makeInteger(TRUE));
- else if (strcmp($1, "nocreaterole") == 0)
- $$ = makeDefElem("createrole", (Node *)makeInteger(FALSE));
- else if (strcmp($1, "replication") == 0)
- $$ = makeDefElem("isreplication", (Node *)makeInteger(TRUE));
- else if (strcmp($1, "noreplication") == 0)
- $$ = makeDefElem("isreplication", (Node *)makeInteger(FALSE));
- else if (strcmp($1, "createdb") == 0)
- $$ = makeDefElem("createdb", (Node *)makeInteger(TRUE));
- else if (strcmp($1, "nocreatedb") == 0)
- $$ = makeDefElem("createdb", (Node *)makeInteger(FALSE));
- else if (strcmp($1, "login") == 0)
- $$ = makeDefElem("canlogin", (Node *)makeInteger(TRUE));
- else if (strcmp($1, "nologin") == 0)
- $$ = makeDefElem("canlogin", (Node *)makeInteger(FALSE));
- else if (strcmp($1, "noinherit") == 0)
- {
- /*
- * Note that INHERIT is a keyword, so it's handled by main parser, but
- * NOINHERIT is handled here.
- */
- $$ = makeDefElem("inherit", (Node *)makeInteger(FALSE));
- }
- else
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("unrecognized role option \"%s\"", $1),
- parser_errposition(@1)));
- }
- ;
- CreateOptRoleElem:
- AlterOptRoleElem { $$ = $1; }
- /* The following are not supported by ALTER ROLE/USER/GROUP */
- | SYSID Iconst
- {
- $$ = makeDefElem("sysid", (Node *)makeInteger($2));
- }
- | ADMIN role_list
- {
- $$ = makeDefElem("adminmembers", (Node *)$2);
- }
- | ROLE role_list
- {
- $$ = makeDefElem("rolemembers", (Node *)$2);
- }
- | IN_P ROLE role_list
- {
- $$ = makeDefElem("addroleto", (Node *)$3);
- }
- | IN_P GROUP_P role_list
- {
- $$ = makeDefElem("addroleto", (Node *)$3);
- }
- ;
- /*****************************************************************************
- *
- * Create a new Postgres DBMS user (role with implied login ability)
- *
- *****************************************************************************/
- CreateUserStmt:
- CREATE USER RoleId opt_with OptRoleList
- {
- CreateRoleStmt *n = makeNode(CreateRoleStmt);
- n->stmt_type = ROLESTMT_USER;
- n->role = $3;
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
- /*****************************************************************************
- *
- * Alter a postgresql DBMS role
- *
- *****************************************************************************/
- AlterRoleStmt:
- ALTER ROLE RoleId opt_with AlterOptRoleList
- {
- AlterRoleStmt *n = makeNode(AlterRoleStmt);
- n->role = $3;
- n->action = +1; /* add, if there are members */
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
- opt_in_database:
- /* EMPTY */ { $$ = NULL; }
- | IN_P DATABASE database_name { $$ = $3; }
- ;
- AlterRoleSetStmt:
- ALTER ROLE RoleId opt_in_database SetResetClause
- {
- AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
- n->role = $3;
- n->database = $4;
- n->setstmt = $5;
- $$ = (Node *)n;
- }
- | ALTER ROLE ALL opt_in_database SetResetClause
- {
- AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
- n->role = NULL;
- n->database = $4;
- n->setstmt = $5;
- $$ = (Node *)n;
- }
- ;
- /*****************************************************************************
- *
- * Alter a postgresql DBMS user
- *
- *****************************************************************************/
- AlterUserStmt:
- ALTER USER RoleId opt_with AlterOptRoleList
- {
- AlterRoleStmt *n = makeNode(AlterRoleStmt);
- n->role = $3;
- n->action = +1; /* add, if there are members */
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
- AlterUserSetStmt:
- ALTER USER RoleId SetResetClause
- {
- AlterRoleSetStmt *n = makeNode(AlterRoleSetStmt);
- n->role = $3;
- n->database = NULL;
- n->setstmt = $4;
- $$ = (Node *)n;
- }
- ;
- /*****************************************************************************
- *
- * Drop a postgresql DBMS role
- *
- * XXX Ideally this would have CASCADE/RESTRICT options, but since a role
- * might own objects in multiple databases, there is presently no way to
- * implement either cascading or restricting. Caveat DBA.
- *****************************************************************************/
- DropRoleStmt:
- DROP ROLE role_list
- {
- DropRoleStmt *n = makeNode(DropRoleStmt);
- n->missing_ok = FALSE;
- n->roles = $3;
- $$ = (Node *)n;
- }
- | DROP ROLE IF_P EXISTS role_list
- {
- DropRoleStmt *n = makeNode(DropRoleStmt);
- n->missing_ok = TRUE;
- n->roles = $5;
- $$ = (Node *)n;
- }
- ;
- /*****************************************************************************
- *
- * Drop a postgresql DBMS user
- *
- * XXX Ideally this would have CASCADE/RESTRICT options, but since a user
- * might own objects in multiple databases, there is presently no way to
- * implement either cascading or restricting. Caveat DBA.
- *****************************************************************************/
- DropUserStmt:
- DROP USER role_list
- {
- DropRoleStmt *n = makeNode(DropRoleStmt);
- n->missing_ok = FALSE;
- n->roles = $3;
- $$ = (Node *)n;
- }
- | DROP USER IF_P EXISTS role_list
- {
- DropRoleStmt *n = makeNode(DropRoleStmt);
- n->roles = $5;
- n->missing_ok = TRUE;
- $$ = (Node *)n;
- }
- ;
- /*****************************************************************************
- *
- * Create a postgresql group (role without login ability)
- *
- *****************************************************************************/
- CreateGroupStmt:
- CREATE GROUP_P RoleId opt_with OptRoleList
- {
- CreateRoleStmt *n = makeNode(CreateRoleStmt);
- n->stmt_type = ROLESTMT_GROUP;
- n->role = $3;
- n->options = $5;
- $$ = (Node *)n;
- }
- ;
- /*****************************************************************************
- *
- * Alter a postgresql group
- *
- *****************************************************************************/
- AlterGroupStmt:
- ALTER GROUP_P RoleId add_drop USER role_list
- {
- AlterRoleStmt *n = makeNode(AlterRoleStmt);
- n->role = $3;
- n->action = $4;
- n->options = list_make1(makeDefElem("rolemembers",
- (Node *)$6));
- $$ = (Node *)n;
- }
- ;
- add_drop: ADD_P { $$ = +1; }
- | DROP { $$ = -1; }
- ;
- /*****************************************************************************
- *
- * Drop a postgresql group
- *
- * XXX see above notes about cascading DROP USER; groups have same problem.
- *****************************************************************************/
- DropGroupStmt:
- DROP GROUP_P role_list
- {
- DropRoleStmt *n = makeNode(DropRoleStmt);
- n->missing_ok = FALSE;
- n->roles = $3;
- $$ = (Node *)n;
- }
- | DROP GROUP_P IF_P EXISTS role_list
- {
- DropRoleStmt *n = makeNode(DropRoleStmt);
- n->missing_ok = TRUE;
- n->roles = $5;
- $$ = (Node *)n;
- }
- ;
- /*****************************************************************************
- *
- * Manipulate a schema
- *
- *****************************************************************************/
- CreateSchemaStmt:
- CREATE SCHEMA OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
- {
- CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
- /* One can omit the schema name or the authorization id. */
- if ($3 != NULL)
- n->schemaname = $3;
- else
- n->schemaname = $5;
- n->authid = $5;
- n->schemaElts = $6;
- n->if_not_exists = false;
- $$ = (Node *)n;
- }
- | CREATE SCHEMA ColId OptSchemaEltList
- {
- CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
- /* ...but not both */
- n->schemaname = $3;
- n->authid = NULL;
- n->schemaElts = $4;
- n->if_not_exists = false;
- $$ = (Node *)n;
- }
- | CREATE SCHEMA IF_P NOT EXISTS OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
- {
- CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
- /* One can omit the schema name or the authorization id. */
- if ($6 != NULL)
- n->schemaname = $6;
- else
- n->schemaname = $8;
- n->authid = $8;
- if ($9 != NIL)
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
- parser_errposition(@9)));
- n->schemaElts = $9;
- n->if_not_exists = true;
- $$ = (Node *)n;
- }
- | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
- {
- CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
- /* ...but not both */
- n->schemaname = $6;
- n->authid = NULL;
- if ($7 != NIL)
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
- parser_errposition(@7)));
- n->schemaElts = $7;
- n->if_not_exists = true;
- $$ = (Node *)n;
- }
- ;
- OptSchemaName:
- ColId { $$ = $1; }
- | /* EMPTY */ { $$ = NULL; }
- ;
- OptSchemaEltList:
- OptSchemaEltList schema_stmt
- {
- if (@$ < 0) /* see comments for YYLLOC_DEFAULT */
- @$ = @2;
- $$ = lappend($1, $2);
- }
- | /* EMPTY */
- { $$ = NIL; }
- ;
- /*
- * schema_stmt are the ones that can show up inside a CREATE SCHEMA
- * statement (in addition to by themselves).
- */
- schema_stmt:
- CreateStmt
- | IndexStmt
- | CreateSeqStmt
- | CreateTrigStmt
- | GrantStmt
- | ViewStmt
- ;
- /*****************************************************************************
- *
- * Set PG internal variable
- * SET name TO 'var_value'
- * Include SQL syntax (thomas 1997-10-22):
- * SET TIME ZONE 'var_value'
- *
- *****************************************************************************/
- VariableSetStmt:
- SET set_rest
- {
- VariableSetStmt *n = $2;
- n->is_local = false;
- $$ = (Node *) n;
- }
- | SET LOCAL set_rest
- {
- VariableSetStmt *n = $3;
- n->is_local = true;
- $$ = (Node *) n;
- }
- | SET SESSION set_rest
- {
- VariableSetStmt *n = $3;
- n->is_local = false;
- $$ = (Node *) n;
- }
- ;
- set_rest:
- TRANSACTION transaction_mode_list
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_MULTI;
- n->name = "TRANSACTION";
- n->args = $2;
- $$ = n;
- }
- | SESSION CHARACTERISTICS AS TRANSACTION transaction_mode_list
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_MULTI;
- n->name = "SESSION CHARACTERISTICS";
- n->args = $5;
- $$ = n;
- }
- | set_rest_more
- ;
- generic_set:
- var_name TO var_list
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_VALUE;
- n->name = $1;
- n->args = $3;
- $$ = n;
- }
- | var_name '=' var_list
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_VALUE;
- n->name = $1;
- n->args = $3;
- $$ = n;
- }
- | var_name TO DEFAULT
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_DEFAULT;
- n->name = $1;
- $$ = n;
- }
- | var_name '=' DEFAULT
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_DEFAULT;
- n->name = $1;
- $$ = n;
- }
- set_rest_more: /* Generic SET syntaxes: */
- generic_set {$$ = $1;}
- | var_name FROM CURRENT_P
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_CURRENT;
- n->name = $1;
- $$ = n;
- }
- /* Special syntaxes mandated by SQL standard: */
- | TIME ZONE zone_value
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_VALUE;
- n->name = "timezone";
- if ($3 != NULL)
- n->args = list_make1($3);
- else
- n->kind = VAR_SET_DEFAULT;
- $$ = n;
- }
- | CATALOG_P Sconst
- {
- ereport(ERROR,
- (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
- errmsg("current database cannot be changed"),
- parser_errposition(@2)));
- $$ = NULL; /*not reached*/
- }
- | SCHEMA Sconst
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_VALUE;
- n->name = "search_path";
- n->args = list_make1(makeStringConst($2, @2));
- $$ = n;
- }
- | NAMES opt_encoding
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_VALUE;
- n->name = "client_encoding";
- if ($2 != NULL)
- n->args = list_make1(makeStringConst($2, @2));
- else
- n->kind = VAR_SET_DEFAULT;
- $$ = n;
- }
- | ROLE NonReservedWord_or_Sconst
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_VALUE;
- n->name = "role";
- n->args = list_make1(makeStringConst($2, @2));
- $$ = n;
- }
- | SESSION AUTHORIZATION NonReservedWord_or_Sconst
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_VALUE;
- n->name = "session_authorization";
- n->args = list_make1(makeStringConst($3, @3));
- $$ = n;
- }
- | SESSION AUTHORIZATION DEFAULT
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_DEFAULT;
- n->name = "session_authorization";
- $$ = n;
- }
- | XML_P OPTION document_or_content
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_VALUE;
- n->name = "xmloption";
- n->args = list_make1(makeStringConst($3 == XMLOPTION_DOCUMENT ? "DOCUMENT" : "CONTENT", @3));
- $$ = n;
- }
- /* Special syntaxes invented by PostgreSQL: */
- | TRANSACTION SNAPSHOT Sconst
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_SET_MULTI;
- n->name = "TRANSACTION SNAPSHOT";
- n->args = list_make1(makeStringConst($3, @3));
- $$ = n;
- }
- ;
- var_name: ColId { $$ = $1; }
- | var_name '.' ColId
- { $$ = psprintf("%s.%s", $1, $3); }
- ;
- var_list: var_value { $$ = list_make1($1); }
- | var_list ',' var_value { $$ = lappend($1, $3); }
- ;
- var_value: opt_boolean_or_string
- { $$ = makeStringConst($1, @1); }
- | NumericOnly
- { $$ = makeAConst($1, @1); }
- ;
- iso_level: READ UNCOMMITTED { $$ = "read uncommitted"; }
- | READ COMMITTED { $$ = "read committed"; }
- | REPEATABLE READ { $$ = "repeatable read"; }
- | SERIALIZABLE { $$ = "serializable"; }
- ;
- opt_boolean_or_string:
- TRUE_P { $$ = "true"; }
- | FALSE_P { $$ = "false"; }
- | ON { $$ = "on"; }
- /*
- * OFF is also accepted as a boolean value, but is handled by
- * the NonReservedWord rule. The action for booleans and strings
- * is the same, so we don't need to distinguish them here.
- */
- | NonReservedWord_or_Sconst { $$ = $1; }
- ;
- /* Timezone values can be:
- * - a string such as 'pst8pdt'
- * - an identifier such as "pst8pdt"
- * - an integer or floating point number
- * - a time interval per SQL99
- * ColId gives reduce/reduce errors against ConstInterval and LOCAL,
- * so use IDENT (meaning we reject anything that is a key word).
- */
- zone_value:
- Sconst
- {
- $$ = makeStringConst($1, @1);
- }
- | IDENT
- {
- $$ = makeStringConst($1, @1);
- }
- | ConstInterval Sconst opt_interval
- {
- TypeName *t = $1;
- if ($3 != NIL)
- {
- A_Const *n = (A_Const *) linitial($3);
- if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
- parser_errposition(@3)));
- }
- t->typmods = $3;
- $$ = makeStringConstCast($2, @2, t);
- }
- | ConstInterval '(' Iconst ')' Sconst opt_interval
- {
- TypeName *t = $1;
- if ($6 != NIL)
- {
- A_Const *n = (A_Const *) linitial($6);
- if ((n->val.val.ival & ~(INTERVAL_MASK(HOUR) | INTERVAL_MASK(MINUTE))) != 0)
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("time zone interval must be HOUR or HOUR TO MINUTE"),
- parser_errposition(@6)));
- if (list_length($6) != 1)
- ereport(ERROR,
- (errcode(ERRCODE_SYNTAX_ERROR),
- errmsg("interval precision specified twice"),
- parser_errposition(@1)));
- t->typmods = lappend($6, makeIntConst($3, @3));
- }
- else
- t->typmods = list_make2(makeIntConst(INTERVAL_FULL_RANGE, -1),
- makeIntConst($3, @3));
- $$ = makeStringConstCast($5, @5, t);
- }
- | NumericOnly { $$ = makeAConst($1, @1); }
- | DEFAULT { $$ = NULL; }
- | LOCAL { $$ = NULL; }
- ;
- opt_encoding:
- Sconst { $$ = $1; }
- | DEFAULT { $$ = NULL; }
- | /*EMPTY*/ { $$ = NULL; }
- ;
- NonReservedWord_or_Sconst:
- NonReservedWord { $$ = $1; }
- | Sconst { $$ = $1; }
- ;
- VariableResetStmt:
- RESET var_name
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_RESET;
- n->name = $2;
- $$ = (Node *) n;
- }
- | RESET TIME ZONE
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_RESET;
- n->name = "timezone";
- $$ = (Node *) n;
- }
- | RESET TRANSACTION ISOLATION LEVEL
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_RESET;
- n->name = "transaction_isolation";
- $$ = (Node *) n;
- }
- | RESET SESSION AUTHORIZATION
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_RESET;
- n->name = "session_authorization";
- $$ = (Node *) n;
- }
- | RESET ALL
- {
- VariableSetStmt *n = makeNode(VariableSetStmt);
- n->kind = VAR_RESET_ALL;
- $$ = (Node *) n;
- }
- ;
- /* SetResetClause allows SET or RESET without LOCAL */
- SetResetClause:
- SET set_rest { $$ = $2; }
- | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
- ;
- /* SetResetClause allows SET or RESET without LOCAL */
- FunctionSetResetClause:
- SET set_rest_more { $$ = $2; }
- | VariableResetStmt { $$ = (VariableSetStmt *) $1; }
- ;
- VariableShowStmt:
- SHOW var_name
- {
- VariableShowStmt *n = makeNode(VariableShowStmt);
- n->name = $2;
- $$ = (Node *) n;
- }
- | SHOW TIME ZONE
- {
- VariableShowStmt *n = makeNode(VariableShowStmt);
- n->name = "timezone";
- $$ = (Node *) n;
- }
- | SHOW TRANSACTION ISOLATION LEVEL
- {
- VariableShowStmt *n = makeNode(VariableShowStmt);
- n->name = "transaction_isolation";
- $$ = (Node *) n;
- }
- | SHOW SESSION AUTHORIZATION
- {
- VariableShowStmt *n = makeNode(VariableShowStmt);
- n->name = "session_authorization";
- $$ = (Node *) n;
- }
- | SHOW ALL
- {
- VariableShowStmt *n = makeNode(VariableShowStmt);
- n->name = "all";
- $$ = (Node *) n;
- }
- ;
- ConstraintsSetStmt:
- SET CONSTRAINTS constraints_set_list constraints_set_mode
- {
- ConstraintsSetStmt *n = makeNode(ConstraintsSetStmt);
- n->constraints = $3;
- n->deferred = $4;
- $$ = (Node *) n;
- }
- ;
- constraints_set_list:
- ALL { $$ = NIL; }
- | qualified_name_list { $$ = $1; }
- ;
- constraints_set_mode:
- DEFERRED { $$ = TRUE; }
- | IMMEDIATE { $$ = FALSE; }
- ;
- /*
- * Checkpoint statement
- */
- CheckPointStmt:
- CHECKPOINT
- {
- Check…
Large files files are truncated, but you can click here to view the full file